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
922
A
Cloning Toys
PROGRAMMING
1,300
[ "implementation" ]
null
null
Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "6 3\n", "4 2\n", "1000 1001\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
500
[ { "input": "6 3", "output": "Yes" }, { "input": "4 2", "output": "No" }, { "input": "1000 1001", "output": "Yes" }, { "input": "1000000000 999999999", "output": "Yes" }, { "input": "81452244 81452247", "output": "No" }, { "input": "188032448 86524683", "output": "Yes" }, { "input": "365289629 223844571", "output": "No" }, { "input": "247579518 361164458", "output": "No" }, { "input": "424836699 793451637", "output": "No" }, { "input": "602093880 930771525", "output": "No" }, { "input": "779351061 773124120", "output": "Yes" }, { "input": "661640950 836815080", "output": "No" }, { "input": "543930839 974134967", "output": "No" }, { "input": "16155311 406422145", "output": "No" }, { "input": "81601559 445618240", "output": "No" }, { "input": "963891449 582938127", "output": "No" }, { "input": "141148629 351661795", "output": "No" }, { "input": "318405810 783948974", "output": "No" }, { "input": "495662991 921268861", "output": "No" }, { "input": "1 0", "output": "No" }, { "input": "0 1", "output": "Yes" }, { "input": "0 0", "output": "No" }, { "input": "453462237 167520068", "output": "Yes" }, { "input": "630719418 9872663", "output": "Yes" }, { "input": "807976599 442159843", "output": "No" }, { "input": "690266488 579479730", "output": "No" }, { "input": "771581370 589752968", "output": "No" }, { "input": "948838551 727072855", "output": "No" }, { "input": "831128440 790763814", "output": "No" }, { "input": "303352912 928083702", "output": "No" }, { "input": "185642801 65403588", "output": "Yes" }, { "input": "67932690 202723476", "output": "No" }, { "input": "540157163 340043363", "output": "No" }, { "input": "422447052 772330542", "output": "No" }, { "input": "599704233 541054210", "output": "Yes" }, { "input": "481994122 678374097", "output": "No" }, { "input": "48564714 743566477", "output": "No" }, { "input": "225821895 880886365", "output": "No" }, { "input": "403079076 313173543", "output": "Yes" }, { "input": "1000000000 1000000000", "output": "No" }, { "input": "1 1", "output": "No" }, { "input": "1 2", "output": "Yes" }, { "input": "2 1", "output": "No" }, { "input": "2 2", "output": "No" }, { "input": "2 0", "output": "No" }, { "input": "0 2", "output": "No" }, { "input": "1000000000 1", "output": "No" }, { "input": "777777 0", "output": "No" }, { "input": "10 1", "output": "No" }, { "input": "7 0", "output": "No" }, { "input": "3 0", "output": "No" }, { "input": "3 2", "output": "Yes" } ]
1,606,968,638
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
x,y = map(int, input().split()) if y == 0: print("No") elif y == 1 and x > 0: print("No") elif x < y-1: print("No") else: no_of_original_toys = y no_of_copies = y-1 if no_of_copies % 2 == x % 2 print("Yes") else: print("No")
Title: Cloning Toys Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input Specification: The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Specification: Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['6 3\n', '4 2\n', '1000 1001\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n'] Note: In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
```python x,y = map(int, input().split()) if y == 0: print("No") elif y == 1 and x > 0: print("No") elif x < y-1: print("No") else: no_of_original_toys = y no_of_copies = y-1 if no_of_copies % 2 == x % 2 print("Yes") else: print("No") ```
-1
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" }, { "input": "22", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "0" }, { "input": "6", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "0" }, { "input": "9", "output": "0" }, { "input": "13", "output": "4" }, { "input": "14", "output": "4" }, { "input": "16", "output": "4" }, { "input": "17", "output": "4" }, { "input": "19", "output": "4" }, { "input": "21", "output": "4" }, { "input": "23", "output": "0" }, { "input": "24", "output": "0" } ]
1,693,244,322
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
92
0
n=int(input()) x=n-10 if(x==0): print(0) elif(1<=x<=9): print(4) elif(x==10): print(15) elif(x==11): print(4)
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. Input Specification: The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. Output Specification: Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. Demo Input: ['12\n', '20\n', '10\n'] Demo Output: ['4', '15', '0'] Note: In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
```python n=int(input()) x=n-10 if(x==0): print(0) elif(1<=x<=9): print(4) elif(x==10): print(15) elif(x==11): print(4) ```
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,650,014,774
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n=6 m=6 a=4 if m%a==0: x=m//a else: x=m//a + 1 if n%a==0: y=n//a else: y=m//a + 1 nf=x*y print("number of flugstone",nf)
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=6 m=6 a=4 if m%a==0: x=m//a else: x=m//a + 1 if n%a==0: y=n//a else: y=m//a + 1 nf=x*y print("number of flugstone",nf) ```
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,675,076,506
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
string = input().strip().split(".") ans = '' for i in string: if(len(i) == 0): ans += '0' elif(len(i) == 1): ans += '1' elif(len(i) == 2): ans += '2' print(ans)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python string = input().strip().split(".") ans = '' for i in string: if(len(i) == 0): ans += '0' elif(len(i) == 1): ans += '1' elif(len(i) == 2): ans += '2' print(ans) ```
0
217
A
Ice Skating
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459", "output": "21" }, { "input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815", "output": "16" }, { "input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663", "output": "10" }, { "input": "1\n321 88", "output": "0" }, { "input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689", "output": "7" }, { "input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510", "output": "6" }, { "input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888", "output": "5" }, { "input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802", "output": "13" }, { "input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662", "output": "11" }, { "input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786", "output": "38" }, { "input": "3\n175 201\n907 909\n388 360", "output": "2" }, { "input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86", "output": "6" }, { "input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820", "output": "16" }, { "input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901", "output": "31" }, { "input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210", "output": "29" }, { "input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894", "output": "29" }, { "input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823", "output": "13" }, { "input": "5\n175 158\n16 2\n397 381\n668 686\n957 945", "output": "4" }, { "input": "5\n312 284\n490 509\n730 747\n504 497\n782 793", "output": "4" }, { "input": "2\n802 903\n476 348", "output": "1" }, { "input": "4\n325 343\n425 442\n785 798\n275 270", "output": "3" }, { "input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653", "output": "25" }, { "input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124", "output": "34" }, { "input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255", "output": "29" }, { "input": "5\n664 666\n951 941\n739 742\n844 842\n2 2", "output": "4" }, { "input": "3\n939 867\n411 427\n757 708", "output": "2" }, { "input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636", "output": "34" }, { "input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195", "output": "28" }, { "input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488", "output": "22" }, { "input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235", "output": "8" }, { "input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621", "output": "22" }, { "input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461", "output": "22" }, { "input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924", "output": "6" }, { "input": "3\n1 1\n2 1\n2 2", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "5\n1 1\n1 2\n2 2\n3 1\n3 3", "output": "0" }, { "input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3", "output": "0" }, { "input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10", "output": "1" }, { "input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11", "output": "1" }, { "input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11", "output": "3" }, { "input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25", "output": "7" }, { "input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28", "output": "5" }, { "input": "3\n1 2\n2 1\n2 2", "output": "0" }, { "input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "3\n1 1\n2 2\n1 2", "output": "0" }, { "input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4", "output": "1" }, { "input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100", "output": "6" }, { "input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4", "output": "0" }, { "input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3", "output": "0" }, { "input": "4\n3 1\n2 1\n2 2\n1 2", "output": "0" }, { "input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3", "output": "0" }, { "input": "3\n1 2\n1 3\n1 4", "output": "0" }, { "input": "4\n1 1\n2 2\n1 2\n2 1", "output": "0" }, { "input": "4\n1 3\n2 1\n3 2\n3 1", "output": "1" }, { "input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4", "output": "0" }, { "input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700", "output": "2" }, { "input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9", "output": "1" }, { "input": "4\n1 1\n2 2\n3 2\n3 1", "output": "0" }, { "input": "3\n1 2\n3 4\n3 2", "output": "0" }, { "input": "3\n1 1\n1 2\n2 2", "output": "0" }, { "input": "4\n5 5\n5 4\n6 3\n6 4", "output": "0" }, { "input": "3\n1 1\n2 2\n2 1", "output": "0" } ]
1,587,516,547
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
216
307,200
n = int(input()) li = [] for i in range(n): x, y = map(int, input().split()) li.append((x, y)) cnt = 0 vis = {} for i in range(n): for j in range(n): if i == j: continue if li[i] not in vis or li[j] not in vis: if li[i][0] == li[j][0] or li[i][1] == li[j][1]: cnt += 1 vis[li[i]], vis[li[j]] = True, True print(min(n - len(vis), n - 1))
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. Output Specification: Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Demo Input: ['2\n2 1\n1 2\n', '2\n2 1\n4 1\n'] Demo Output: ['1\n', '0\n'] Note: none
```python n = int(input()) li = [] for i in range(n): x, y = map(int, input().split()) li.append((x, y)) cnt = 0 vis = {} for i in range(n): for j in range(n): if i == j: continue if li[i] not in vis or li[j] not in vis: if li[i][0] == li[j][0] or li[i][1] == li[j][1]: cnt += 1 vis[li[i]], vis[li[j]] = True, True print(min(n - len(vis), n - 1)) ```
0
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "25 9712", "output": "11" }, { "input": "9 7601", "output": "5" }, { "input": "1 9058", "output": "0" }, { "input": "29 7772", "output": "26" }, { "input": "45 9465", "output": "14" }, { "input": "46 866", "output": "5" }, { "input": "29 1241", "output": "20" }, { "input": "17 4248", "output": "12" }, { "input": "20 8082", "output": "11" }, { "input": "50 9555", "output": "0" }, { "input": "4 7455", "output": "2" }, { "input": "36 880", "output": "4" }, { "input": "24 7440", "output": "9" }, { "input": "44 7888", "output": "12" }, { "input": "1 1", "output": "0" }, { "input": "50 10000", "output": "40" }, { "input": "1 10000", "output": "0" }, { "input": "50 1", "output": "0" }, { "input": "50 50", "output": "5" } ]
1,574,152,829
2,429
Python 3
OK
TESTS
25
248
0
n,m=map(int,input().split()) s,k=0,0 for i in range(1,n+1): s+=i while m>s: m-=s for i in range(1,n+1): if m>=i: m-=i else: break print(m)
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. Output Specification: Print the number of chips the presenter ended up with. Demo Input: ['4 11\n', '17 107\n', '3 8\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
```python n,m=map(int,input().split()) s,k=0,0 for i in range(1,n+1): s+=i while m>s: m-=s for i in range(1,n+1): if m>=i: m-=i else: break print(m) ```
3.938
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", "output": "2\n99 100 " }, { "input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 " }, { "input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421", "output": "8\n117 151 183 227 954 222 909 421 " }, { "input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2", "output": "4\n62 726 903 2 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2", "output": "6\n5 33 375 37 3 2 " }, { "input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6", "output": "6\n4 3 2 5 1 6 " }, { "input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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\n233 1 " }, { "input": "47\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", "output": "1\n1 " }, { "input": "2\n964 964", "output": "1\n964 " }, { "input": "2\n1000 1000", "output": "1\n1000 " }, { "input": "1\n1000", "output": "1\n1000 " }, { "input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993", "output": "10\n996 1000 999 992 997 991 995 998 994 993 " }, { "input": "6\n994 993 1000 998 991 994", "output": "5\n993 1000 998 991 994 " }, { "input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999", "output": "10\n993 996 995 991 994 997 998 992 1000 999 " }, { "input": "3\n6 6 3", "output": "2\n6 3 " }, { "input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997", "output": "9\n1000 995 994 993 999 996 998 991 997 " }, { "input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996", "output": "10\n998 995 999 992 1000 993 994 997 991 996 " }, { "input": "2\n1000 999", "output": "2\n1000 999 " }, { "input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000", "output": "10\n996 999 993 994 997 995 991 992 998 1000 " }, { "input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992", "output": "8\n993 997 998 994 1000 991 995 992 " }, { "input": "6\n1000 1 1000 2 1000 1", "output": "3\n2 1000 1 " }, { "input": "6\n1000 1 1000 2 1 1000", "output": "3\n2 1 1000 " }, { "input": "7\n1 1000 1 999 1000 1 2", "output": "4\n999 1000 1 2 " } ]
1,681,492,102
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
def main(): size = int(input()) numbers = tuple(map(int, input().split())) for i in range(size - 1): if numbers[i + 1:].count(numbers[i]) == 0: print(numbers[i], end=' ') print(numbers[-1]) if __name__ == '__main__': main()
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. Output Specification: In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Demo Input: ['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n'] Demo Output: ['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n'] Note: In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
```python def main(): size = int(input()) numbers = tuple(map(int, input().split())) for i in range(size - 1): if numbers[i + 1:].count(numbers[i]) == 0: print(numbers[i], end=' ') print(numbers[-1]) if __name__ == '__main__': main() ```
0
400
C
Inna and Huge Candy Matrix
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as (*i*,<=*j*). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has *p* candies: the *k*-th candy is at cell (*x**k*,<=*y**k*). The time moved closer to dinner and Inna was already going to eat *p* of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix *x* times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix *y* times. And then he rotated the matrix *z* times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!
The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105). Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell.
For each of the *p* candies, print on a single line its space-separated new coordinates.
[ "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n" ]
[ "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n" ]
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
1,500
[ { "input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1" }, { "input": "5 5 0 0 0 1\n1 4", "output": "1 4" }, { "input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n13 75\n9 9\n3 63\n8 49\n5 1\n1 67\n13 31\n9 35\n3 53\n13 73\n5 71\n1 32\n5 49\n1 41\n14 69", "output": "4 21\n14 65\n10 25\n1 63\n4 30\n14 19\n10 7\n6 51\n13 49\n2 75\n6 9\n12 63\n7 49\n10 1\n14 67\n2 31\n6 35\n12 53\n2 73\n10 71\n14 32\n10 49\n14 41\n1 69" }, { "input": "63 67 18046757 61758841 85367218 68\n22 30\n25 40\n56 58\n29 11\n34 63\n28 66\n51 5\n39 64\n1 23\n24 61\n19 47\n10 31\n55 28\n52 26\n38 7\n28 31\n13 27\n37 42\n10 52\n19 33\n7 36\n13 1\n46 40\n21 41\n1 1\n6 35\n10 4\n46 9\n21 57\n1 49\n34 14\n14 35\n43 4\n1 41\n25 22\n18 25\n27 23\n43 17\n34 23\n29 4\n50 40\n43 67\n55 37\n4 60\n35 32\n22 58\n22 12\n9 2\n42 44\n20 57\n5 37\n22 48\n26 8\n33 1\n61 28\n55 18\n21 1\n1 2\n36 29\n45 65\n1 41\n22 46\n25 67\n25 41\n36 42\n8 66\n52 60\n28 50", "output": "38 42\n28 39\n10 8\n57 35\n5 30\n2 36\n63 13\n4 25\n45 63\n7 40\n21 45\n37 54\n40 9\n42 12\n61 26\n37 36\n41 51\n26 27\n16 54\n35 45\n32 57\n67 51\n28 18\n27 43\n67 63\n33 58\n64 54\n59 18\n11 43\n19 63\n54 30\n33 50\n64 21\n27 63\n46 39\n43 46\n45 37\n51 21\n45 30\n64 35\n28 14\n1 21\n31 9\n8 60\n36 29\n10 42\n56 42\n66 55\n24 22\n11 44\n31 59\n20 42\n60 38\n67 31\n40 3\n50 9\n67 43\n66 63\n39 28\n3 19\n27 63\n22 42\n1 39\n27 39\n26 28\n2 56\n8 12\n18 36" }, { "input": "75 18 163006189 147424057 443319537 71\n56 7\n1 5\n17 4\n67 13\n45 1\n55 9\n46 14\n23 10\n10 1\n1 1\n14 9\n18 16\n25 9\n22 4\n73 13\n51 7\n43 13\n59 1\n62 15\n37 6\n43 11\n66 17\n61 13\n45 1\n16 7\n46 7\n25 1\n52 13\n74 7\n16 17\n34 11\n37 16\n24 5\n10 11\n20 5\n74 1\n57 7\n72 10\n21 11\n66 13\n46 1\n46 13\n65 1\n68 11\n14 13\n72 11\n58 1\n16 15\n49 1\n53 10\n30 1\n75 1\n45 4\n42 13\n52 10\n25 1\n31 1\n26 1\n21 7\n27 4\n55 10\n61 1\n37 3\n13 18\n24 1\n11 3\n14 17\n34 5\n49 4\n56 13\n19 11", "output": "20 7\n75 5\n59 4\n9 13\n31 1\n21 9\n30 14\n53 10\n66 1\n75 1\n62 9\n58 16\n51 9\n54 4\n3 13\n25 7\n33 13\n17 1\n14 15\n39 6\n33 11\n10 17\n15 13\n31 1\n60 7\n30 7\n51 1\n24 13\n2 7\n60 17\n42 11\n39 16\n52 5\n66 11\n56 5\n2 1\n19 7\n4 10\n55 11\n10 13\n30 1\n30 13\n11 1\n8 11\n62 13\n4 11\n18 1\n60 15\n27 1\n23 10\n46 1\n1 1\n31 4\n34 13\n24 10\n51 1\n45 1\n50 1\n55 7\n49 4\n21 10\n15 1\n39 3\n63 18\n52 1\n65 3\n62 17\n42 5\n27 4\n20 13\n57 11" }, { "input": "99 65 100328801 11658361 60379320 41\n46 61\n92 23\n46 16\n60 56\n50 42\n24 19\n43 54\n40 1\n41 16\n19 34\n57 59\n84 20\n33 3\n82 59\n74 53\n26 65\n83 30\n76 14\n73 55\n58 33\n97 62\n10 18\n70 1\n56 27\n64 25\n25 57\n28 21\n96 2\n10 41\n99 59\n25 15\n1 3\n46 27\n38 65\n34 25\n64 55\n37 53\n78 43\n70 64\n64 49\n4 12", "output": "61 46\n23 92\n16 46\n56 60\n42 50\n19 24\n54 43\n1 40\n16 41\n34 19\n59 57\n20 84\n3 33\n59 82\n53 74\n65 26\n30 83\n14 76\n55 73\n33 58\n62 97\n18 10\n1 70\n27 56\n25 64\n57 25\n21 28\n2 96\n41 10\n59 99\n15 25\n3 1\n27 46\n65 38\n25 34\n55 64\n53 37\n43 78\n64 70\n49 64\n12 4" }, { "input": "60 1 884622497 447787585 45746569 5\n41 1\n3 1\n57 1\n1 1\n28 1", "output": "20 1\n58 1\n4 1\n60 1\n33 1" }, { "input": "29 9 101222353 522378781 221562741 21\n8 1\n12 8\n21 7\n29 2\n12 3\n1 4\n18 9\n28 6\n2 3\n10 8\n16 4\n3 9\n14 4\n15 3\n16 6\n28 7\n18 1\n12 1\n23 1\n11 1\n18 4", "output": "22 1\n18 8\n9 7\n1 2\n18 3\n29 4\n12 9\n2 6\n28 3\n20 8\n14 4\n27 9\n16 4\n15 3\n14 6\n2 7\n12 1\n18 1\n7 1\n19 1\n12 4" }, { "input": "14 33 331499150 82809609 266661996 75\n9 10\n1 1\n8 8\n13 26\n3 1\n5 1\n8 13\n3 19\n1 13\n1 6\n13 1\n12 19\n5 25\n3 10\n6 19\n6 23\n7 1\n11 7\n11 16\n7 32\n8 30\n1 2\n11 2\n13 25\n8 7\n9 33\n9 1\n1 7\n1 30\n14 32\n9 10\n11 7\n12 5\n11 31\n7 10\n7 21\n9 28\n3 23\n11 31\n9 12\n5 14\n9 7\n10 11\n5 14\n5 14\n4 16\n3 32\n3 16\n13 28\n5 10\n2 8\n4 11\n8 4\n11 15\n1 12\n5 17\n14 10\n13 12\n7 7\n2 32\n3 25\n4 5\n4 31\n10 23\n10 28\n5 8\n5 31\n4 25\n3 25\n13 7\n1 26\n6 4\n9 33\n5 4\n1 14", "output": "6 10\n14 1\n7 8\n2 26\n12 1\n10 1\n7 13\n12 19\n14 13\n14 6\n2 1\n3 19\n10 25\n12 10\n9 19\n9 23\n8 1\n4 7\n4 16\n8 32\n7 30\n14 2\n4 2\n2 25\n7 7\n6 33\n6 1\n14 7\n14 30\n1 32\n6 10\n4 7\n3 5\n4 31\n8 10\n8 21\n6 28\n12 23\n4 31\n6 12\n10 14\n6 7\n5 11\n10 14\n10 14\n11 16\n12 32\n12 16\n2 28\n10 10\n13 8\n11 11\n7 4\n4 15\n14 12\n10 17\n1 10\n2 12\n8 7\n13 32\n12 25\n11 5\n11 31\n5 23\n5 28\n10 8\n10 31\n11 25\n12 25\n2 7\n14 26\n9 4\n6 33\n10 4\n14 14" }, { "input": "26 89 146819986 242756320 184308201 43\n20 71\n12 22\n3 73\n9 48\n1 32\n5 20\n1 18\n19 57\n23 77\n1 4\n17 86\n1 13\n16 64\n1 56\n7 63\n18 38\n17 82\n21 43\n5 16\n9 39\n7 23\n5 53\n19 8\n25 10\n11 69\n11 7\n16 47\n25 48\n20 87\n14 16\n1 16\n14 43\n22 43\n11 89\n7 3\n1 57\n5 43\n21 1\n1 21\n3 85\n5 7\n19 16\n7 15", "output": "71 7\n22 15\n73 24\n48 18\n32 26\n20 22\n18 26\n57 8\n77 4\n4 26\n86 10\n13 26\n64 11\n56 26\n63 20\n38 9\n82 10\n43 6\n16 22\n39 18\n23 20\n53 22\n8 8\n10 2\n69 16\n7 16\n47 11\n48 2\n87 7\n16 13\n16 26\n43 13\n43 5\n89 16\n3 20\n57 26\n43 22\n1 6\n21 26\n85 24\n7 22\n16 8\n15 20" }, { "input": "57 62 402127657 5834146 166754152 26\n55 15\n3 10\n10 21\n25 45\n28 50\n54 39\n1 57\n5 11\n13 54\n52 17\n52 9\n28 3\n37 25\n29 15\n55 33\n23 25\n28 1\n46 7\n39 25\n20 43\n33 49\n52 47\n22 11\n37 37\n52 48\n25 53", "output": "15 3\n10 55\n21 48\n45 33\n50 30\n39 4\n57 57\n11 53\n54 45\n17 6\n9 6\n3 30\n25 21\n15 29\n33 3\n25 35\n1 30\n7 12\n25 19\n43 38\n49 25\n47 6\n11 36\n37 21\n48 6\n53 33" }, { "input": "83 53 263444877 330109611 453128994 25\n47 7\n40 13\n47 53\n23 37\n57 23\n4 38\n39 25\n42 41\n61 23\n74 6\n48 5\n56 53\n48 37\n13 37\n34 32\n49 4\n43 32\n14 1\n75 15\n59 18\n25 14\n46 23\n47 48\n72 3\n55 17", "output": "47 37\n41 44\n1 37\n17 61\n31 27\n16 80\n29 45\n13 42\n31 23\n48 10\n49 36\n1 28\n17 36\n17 71\n22 50\n50 35\n22 41\n53 70\n39 9\n36 25\n40 59\n31 38\n6 37\n51 12\n37 29" }, { "input": "65 66 68528825 50348481 104442753 7\n1 49\n54 47\n16 37\n1 34\n51 29\n36 17\n11 16", "output": "65 49\n12 47\n50 37\n65 34\n15 29\n30 17\n55 16" }, { "input": "63 5 311153546 666957619 681867949 3\n14 3\n22 1\n14 2", "output": "3 50\n5 42\n4 50" }, { "input": "1 9 549924215 115901887 855235569 1\n1 6", "output": "1 4" }, { "input": "85 26 48272945 423830401 423026164 3\n35 1\n50 17\n55 2", "output": "1 35\n17 50\n2 55" }, { "input": "67 61 443905131 226973811 158369983 1\n52 51", "output": "16 51" }, { "input": "1 13 348638338 31146449 81215464 3\n1 4\n1 10\n1 6", "output": "1 4\n1 10\n1 6" }, { "input": "68 45 637151929 93583345 392834373 10\n52 11\n28 1\n67 21\n33 29\n43 28\n30 17\n39 30\n52 37\n11 7\n11 26", "output": "17 11\n41 1\n2 21\n36 29\n26 28\n39 17\n30 30\n17 37\n58 7\n58 26" }, { "input": "25 45 20761261 857816695 7926985 1\n1 26", "output": "25 26" }, { "input": "1 1 0 0 0 2\n1 1\n1 1", "output": "1 1\n1 1" }, { "input": "2 2 1 0 0 4\n1 1\n1 2\n2 2\n2 1", "output": "1 2\n2 2\n2 1\n1 1" }, { "input": "2 2 0 1 0 4\n1 1\n1 2\n2 2\n2 1", "output": "1 2\n1 1\n2 1\n2 2" }, { "input": "2 2 0 0 1 4\n1 1\n1 2\n2 2\n2 1", "output": "2 1\n1 1\n1 2\n2 2" }, { "input": "2 1 1 0 0 2\n1 1\n2 1", "output": "1 2\n1 1" }, { "input": "2 1 0 1 0 2\n1 1\n2 1", "output": "1 1\n2 1" }, { "input": "2 1 0 0 1 2\n1 1\n2 1", "output": "1 1\n1 2" }, { "input": "1 1 0 1 0 2\n1 1\n1 1", "output": "1 1\n1 1" } ]
1,638,455,716
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
102,400
import sys import collections import bisect input = sys.stdin.readline ip = lambda: input().rstrip('\n') IP = lambda: list(map(int, ip().split())) def horizontal_flip(x): global n, m x[1] = m+1 - x[1] return x def vertical_flip(x): global n, m x[0] = n+1 - x[0] return x def rotate(x, clockwise = 0): x[0], x[1] = x[1], x[0] if clockwise: x = horizontal_flip(x) else: x = vertical_flip(x) return x n, m, x, y, z, p = IP() P = [] for i in range(p): P.append(IP()) for i in range(p): for cnt in range(x % 4): P[i] = rotate(P[i]) for cnt in range(y % 2): P[i] = horizontal_flip(P[i]) for cnt in range(z % 4): P[i] = rotate(P[i], 1) for i in range(p): print(*P[i])
Title: Inna and Huge Candy Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as (*i*,<=*j*). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has *p* candies: the *k*-th candy is at cell (*x**k*,<=*y**k*). The time moved closer to dinner and Inna was already going to eat *p* of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix *x* times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix *y* times. And then he rotated the matrix *z* times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input Specification: The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105). Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell. Output Specification: For each of the *p* candies, print on a single line its space-separated new coordinates. Demo Input: ['3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n'] Demo Output: ['1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n'] Note: Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
```python import sys import collections import bisect input = sys.stdin.readline ip = lambda: input().rstrip('\n') IP = lambda: list(map(int, ip().split())) def horizontal_flip(x): global n, m x[1] = m+1 - x[1] return x def vertical_flip(x): global n, m x[0] = n+1 - x[0] return x def rotate(x, clockwise = 0): x[0], x[1] = x[1], x[0] if clockwise: x = horizontal_flip(x) else: x = vertical_flip(x) return x n, m, x, y, z, p = IP() P = [] for i in range(p): P.append(IP()) for i in range(p): for cnt in range(x % 4): P[i] = rotate(P[i]) for cnt in range(y % 2): P[i] = horizontal_flip(P[i]) for cnt in range(z % 4): P[i] = rotate(P[i], 1) for i in range(p): print(*P[i]) ```
0
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01234567890123456789012345678901234567890123456789", "output": "25" }, { "input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "output": "10" }, { "input": "cjw2dwmr10pku4yxohe0wglktd", "output": "4" }, { "input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "output": "13" }, { "input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1", "output": "13" }, { "input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs", "output": "8" }, { "input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc", "output": "14" }, { "input": "2222", "output": "0" }, { "input": "13579", "output": "5" }, { "input": "1", "output": "1" }, { "input": "0", "output": "0" }, { "input": "a", "output": "1" }, { "input": "y", "output": "0" }, { "input": "w", "output": "0" }, { "input": "oo", "output": "2" }, { "input": "oy", "output": "1" }, { "input": "yo", "output": "1" }, { "input": "yy", "output": "0" }, { "input": "a0", "output": "1" }, { "input": "a9", "output": "2" }, { "input": "y0", "output": "0" }, { "input": "y7", "output": "1" }, { "input": "0a", "output": "1" }, { "input": "3a", "output": "2" }, { "input": "06", "output": "0" }, { "input": "07", "output": "1" }, { "input": "70", "output": "1" }, { "input": "77", "output": "2" }, { "input": "13570", "output": "4" }, { "input": "0000000000011111", "output": "5" }, { "input": "1357", "output": "4" }, { "input": "uuuuuuuuuuuuuuuuuu", "output": "18" }, { "input": "gabieurat", "output": "5" } ]
1,624,393,339
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
s = list(input()) ans = 0 v = ['a','e','i','o','u'] n = ['0', '2', '4', '6', '8'] for i in s: if i in v or i in n: ans += 1 print(ans)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. Input Specification: The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. Output Specification: Print a single integer, the minimum number of cards you must turn over to verify your claim. Demo Input: ['ee\n', 'z\n', '0ay1\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
```python s = list(input()) ans = 0 v = ['a','e','i','o','u'] n = ['0', '2', '4', '6', '8'] for i in s: if i in v or i in n: ans += 1 print(ans) ```
0
108
A
Palindromic Times
PROGRAMMING
1,000
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
500
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, { "input": "12:15", "output": "12:21" }, { "input": "07:07", "output": "10:01" }, { "input": "00:17", "output": "01:10" }, { "input": "04:55", "output": "05:50" }, { "input": "02:17", "output": "02:20" }, { "input": "07:56", "output": "10:01" }, { "input": "00:29", "output": "01:10" }, { "input": "23:31", "output": "23:32" }, { "input": "19:30", "output": "20:02" }, { "input": "12:14", "output": "12:21" }, { "input": "17:32", "output": "20:02" }, { "input": "03:44", "output": "04:40" }, { "input": "07:15", "output": "10:01" }, { "input": "18:42", "output": "20:02" }, { "input": "08:56", "output": "10:01" }, { "input": "04:50", "output": "05:50" }, { "input": "14:32", "output": "14:41" }, { "input": "23:23", "output": "23:32" }, { "input": "08:35", "output": "10:01" }, { "input": "03:32", "output": "04:40" }, { "input": "07:59", "output": "10:01" }, { "input": "14:12", "output": "14:41" }, { "input": "23:52", "output": "00:00" }, { "input": "16:36", "output": "20:02" }, { "input": "17:50", "output": "20:02" }, { "input": "06:59", "output": "10:01" }, { "input": "16:50", "output": "20:02" }, { "input": "00:00", "output": "01:10" }, { "input": "23:59", "output": "00:00" }, { "input": "23:33", "output": "00:00" } ]
1,632,385,345
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
s=input("") l=s.split(":") rev=l[0][::-1] nrev,ntime=int(rev),int(l[1]) if(int(l[0])<=23): if(nrev<60 and ntime+10<=60): if(nrev<=ntime): out=str(int(l[0])+1)+":"+str(nrev+10) if(len(out)==5): print(out) else: print("0"+out) else: print(l[0]+":"+rev) else: if(int(l[0])>=15): print("20:02") else: print("10:01") else: print("00:00")
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him. Input Specification: The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. Output Specification: Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. Demo Input: ['12:21\n', '23:59\n'] Demo Output: ['13:31\n', '00:00\n'] Note: none
```python s=input("") l=s.split(":") rev=l[0][::-1] nrev,ntime=int(rev),int(l[1]) if(int(l[0])<=23): if(nrev<60 and ntime+10<=60): if(nrev<=ntime): out=str(int(l[0])+1)+":"+str(nrev+10) if(len(out)==5): print(out) else: print("0"+out) else: print(l[0]+":"+rev) else: if(int(l[0])>=15): print("20:02") else: print("10:01") else: print("00:00") ```
0
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,664,376,060
2,147,483,647
Python 3
OK
TESTS
45
92
0
# from math import gcd a, b, n = map( int, input().split() ) # def nod(x, y): # while(y): # x, x = y, x % y # return x def gcd_rem_division(num1, num2): while num1 != 0 and num2 != 0: if num1 >= num2: num1 %= num2 else: num2 %= num1 return num1 or num2 last_move = True while n > 0: n -= gcd_rem_division(a, n) if last_move else gcd_rem_division(b, n) last_move = False if last_move else True print(1) if last_move else print(0)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python # from math import gcd a, b, n = map( int, input().split() ) # def nod(x, y): # while(y): # x, x = y, x % y # return x def gcd_rem_division(num1, num2): while num1 != 0 and num2 != 0: if num1 >= num2: num1 %= num2 else: num2 %= num1 return num1 or num2 last_move = True while n > 0: n -= gcd_rem_division(a, n) if last_move else gcd_rem_division(b, n) last_move = False if last_move else True print(1) if last_move else print(0) ```
3
895
A
Pizza Separation
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
[ "4\n90 90 90 90\n", "3\n100 100 160\n", "1\n360\n", "4\n170 30 150 10\n" ]
[ "0\n", "40\n", "360\n", "0\n" ]
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
500
[ { "input": "4\n90 90 90 90", "output": "0" }, { "input": "3\n100 100 160", "output": "40" }, { "input": "1\n360", "output": "360" }, { "input": "4\n170 30 150 10", "output": "0" }, { "input": "5\n10 10 10 10 320", "output": "280" }, { "input": "8\n45 45 45 45 45 45 45 45", "output": "0" }, { "input": "3\n120 120 120", "output": "120" }, { "input": "5\n110 90 70 50 40", "output": "40" }, { "input": "2\n170 190", "output": "20" }, { "input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10", "output": "10" }, { "input": "5\n30 60 180 60 30", "output": "0" }, { "input": "2\n359 1", "output": "358" }, { "input": "5\n100 100 30 100 30", "output": "40" }, { "input": "5\n36 34 35 11 244", "output": "128" }, { "input": "5\n96 94 95 71 4", "output": "18" }, { "input": "2\n85 275", "output": "190" }, { "input": "3\n281 67 12", "output": "202" }, { "input": "5\n211 113 25 9 2", "output": "62" }, { "input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1", "output": "212" }, { "input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "92" }, { "input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n1 1 358", "output": "356" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341", "output": "322" }, { "input": "33\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328", "output": "296" }, { "input": "70\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291", "output": "222" }, { "input": "130\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231", "output": "102" }, { "input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161", "output": "0" }, { "input": "222\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139", "output": "0" }, { "input": "10\n8 3 11 4 1 10 10 1 8 304", "output": "248" }, { "input": "12\n8 7 7 3 11 2 10 1 10 8 10 283", "output": "206" }, { "input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275", "output": "190" }, { "input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280", "output": "200" }, { "input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275", "output": "190" }, { "input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189", "output": "18" }, { "input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189", "output": "18" }, { "input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168", "output": "0" }, { "input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5", "output": "0" }, { "input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68", "output": "0" }, { "input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "6\n27 15 28 34 41 215", "output": "70" }, { "input": "7\n41 38 41 31 22 41 146", "output": "14" }, { "input": "8\n24 27 34 23 29 23 30 170", "output": "20" }, { "input": "9\n11 11 20 20 33 32 35 26 172", "output": "6" }, { "input": "10\n36 13 28 13 33 34 23 25 34 121", "output": "0" }, { "input": "11\n19 37 13 41 37 15 32 12 19 35 100", "output": "10" }, { "input": "12\n37 25 34 38 21 24 34 38 11 29 28 41", "output": "2" }, { "input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28", "output": "2" }, { "input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44", "output": "4" }, { "input": "3\n95 91 174", "output": "12" }, { "input": "4\n82 75 78 125", "output": "46" }, { "input": "6\n87 75 88 94 15 1", "output": "4" }, { "input": "10\n27 52 58 64 45 64 1 19 2 28", "output": "12" }, { "input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1", "output": "0" }, { "input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3", "output": "0" }, { "input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1", "output": "0" }, { "input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2", "output": "0" }, { "input": "5\n35 80 45 100 100", "output": "40" }, { "input": "4\n90 179 90 1", "output": "2" }, { "input": "5\n50 50 20 160 80", "output": "0" }, { "input": "5\n30 175 30 5 120", "output": "10" }, { "input": "4\n170 30 10 150", "output": "20" }, { "input": "6\n90 30 90 30 90 30", "output": "60" }, { "input": "4\n70 80 110 100", "output": "20" }, { "input": "7\n35 45 70 100 10 10 90", "output": "0" }, { "input": "6\n50 90 10 90 20 100", "output": "20" }, { "input": "6\n10 155 162 1 26 6", "output": "18" }, { "input": "7\n80 90 80 45 10 10 45", "output": "20" }, { "input": "4\n18 36 162 144", "output": "36" }, { "input": "5\n20 50 50 160 80", "output": "40" }, { "input": "5\n10 30 140 20 160", "output": "0" }, { "input": "6\n90 80 60 50 40 40", "output": "20" }, { "input": "9\n40 20 20 20 20 20 20 40 160", "output": "40" }, { "input": "4\n90 54 90 126", "output": "72" }, { "input": "4\n150 170 30 10", "output": "20" }, { "input": "8\n130 12 13 85 41 67 5 7", "output": "26" }, { "input": "7\n70 170 20 10 30 30 30", "output": "20" }, { "input": "8\n100 100 50 50 15 15 15 15", "output": "40" }, { "input": "4\n100 70 80 110", "output": "20" }, { "input": "5\n160 130 40 20 10", "output": "20" }, { "input": "4\n20 149 151 40", "output": "22" }, { "input": "4\n100 10 100 150", "output": "60" }, { "input": "6\n19 64 105 168 1 3", "output": "16" }, { "input": "8\n10 10 70 70 90 90 10 10", "output": "0" } ]
1,514,994,855
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
53,964,800
def main(): x = int(input()) a = list(map(int,input().split(" "))) while x != 4: a.append(0) x = x + 1 a = sorted(a) print(abs(a[0]+a[3]-a[1]-a[2])) main()
Title: Pizza Separation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. Output Specification: Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya. Demo Input: ['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n'] Demo Output: ['0\n', '40\n', '360\n', '0\n'] Note: In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
```python def main(): x = int(input()) a = list(map(int,input().split(" "))) while x != 4: a.append(0) x = x + 1 a = sorted(a) print(abs(a[0]+a[3]-a[1]-a[2])) main() ```
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,673,862,497
2,147,483,647
PyPy 3-64
OK
TESTS
64
124
0
k = int(input()) l = int(input()) p = k importance = 0 cifiera = False if k == 1: cifiera = (k == l) else: while p < 2 ** 31: if p == l: cifiera = True break p *= k importance += 1 if cifiera: print('YES') print(importance) 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()) l = int(input()) p = k importance = 0 cifiera = False if k == 1: cifiera = (k == l) else: while p < 2 ** 31: if p == l: cifiera = True break p *= k importance += 1 if cifiera: print('YES') print(importance) else: print('NO') ```
3
680
A
Bear and Five Cards
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number. Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
[ "7 3 7 3 20\n", "7 9 3 1 8\n", "10 10 10 10 10\n" ]
[ "26\n", "28\n", "20\n" ]
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. - Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34. You are asked to minimize the sum so the answer is 26. In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28. In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
500
[ { "input": "7 3 7 3 20", "output": "26" }, { "input": "7 9 3 1 8", "output": "28" }, { "input": "10 10 10 10 10", "output": "20" }, { "input": "8 7 1 8 7", "output": "15" }, { "input": "7 7 7 8 8", "output": "16" }, { "input": "8 8 8 2 2", "output": "4" }, { "input": "8 8 2 2 2", "output": "6" }, { "input": "5 50 5 5 60", "output": "110" }, { "input": "100 100 100 100 100", "output": "200" }, { "input": "1 1 1 1 1", "output": "2" }, { "input": "29 29 20 20 20", "output": "58" }, { "input": "20 29 20 29 20", "output": "58" }, { "input": "31 31 20 20 20", "output": "60" }, { "input": "20 20 20 31 31", "output": "60" }, { "input": "20 31 20 31 20", "output": "60" }, { "input": "20 20 20 30 30", "output": "60" }, { "input": "30 30 20 20 20", "output": "60" }, { "input": "8 1 8 8 8", "output": "9" }, { "input": "1 1 1 8 1", "output": "9" }, { "input": "1 2 3 4 5", "output": "15" }, { "input": "100 99 98 97 96", "output": "490" }, { "input": "1 1 100 100 100", "output": "2" }, { "input": "100 100 99 99 98", "output": "296" }, { "input": "98 99 100 99 100", "output": "296" }, { "input": "1 90 1 91 1", "output": "181" }, { "input": "60 1 75 1 92", "output": "227" }, { "input": "15 40 90 40 90", "output": "95" }, { "input": "1 1 15 20 20", "output": "17" }, { "input": "90 11 11 10 10", "output": "110" }, { "input": "20 21 22 23 24", "output": "110" }, { "input": "1 1 2 98 99", "output": "199" }, { "input": "3 7 7 7 10", "output": "13" }, { "input": "1 3 3 3 1", "output": "2" }, { "input": "1 9 9 9 10", "output": "11" }, { "input": "100 1 1 1 1", "output": "101" }, { "input": "2 2 2 100 100", "output": "6" }, { "input": "1 2 2 2 2", "output": "3" }, { "input": "1 1 2 2 5", "output": "7" }, { "input": "1 2 3 4 1", "output": "9" }, { "input": "11 10 10 10 10", "output": "21" }, { "input": "2 2 2 10 10", "output": "6" }, { "input": "1 1 1 1 4", "output": "5" }, { "input": "98 98 98 98 23", "output": "121" }, { "input": "1 2 3 100 100", "output": "6" }, { "input": "2 2 5 10 10", "output": "9" }, { "input": "2 2 3 3 3", "output": "4" }, { "input": "1 1 1 1 2", "output": "3" }, { "input": "12 12 7 7 7", "output": "21" } ]
1,600,349,121
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
139
0
import math def main(): a = list(map(int, input().split())) if len(a) == len(set(a)): print(sum(a)) else: s = sum(a) b = set(a) b = list(b) b.sort() b.reverse() for x in b: if a.count(x) >= 3: s -= x * 3 break elif a.count(x) == 2: s -= 2 * x break print(s) if __name__ == '__main__': main()
Title: Bear and Five Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number. Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? Input Specification: The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. Output Specification: Print the minimum possible sum of numbers written on remaining cards. Demo Input: ['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n'] Demo Output: ['26\n', '28\n', '20\n'] Note: In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. - Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34. You are asked to minimize the sum so the answer is 26. In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28. In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
```python import math def main(): a = list(map(int, input().split())) if len(a) == len(set(a)): print(sum(a)) else: s = sum(a) b = set(a) b = list(b) b.sort() b.reverse() for x in b: if a.count(x) >= 3: s -= x * 3 break elif a.count(x) == 2: s -= 2 * x break print(s) if __name__ == '__main__': main() ```
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,563,368,919
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
124
204,800
n=int(input()) s=input() freq=[0]*26 for i in s: freq[ord(i)-ord('a')]+=1 change=0 for i in range(26): if freq[i]: change+=freq[i]-1 print(change)
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 n=int(input()) s=input() freq=[0]*26 for i in s: freq[ord(i)-ord('a')]+=1 change=0 for i in range(26): if freq[i]: change+=freq[i]-1 print(change) ```
0
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color.
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "output": "NO" }, { "input": ".#.#\n#.#.\n#.#.\n#.#.", "output": "NO" }, { "input": ".#.#\n#.#.\n#.#.\n.#.#", "output": "NO" }, { "input": "#.#.\n#.#.\n#.#.\n#.#.", "output": "NO" }, { "input": ".#.#\n.#.#\n.#.#\n.#.#", "output": "NO" }, { "input": "#..#\n.##.\n####\n####", "output": "YES" }, { "input": "#.#.\n.###\n#.#.\n.###", "output": "YES" }, { "input": "#..#\n.##.\n.##.\n#..#", "output": "YES" }, { "input": ".##.\n.#..\n##.#\n#..#", "output": "YES" }, { "input": ".##.\n##..\n#..#\n..##", "output": "YES" }, { "input": "##..\n##..\n..##\n..##", "output": "YES" }, { "input": ".#..\n###.\n.#.#\n..#.", "output": "YES" }, { "input": "###.\n###.\n...#\n...#", "output": "YES" }, { "input": "#.##\n##.#\n#.##\n##.#", "output": "YES" }, { "input": ".#.#\n#.#.\n.#.#\n#.##", "output": "YES" }, { "input": "##..\n..##\n##..\n...#", "output": "YES" }, { "input": ".#..\n..##\n##..\n..##", "output": "YES" }, { "input": "##..\n...#\n##..\n...#", "output": "YES" }, { "input": ".#..\n..#.\n.#..\n..#.", "output": "YES" }, { "input": "....\n....\n....\n.#.#", "output": "YES" }, { "input": "....\n....\n....\n...#", "output": "YES" } ]
1,584,817,558
2,147,483,647
Python 3
OK
TESTS
30
124
307,200
n = 4 vois = 1 def nb_same_square(mat,x,y): nb_sign1 = 0 for dx in range(vois + 1): for dy in range(vois + 1): elem = mat[x + dx][y + dy] nb_sign1 += (1 if elem == '#' else 0) nb_sign2 = 4 - nb_sign1 max_same = max(nb_sign1,nb_sign2) return max_same def solve(mat): for i in range(n - 1): for j in range(n - 1): if nb_same_square(mat,i,j) >= 3: print('YES') return print('NO') mat = [[None for i in range(n)] for j in range(n)] for i in range(n): s = input() for j in range(n): mat[i][j] = s[j] solve(mat)
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color. Input Specification: Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. Output Specification: Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. Demo Input: ['####\n.#..\n####\n....\n', '####\n....\n####\n....\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
```python n = 4 vois = 1 def nb_same_square(mat,x,y): nb_sign1 = 0 for dx in range(vois + 1): for dy in range(vois + 1): elem = mat[x + dx][y + dy] nb_sign1 += (1 if elem == '#' else 0) nb_sign2 = 4 - nb_sign1 max_same = max(nb_sign1,nb_sign2) return max_same def solve(mat): for i in range(n - 1): for j in range(n - 1): if nb_same_square(mat,i,j) >= 3: print('YES') return print('NO') mat = [[None for i in range(n)] for j in range(n)] for i in range(n): s = input() for j in range(n): mat[i][j] = s[j] solve(mat) ```
3
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108). The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108).
Output a single integer — the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25", "output": "25" }, { "input": "100000000\n100000000", "output": "100000000" }, { "input": "7\n1234", "output": "82" }, { "input": "1\n1", "output": "1" }, { "input": "1\n100000000", "output": "0" }, { "input": "100000000\n1", "output": "1" }, { "input": "1\n2", "output": "0" }, { "input": "2\n1", "output": "1" }, { "input": "2\n2", "output": "2" }, { "input": "2\n3", "output": "3" }, { "input": "2\n4", "output": "0" }, { "input": "2\n5", "output": "1" }, { "input": "25\n33554432", "output": "0" }, { "input": "26\n33554432", "output": "33554432" }, { "input": "25\n67108864", "output": "0" }, { "input": "26\n67108864", "output": "0" }, { "input": "25\n92831989", "output": "25723125" }, { "input": "26\n92831989", "output": "25723125" }, { "input": "27\n92831989", "output": "92831989" }, { "input": "29\n92831989", "output": "92831989" }, { "input": "30\n92831989", "output": "92831989" }, { "input": "31\n92831989", "output": "92831989" }, { "input": "99812399\n93172892", "output": "93172892" }, { "input": "67108864\n12345678", "output": "12345678" }, { "input": "3\n98391849", "output": "1" }, { "input": "13\n1231232", "output": "2432" }, { "input": "18\n9842194", "output": "142866" }, { "input": "24\n71237177", "output": "4128313" }, { "input": "11\n65535", "output": "2047" }, { "input": "11\n65536", "output": "0" }, { "input": "12\n123", "output": "123" }, { "input": "123456\n12", "output": "12" }, { "input": "88\n888", "output": "888" }, { "input": "888\n88", "output": "88" }, { "input": "8888\n8888", "output": "8888" }, { "input": "64\n128", "output": "128" }, { "input": "128\n64", "output": "64" }, { "input": "60\n9999999", "output": "9999999" }, { "input": "200\n100000", "output": "100000" }, { "input": "3\n8", "output": "0" }, { "input": "10000000\n25024886", "output": "25024886" }, { "input": "100\n100000", "output": "100000" }, { "input": "99999999\n100000000", "output": "100000000" }, { "input": "70\n12345678", "output": "12345678" } ]
1,638,953,205
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
45,875,200
# from time import time as t n, m = int(input()), int(input()) # s = t() print(pow(m, 1, pow(2, n))) # print(t()-s)
Title: Modular Exponentiation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108). The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). Output Specification: Output a single integer — the value of . Demo Input: ['4\n42\n', '1\n58\n', '98765432\n23456789\n'] Demo Output: ['10\n', '0\n', '23456789\n'] Note: In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
```python # from time import time as t n, m = int(input()), int(input()) # s = t() print(pow(m, 1, pow(2, n))) # print(t()-s) ```
0
444
C
DZY Loves Colors
PROGRAMMING
2,400
[ "data structures" ]
null
null
DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consists of *n* units (they are numbered from 1 to *n* from left to right). The color of the *i*-th unit of the ribbon is *i* at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first. DZY loves painting, we know. He takes up a paintbrush with color *x* and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit *i* currently is *y*. When it is painted by this paintbrush, the color of the unit becomes *x*, and the colorfulness of the unit increases by |*x*<=-<=*y*|. DZY wants to perform *m* operations, each operation can be one of the following: 1. Paint all the units with numbers between *l* and *r* (both inclusive) with color *x*. 1. Ask the sum of colorfulness of the units between *l* and *r* (both inclusive). Can you help DZY?
The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105). Each of the next *m* lines begins with a integer *type* (1<=≤<=*type*<=≤<=2), which represents the type of this operation. If *type*<==<=1, there will be 3 more integers *l*,<=*r*,<=*x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*x*<=≤<=108) in this line, describing an operation 1. If *type*<==<=2, there will be 2 more integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) in this line, describing an operation 2.
For each operation 2, print a line containing the answer — sum of colorfulness.
[ "3 3\n1 1 2 4\n1 2 3 5\n2 1 3\n", "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3\n", "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10\n" ]
[ "8\n", "3\n2\n1\n", "129\n" ]
In the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0]. After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0]. After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2]. So the answer to the only operation of type 2 is 8.
2,000
[ { "input": "3 3\n1 1 2 4\n1 2 3 5\n2 1 3", "output": "8" }, { "input": "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3", "output": "3\n2\n1" }, { "input": "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10", "output": "129" }, { "input": "3 3\n1 2 2 31844623\n1 1 2 37662529\n2 2 3", "output": "37662527" }, { "input": "3 3\n2 2 3\n1 1 3 72971211\n2 2 3", "output": "0\n145942417" }, { "input": "10 10\n1 5 9 60144710\n2 3 3\n2 3 4\n2 6 10\n1 8 9 11764737\n1 1 9 38454635\n1 3 10 58013969\n1 2 3 49601991\n1 1 3 73003418\n2 4 6", "output": "0\n0\n240578810\n260802192" } ]
1,689,251,538
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689251538.034106")# 1689251538.034152
Title: DZY Loves Colors Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consists of *n* units (they are numbered from 1 to *n* from left to right). The color of the *i*-th unit of the ribbon is *i* at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first. DZY loves painting, we know. He takes up a paintbrush with color *x* and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit *i* currently is *y*. When it is painted by this paintbrush, the color of the unit becomes *x*, and the colorfulness of the unit increases by |*x*<=-<=*y*|. DZY wants to perform *m* operations, each operation can be one of the following: 1. Paint all the units with numbers between *l* and *r* (both inclusive) with color *x*. 1. Ask the sum of colorfulness of the units between *l* and *r* (both inclusive). Can you help DZY? Input Specification: The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105). Each of the next *m* lines begins with a integer *type* (1<=≤<=*type*<=≤<=2), which represents the type of this operation. If *type*<==<=1, there will be 3 more integers *l*,<=*r*,<=*x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*x*<=≤<=108) in this line, describing an operation 1. If *type*<==<=2, there will be 2 more integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) in this line, describing an operation 2. Output Specification: For each operation 2, print a line containing the answer — sum of colorfulness. Demo Input: ['3 3\n1 1 2 4\n1 2 3 5\n2 1 3\n', '3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3\n', '10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10\n'] Demo Output: ['8\n', '3\n2\n1\n', '129\n'] Note: In the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0]. After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0]. After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2]. So the answer to the only operation of type 2 is 8.
```python print("_RANDOM_GUESS_1689251538.034106")# 1689251538.034152 ```
0
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", "output": "9" }, { "input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2", "output": "5" }, { "input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352", "output": "0" }, { "input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0" }, { "input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5", "output": "0" }, { "input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1", "output": "0" }, { "input": "1 1 1\n1 1", "output": "0" }, { "input": "10 10 4\n5 9\n6 9\n6 10\n5 10", "output": "4" }, { "input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000", "output": "4" }, { "input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2", "output": "5" }, { "input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000", "output": "4" } ]
1,697,698,268
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
# -*- coding: utf-8 -*- """ Created on Wed Oct 18 16:18:28 2023 @author: masiyu004 """ def y(a,b,x): for i in [(1,1),(1,-1),(-1,1),(-1,-1)]: nexta=a+i[0] nextb=b+i[1] if 0<=nexta<=n-1 and 0<=nextb<=m-1: test1=x[nexta][nextb] test2=x[nexta][b] test3=x[a][nextb] if (test1,test2,test3)==(1,1,1): return True return False import numpy n,m,k=map(int,input().split()) x=numpy.zeros(shape=(n+2,m+2)) s=0 for i in range(k): a,b=map(int,input().split()) x[a-1][b-1]=1 if s==0 and y(a,b,x): s=i+1 print(s)
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. Input Specification: The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. Output Specification: If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. Demo Input: ['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n'] Demo Output: ['4\n', '5\n', '0\n'] Note: none
```python # -*- coding: utf-8 -*- """ Created on Wed Oct 18 16:18:28 2023 @author: masiyu004 """ def y(a,b,x): for i in [(1,1),(1,-1),(-1,1),(-1,-1)]: nexta=a+i[0] nextb=b+i[1] if 0<=nexta<=n-1 and 0<=nextb<=m-1: test1=x[nexta][nextb] test2=x[nexta][b] test3=x[a][nextb] if (test1,test2,test3)==(1,1,1): return True return False import numpy n,m,k=map(int,input().split()) x=numpy.zeros(shape=(n+2,m+2)) s=0 for i in range(k): a,b=map(int,input().split()) x[a-1][b-1]=1 if s==0 and y(a,b,x): s=i+1 print(s) ```
-1
137
A
Postcards and photos
PROGRAMMING
900
[ "implementation" ]
null
null
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?
The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo.
Print the only number — the minimum number of times Polycarpus has to visit the closet.
[ "CPCPCPC\n", "CCCCCCPPPPPP\n", "CCCCCCPPCPPPPPPPPPP\n", "CCCCCCCCCC\n" ]
[ "7\n", "4\n", "6\n", "2\n" ]
In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice. In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
500
[ { "input": "CPCPCPC", "output": "7" }, { "input": "CCCCCCPPPPPP", "output": "4" }, { "input": "CCCCCCPPCPPPPPPPPPP", "output": "6" }, { "input": "CCCCCCCCCC", "output": "2" }, { "input": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "output": "20" }, { "input": "CPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCP", "output": "100" }, { "input": "CCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPP", "output": "28" }, { "input": "P", "output": "1" }, { "input": "C", "output": "1" }, { "input": "PC", "output": "2" }, { "input": "PPPPP", "output": "1" }, { "input": "PPPP", "output": "1" }, { "input": "CCCCCCCCCC", "output": "2" }, { "input": "CP", "output": "2" }, { "input": "CPCCPCPPPC", "output": "7" }, { "input": "PPCPCCPCPPCCPPPPPPCP", "output": "12" }, { "input": "PCPCCPCPPCCPCPCCPPPPPCPCPCPCCC", "output": "20" }, { "input": "CCPPPPPCPCCPPPCCPPCPCCPCPPCPPCCCPPCPPPCC", "output": "21" }, { "input": "CPPCCCCCCPCCCCPCCPCPPPCPCCCCCCCPCCPPCCCPCCCCCPPCCC", "output": "23" }, { "input": "PPCCCCPPCCPPPCCCCPPPPPCPPPCPPPCCCPCCCPCPPPCPCCCPCCPPCCPPPPPC", "output": "26" }, { "input": "PPCPPCCCCCPCCCPCCPCCCCPPPCCCCPCPCCPCPCPCPPPPCCPPPPPPPCPCPPPCPCPCPCPPPC", "output": "39" }, { "input": "CCPCPPPPCPPPPCCCCPCCPCPCCPPCPCCCPPCCCCPCCCPCPCCPPPCPPPCPCPPPPPCPCCPCCPPCCCPCPPPC", "output": "43" }, { "input": "CCPPCPCPCPPCCCPCPPPCCCCCPCPPCCCPPCPCPPPPCPPCPPPPCCCPCCPCPPPCPCPPCCCPCCCCCCPCCCCPCCPPPPCCPP", "output": "47" }, { "input": "PPCPPPPCCCCPPPPCPPPPPPPPCPCPPCCPPPPPPPPCPPPPCCCCPPPPCPPCPCPPPCCPPCPPCCCPCPPCCCCCCPCPCPCPPCPCPCPPPCCC", "output": "49" }, { "input": "CCPCCCPPCPPCPCCCPCPPCPPCPPCCCCCCCPCPPCPCCPCCPCPCPCCCPCCCPPPCCPCCPPCCCCCPPPPCPCPPCPCPCCPCPPP", "output": "53" }, { "input": "PCPCPPPPCPCPPPCPPCCCPCPCPCPPCPPPPCCPPPCPPPCPPPPCCPPCCCPCCPCCCCPCCPCPPCPCCCPCPPCP", "output": "47" }, { "input": "PCCPPCCCPPCPPCC", "output": "8" }, { "input": "CCCPPPPPPCCCCPCCPCCCCCCPCCCPPPCPC", "output": "15" }, { "input": "CPPCCPPCCPPPCCCPPPPCPPPPPPPCCPCPCCPPPPCCCPPCCPCCPPCCCPCCPCPPPPCCPP", "output": "31" }, { "input": "CCCCCPPPCCPCPCCPPPPCPCCCPCPPCPCPPPPPCCPCPCPC", "output": "25" }, { "input": "PPPPPPPPPCPCP", "output": "6" }, { "input": "PPPCPCPCCCPPCPCCPPPPCCCPCCP", "output": "15" }, { "input": "PCPCCPCPPPPPPCPCCPCPCPCCPPPCPCPCPPCPPCCPCPCCCPCCCPPCPCPCCPCPPPPCCCCCCPPCCPCCCCCPCCCCPPPCPCCCCCPCPCP", "output": "59" }, { "input": "PCCPCPPCCCCCPCCCPCCCPPCCCCCPPPCCPPPPPPPPCPPPCCPPCPPCPCP", "output": "26" }, { "input": "CPCPCCPPPPCCPPCPPCPPCCCCCCPCCPPPCPPCPCCCCCCPCPCCCCCPCCCCCCPCCPPCCP", "output": "35" }, { "input": "PPCCCCCCPP", "output": "4" }, { "input": "CCCCCCCCCCCCPPCCCCPP", "output": "6" }, { "input": "PPPPPPPPPPPCCCCCCCCCCCCCCCCCCP", "output": "8" }, { "input": "PPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCPPPPCCCC", "output": "10" }, { "input": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCPPPC", "output": "12" }, { "input": "CCCCCCCCCPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCC", "output": "13" }, { "input": "CCCCCCCCCCCCCCCCCCCCCCCCCPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "output": "15" }, { "input": "CCCCCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCPPPPPPPCCPPP", "output": "18" }, { "input": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPP", "output": "19" }, { "input": "PPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCCCPPPPCCCCCPCC", "output": "23" } ]
1,531,914,531
2,147,483,647
Python 3
OK
TESTS
45
248
0
import sys import math s=str(input()) c,p,cona=0,0,0 for i in range(len(s)): if(s[i]=='C'): c+=1 if(p!=0): cona+=p//5 if(p%5!=0): cona+=1 p=0 else: p+=1 if(c!=0): cona+=c//5 if (c%5!=0): cona+=1 c=0 if(c!=0 or p!=0): cona+=c//5+p//5 if(c%5!=0 or p%5!=0): cona+=1 print(cona)
Title: Postcards and photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items? Input Specification: The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo. Output Specification: Print the only number — the minimum number of times Polycarpus has to visit the closet. Demo Input: ['CPCPCPC\n', 'CCCCCCPPPPPP\n', 'CCCCCCPPCPPPPPPPPPP\n', 'CCCCCCCCCC\n'] Demo Output: ['7\n', '4\n', '6\n', '2\n'] Note: In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice. In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
```python import sys import math s=str(input()) c,p,cona=0,0,0 for i in range(len(s)): if(s[i]=='C'): c+=1 if(p!=0): cona+=p//5 if(p%5!=0): cona+=1 p=0 else: p+=1 if(c!=0): cona+=c//5 if (c%5!=0): cona+=1 c=0 if(c!=0 or p!=0): cona+=c//5+p//5 if(c%5!=0 or p%5!=0): cona+=1 print(cona) ```
3
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes).
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth", "output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv", "output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES" }, { "input": "1\nz", "output": "NO" }, { "input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO" }, { "input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr", "output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES" }, { "input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES" }, { "input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO\nNO\nNO" }, { "input": "2\nab\nba", "output": "NO\nNO" }, { "input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", "output": "NO\nYES" }, { "input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na", "output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" } ]
1,651,937,711
2,147,483,647
Python 3
OK
TESTS
55
62
102,400
from sys import stdin from math import log, floor, ceil, gcd from collections import defaultdict as dd #from bisect import bisect_left as bl,bisect_right as br input = stdin.readline def inp(): return int(stdin.readline()) def rs(): return stdin.readline().strip() def ra(typ): return list(map(typ, stdin.readline().split())) def rv(typ): return map(typ, stdin.readline().split()) #mod = 1000000007 def main(): x = set() for _ in range(inp()): s = rs() if s in x: print("YES") continue x.add(s) print("NO") main()
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes). Input Specification: First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. Output Specification: Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower). Demo Input: ['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n'] Demo Output: ['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n'] Note: In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
```python from sys import stdin from math import log, floor, ceil, gcd from collections import defaultdict as dd #from bisect import bisect_left as bl,bisect_right as br input = stdin.readline def inp(): return int(stdin.readline()) def rs(): return stdin.readline().strip() def ra(typ): return list(map(typ, stdin.readline().split())) def rv(typ): return map(typ, stdin.readline().split()) #mod = 1000000007 def main(): x = set() for _ in range(inp()): s = rs() if s in x: print("YES") continue x.add(s) print("NO") main() ```
3
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479" }, { "input": "1\n536870912 32", "output": "16777216" }, { "input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000" }, { "input": "3\n1000000000 1\n1000000000 1\n1 100000000", "output": "1000000000\n1000000000\n100000000" } ]
1,683,454,550
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
1,000
0
n=int(input()) for i in range(0,n): a=list(map(int,input().split())) a.sort() x=a[0] y=a[1] c=0 while(x!=0 and y!=0): y=y-x if x>=y: t=x x=y y=t c=c+1 print(c)
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? Input Specification: The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). Output Specification: Print the sought number of operations for each pair on a single line. Demo Input: ['2\n4 17\n7 987654321\n'] Demo Output: ['8\n141093479\n'] Note: none
```python n=int(input()) for i in range(0,n): a=list(map(int,input().split())) a.sort() x=a[0] y=a[1] c=0 while(x!=0 and y!=0): y=y-x if x>=y: t=x x=y y=t c=c+1 print(c) ```
0
855
B
Marvolo Gaunt's Ring
PROGRAMMING
1,500
[ "brute force", "data structures", "dp" ]
null
null
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
[ "5 1 2 3\n1 2 3 4 5\n", "5 1 2 -3\n-1 -2 -3 -4 -5\n" ]
[ "30\n", "12\n" ]
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
1,000
[ { "input": "5 1 2 3\n1 2 3 4 5", "output": "30" }, { "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12" }, { "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046" }, { "input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "output": "547306902373544674" }, { "input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162", "output": "1876641179289775029" }, { "input": "1 0 0 0\n0", "output": "0" }, { "input": "1 1000000000 1000000000 1000000000\n1000000000", "output": "3000000000000000000" }, { "input": "1 -1000000000 -1000000000 1000000000\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 -1000000000\n1000000000", "output": "-3000000000000000000" }, { "input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000", "output": "-3000000000000000000" }, { "input": "1 1 1 1\n-1", "output": "-3" }, { "input": "1 -1 -1 -1\n1", "output": "-3" }, { "input": "1 1000000000 1000000000 1000000000\n-1000000000", "output": "-3000000000000000000" }, { "input": "1 1 2 3\n-1", "output": "-6" }, { "input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "3 1 1 1\n-1 -1 -1", "output": "-3" }, { "input": "1 -1000000000 0 0\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -100 -100 -100\n100", "output": "-30000" }, { "input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "1 999999999 999999999 999999999\n-999999999", "output": "-2999999994000000003" }, { "input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000", "output": "-1999999999000000000" }, { "input": "3 -2 3 -2\n1 2 1", "output": "2" }, { "input": "2 1 -1 1\n1 -1", "output": "1" }, { "input": "1 -1000000000 1 -1000000000\n1000000000", "output": "-1999999999000000000" }, { "input": "1 1000000000 1000000000 -1000000000\n-1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 0\n1000000000", "output": "-2000000000000000000" } ]
1,620,935,812
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
4
202
30,617,600
from sys import stdin,stdout nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) NI=float('-inf') def fn(pos,state): if pos>=n: if state in [0,1,2]:return NI return 0 if (pos,state) in dp:return dp[pos,state] if state==0: ans=max(fn(pos+1,0),a[pos]*p+fn(pos,1)) elif state==1: ans=max(fn(pos+1,1),a[pos]*q+fn(pos,2)) else: ans=max(fn(pos+1,2),a[pos]*r) dp[pos,state]=ans return ans for _ in range(1):#nmbr()): dp={} n,p,q,r=lst() a=lst() print(fn(0,0))
Title: Marvolo Gaunt's Ring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. Input Specification: First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Output Specification: Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Demo Input: ['5 1 2 3\n1 2 3 4 5\n', '5 1 2 -3\n-1 -2 -3 -4 -5\n'] Demo Output: ['30\n', '12\n'] Note: In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
```python from sys import stdin,stdout nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) NI=float('-inf') def fn(pos,state): if pos>=n: if state in [0,1,2]:return NI return 0 if (pos,state) in dp:return dp[pos,state] if state==0: ans=max(fn(pos+1,0),a[pos]*p+fn(pos,1)) elif state==1: ans=max(fn(pos+1,1),a[pos]*q+fn(pos,2)) else: ans=max(fn(pos+1,2),a[pos]*r) dp[pos,state]=ans return ans for _ in range(1):#nmbr()): dp={} n,p,q,r=lst() a=lst() print(fn(0,0)) ```
-1
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", "output": "Yes" }, { "input": "+", "output": "No" }, { "input": "-+", "output": "No" }, { "input": "--", "output": "Yes" }, { "input": "+++", "output": "No" }, { "input": "--+", "output": "No" }, { "input": "++--++", "output": "Yes" }, { "input": "+-++-+", "output": "Yes" }, { "input": "+-+--+", "output": "No" }, { "input": "--++-+", "output": "No" }, { "input": "-+-+--", "output": "No" }, { "input": "+-+++-", "output": "No" }, { "input": "-+-+-+", "output": "No" }, { "input": "-++-+--++--+-++-", "output": "Yes" }, { "input": "+-----+-++---+------+++-++++", "output": "No" }, { "input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-", "output": "No" }, { "input": "-+-----++++--++-+-++", "output": "Yes" }, { "input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+", "output": "Yes" }, { "input": "-+-+-++-+-+-", "output": "Yes" }, { "input": "-+-++-+-", "output": "Yes" }, { "input": "-+-++-+-+-", "output": "No" }, { "input": "++-+-+-+-+--+", "output": "No" }, { "input": "+++---", "output": "No" }, { "input": "+-+-+-+-+--+-+-+-+-++--++--+", "output": "Yes" }, { "input": "+-+-++", "output": "No" }, { "input": "-++--+--+++-+-+-+-+-", "output": "No" }, { "input": "+---+-+-", "output": "No" }, { "input": "+-+--+-+", "output": "Yes" }, { "input": "+++---+++---", "output": "No" }, { "input": "-+++++", "output": "No" }, { "input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-", "output": "Yes" }, { "input": "-+++--", "output": "No" }, { "input": "+---+", "output": "No" }, { "input": "-++", "output": "No" }, { "input": "-+--+-", "output": "Yes" }, { "input": "+---++--++", "output": "No" }, { "input": "+++-", "output": "No" }, { "input": "--+++", "output": "No" }, { "input": "++-+", "output": "No" } ]
1,591,812,733
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
216
0
string = input() if len(string)==1: print('No') else: if string[0] == string[-1]: plus = 0 minus = 0 for i in range(len(string)): if string[i]=='+': plus+=1 else: minus+=1 if plus%2 == 0 and minus%2==0: print('Yes') else: print('No') else: print('NO')
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input Specification: The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Specification: Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Demo Input: ['-++-\n', '+-\n', '++\n', '-\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'No\n'] Note: The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
```python string = input() if len(string)==1: print('No') else: if string[0] == string[-1]: plus = 0 minus = 0 for i in range(len(string)): if string[i]=='+': plus+=1 else: minus+=1 if plus%2 == 0 and minus%2==0: print('Yes') else: print('No') else: print('NO') ```
0
386
A
Second-Price Auction
PROGRAMMING
800
[ "implementation" ]
null
null
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
[ "2\n5 7\n", "3\n10 2 8\n", "6\n3 8 2 9 4 14\n" ]
[ "2 5\n", "1 8\n", "6 9\n" ]
none
500
[ { "input": "2\n5 7", "output": "2 5" }, { "input": "3\n10 2 8", "output": "1 8" }, { "input": "6\n3 8 2 9 4 14", "output": "6 9" }, { "input": "4\n4707 7586 4221 5842", "output": "2 5842" }, { "input": "5\n3304 4227 4869 6937 6002", "output": "4 6002" }, { "input": "6\n5083 3289 7708 5362 9031 7458", "output": "5 7708" }, { "input": "7\n9038 6222 3392 1706 3778 1807 2657", "output": "1 6222" }, { "input": "8\n7062 2194 4481 3864 7470 1814 8091 733", "output": "7 7470" }, { "input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408", "output": "3 7906" }, { "input": "2\n3458 1504", "output": "1 1504" }, { "input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991", "output": "39 9752" }, { "input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602", "output": "86 9806" }, { "input": "2\n2 1", "output": "1 1" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "3\n10 20 30", "output": "3 20" }, { "input": "3\n10 30 20", "output": "2 20" }, { "input": "3\n20 10 30", "output": "3 20" }, { "input": "3\n20 30 10", "output": "2 20" }, { "input": "3\n30 10 20", "output": "1 20" }, { "input": "3\n30 20 10", "output": "1 20" }, { "input": "2\n1 10000", "output": "2 1" }, { "input": "2\n10000 999", "output": "1 999" }, { "input": "3\n3 4 1", "output": "2 3" }, { "input": "6\n1 2 24 6 5 7", "output": "3 7" } ]
1,606,475,011
2,147,483,647
Python 3
OK
TESTS
42
109
307,200
n = int(input()) nums = [int(j) for j in input().split()] ref = 10000 * [-1] for j in range(n): ref[nums[j] - 1] = j + 1 index, pointer = -1, 9999 while pointer >= 0: if ref[pointer] != -1: index = ref[pointer] pointer -= 1 break pointer -= 1 value = -1 while pointer >= 0: if ref[pointer] != -1: value = pointer + 1 break pointer -= 1 print(index, value)
Title: Second-Price Auction Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. Output Specification: The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. Demo Input: ['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n'] Demo Output: ['2 5\n', '1 8\n', '6 9\n'] Note: none
```python n = int(input()) nums = [int(j) for j in input().split()] ref = 10000 * [-1] for j in range(n): ref[nums[j] - 1] = j + 1 index, pointer = -1, 9999 while pointer >= 0: if ref[pointer] != -1: index = ref[pointer] pointer -= 1 break pointer -= 1 value = -1 while pointer >= 0: if ref[pointer] != -1: value = pointer + 1 break pointer -= 1 print(index, value) ```
3
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,641,905,340
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
13,516,800
n = int(input()) numbers = [x for x in map(int, input().split())] srebmun = numbers[::-1] m = int(input()) searches = [x for x in map(int, input().split())] a = 0 b = 0 for item in searches: a += numbers.index(item) + 1 b += srebmun.index(item) + 1 print (a, b)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n = int(input()) numbers = [x for x in map(int, input().split())] srebmun = numbers[::-1] m = int(input()) searches = [x for x in map(int, input().split())] a = 0 b = 0 for item in searches: a += numbers.index(item) + 1 b += srebmun.index(item) + 1 print (a, b) ```
0
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,688,741,619
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
0
n = int(input()) if n%2 == 0: x = n - 2 y = n - x if x % 2 == 0 and y % 2 == 0 : print('YES') else: print('NO') else: print('NO')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python n = int(input()) if n%2 == 0: x = n - 2 y = n - x if x % 2 == 0 and y % 2 == 0 : print('YES') else: print('NO') else: print('NO') ```
0
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" }, { "input": "22", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "0" }, { "input": "6", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "0" }, { "input": "9", "output": "0" }, { "input": "13", "output": "4" }, { "input": "14", "output": "4" }, { "input": "16", "output": "4" }, { "input": "17", "output": "4" }, { "input": "19", "output": "4" }, { "input": "21", "output": "4" }, { "input": "23", "output": "0" }, { "input": "24", "output": "0" } ]
1,684,710,006
2,147,483,647
PyPy 3
OK
TESTS
25
124
0
def main(): original_points = 10 needed = int(input()) dict = {1: 4, 11: 4, 10: 15, 2: 4, 3: 4, 4: 4, 5: 4, 6: 4, 7: 4, 8: 4, 9: 4} to_find = needed - original_points if to_find not in dict: print(0) else: print(dict[to_find]) main()
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. Input Specification: The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. Output Specification: Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. Demo Input: ['12\n', '20\n', '10\n'] Demo Output: ['4', '15', '0'] Note: In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
```python def main(): original_points = 10 needed = int(input()) dict = {1: 4, 11: 4, 10: 15, 2: 4, 3: 4, 4: 4, 5: 4, 6: 4, 7: 4, 8: 4, 9: 4} to_find = needed - original_points if to_find not in dict: print(0) else: print(dict[to_find]) main() ```
3.969
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51", "output": "6" }, { "input": "2 400 23 57", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10000 10000 3 2", "output": "16670000" }, { "input": "1 2 1 2", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "1 1 10 10", "output": "1" }, { "input": "5324 5439 32 13", "output": "69622" }, { "input": "9000 1 2432 1", "output": "9000" }, { "input": "230 1234 9124 23", "output": "10" }, { "input": "11 1 1 1", "output": "11" }, { "input": "6246 8489 1227 9", "output": "4858" }, { "input": "9 20 5 7", "output": "6" } ]
1,579,607,186
2,147,483,647
Python 3
OK
TESTS
18
109
307,200
import math if __name__ == '__main__': k, n, s, p = map(int, input().split()) ans = math.ceil(math.ceil(n / s) * k / p) print(ans)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? Input Specification: The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. Output Specification: Print a single integer — the minimum number of packs they should buy. Demo Input: ['5 3 2 3\n', '5 3 100 1\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
```python import math if __name__ == '__main__': k, n, s, p = map(int, input().split()) ans = math.ceil(math.ceil(n / s) * k / p) print(ans) ```
3
479
C
Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
[ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ]
[ "2\n", "6\n" ]
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
1,500
[ { "input": "3\n5 2\n3 1\n4 2", "output": "2" }, { "input": "3\n6 1\n5 2\n4 3", "output": "6" }, { "input": "1\n1000000000 999999999", "output": "999999999" }, { "input": "1\n2 1", "output": "1" }, { "input": "2\n3 2\n3 2", "output": "2" }, { "input": "5\n4 3\n4 2\n4 1\n4 1\n4 1", "output": "3" }, { "input": "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1", "output": "11" }, { "input": "2\n3 1\n3 2", "output": "2" }, { "input": "2\n4 2\n4 1", "output": "2" }, { "input": "2\n5 2\n5 1", "output": "2" }, { "input": "6\n3 1\n3 2\n4 1\n4 2\n5 4\n5 4", "output": "4" }, { "input": "3\n3 2\n4 1\n100 10", "output": "10" }, { "input": "3\n4 3\n5 2\n10 8", "output": "8" }, { "input": "5\n6 5\n6 4\n6 3\n6 2\n6 1", "output": "5" }, { "input": "3\n5 4\n6 3\n8 7", "output": "7" }, { "input": "4\n7 1\n7 3\n8 2\n9 8", "output": "8" }, { "input": "3\n3 2\n4 1\n10 5", "output": "5" }, { "input": "3\n5 4\n6 3\n11 10", "output": "10" }, { "input": "4\n2 1\n3 2\n4 1\n6 5", "output": "5" } ]
1,694,682,432
2,147,483,647
Python 3
OK
TESTS
53
46
716,800
n=int(input()) l=[] for i in range(n): a, b= map(int, input().split()) l.append([a,b]) l.sort() prev=0 for a, b in l: if b>= prev: prev=b else: prev=a print(prev)
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly. Output Specification: Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Demo Input: ['3\n5 2\n3 1\n4 2\n', '3\n6 1\n5 2\n4 3\n'] Demo Output: ['2\n', '6\n'] Note: In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
```python n=int(input()) l=[] for i in range(n): a, b= map(int, input().split()) l.append([a,b]) l.sort() prev=0 for a, b in l: if b>= prev: prev=b else: prev=a print(prev) ```
3
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()(((", "output": "6" }, { "input": "()))(()((((()(())", "output": "10" }, { "input": "())))((()())())))))())", "output": "14" }, { "input": ")))((((())(()((()((((()()())((", "output": "16" }, { "input": "))()()((()()))())()(((((((())((((((((())()()((())(", "output": "32" }, { "input": "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))", "output": "48" } ]
1,666,594,525
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
26
5,000
3,174,400
a=input() b=0 if a.count("(") != 0 and a.count(')') != 0: if a.count("(") == 1 and a.count(')') ==1: b = 1 else: while '()' in a: b+=a.count('()') a=a.replace('()','') print(b*2)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained? Input Specification: Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. Output Specification: Output the maximum possible length of a regular bracket sequence. Demo Input: ['(()))(\n', '((()())\n'] Demo Output: ['4\n', '6\n'] Note: none
```python a=input() b=0 if a.count("(") != 0 and a.count(')') != 0: if a.count("(") == 1 and a.count(')') ==1: b = 1 else: while '()' in a: b+=a.count('()') a=a.replace('()','') print(b*2) ```
0
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, { "input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "output": "10" }, { "input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1", "output": "29" }, { "input": "1\n1 1 1", "output": "1" }, { "input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "output": "4" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "16" } ]
1,699,365,782
2,147,483,647
PyPy 3-64
OK
TESTS
21
216
2,048,000
ans=0 for i in range(int(input())): task = sum(map(int, input().split())) if task>=2: ans+=1 print(ans)
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 ans=0 for i in range(int(input())): task = sum(map(int, input().split())) if task>=2: ans+=1 print(ans) ```
3
875
A
Classroom Watch
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
500
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "input": "1000000000", "output": "1\n999999932" }, { "input": "999999979", "output": "2\n999999899\n999999908" }, { "input": "9", "output": "0" }, { "input": "10", "output": "1\n5" }, { "input": "11", "output": "1\n10" }, { "input": "39", "output": "1\n33" }, { "input": "66", "output": "1\n60" }, { "input": "75", "output": "0" }, { "input": "100", "output": "1\n86" }, { "input": "101", "output": "2\n91\n100" }, { "input": "2014", "output": "2\n1988\n2006" }, { "input": "999999994", "output": "0" } ]
1,508,152,236
336
Python 3
OK
TESTS
18
61
5,529,600
n = int(input()) a = [] for i in range(min(n, 82), -1, -1): c = n - i c += sum([int(j) for j in str(c)]) if c == n: a.append(n - i) print(len(a)) for i in a: print(i)
Title: Classroom Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order. Demo Input: ['21\n', '20\n'] Demo Output: ['1\n15\n', '0\n'] Note: In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
```python n = int(input()) a = [] for i in range(min(n, 82), -1, -1): c = n - i c += sum([int(j) for j in str(c)]) if c == n: a.append(n - i) print(len(a)) for i in a: print(i) ```
3
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game?
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, { "input": "1 3", "output": "Akshat" }, { "input": "2 1", "output": "Akshat" }, { "input": "2 2", "output": "Malvika" }, { "input": "3 1", "output": "Akshat" }, { "input": "3 2", "output": "Malvika" }, { "input": "68 42", "output": "Malvika" }, { "input": "1 35", "output": "Akshat" }, { "input": "25 70", "output": "Akshat" }, { "input": "59 79", "output": "Akshat" }, { "input": "65 63", "output": "Akshat" }, { "input": "46 6", "output": "Malvika" }, { "input": "28 82", "output": "Malvika" }, { "input": "98 98", "output": "Malvika" }, { "input": "98 99", "output": "Malvika" }, { "input": "98 100", "output": "Malvika" }, { "input": "99 98", "output": "Malvika" }, { "input": "99 99", "output": "Akshat" }, { "input": "99 100", "output": "Akshat" }, { "input": "100 98", "output": "Malvika" }, { "input": "100 99", "output": "Akshat" }, { "input": "100 100", "output": "Malvika" }, { "input": "3 4", "output": "Akshat" } ]
1,690,872,428
2,147,483,647
Python 3
OK
TESTS
28
46
0
n,m = map(int, input().split()) a = min(n,m) if a%2==0: print('Malvika') else: print('Akshat')
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game? Input Specification: The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Output Specification: Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. Demo Input: ['2 2\n', '2 3\n', '3 3\n'] Demo Output: ['Malvika\n', 'Malvika\n', 'Akshat\n'] Note: Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
```python n,m = map(int, input().split()) a = min(n,m) if a%2==0: print('Malvika') else: print('Akshat') ```
3
312
A
Whose sentence is it?
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100.
For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG&gt;.&lt; I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions.
[ "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n" ]
[ "Freda's\nOMG&gt;.&lt; I don't know!\nOMG&gt;.&lt; I don't know!\nRainbow's\nOMG&gt;.&lt; I don't know!\n" ]
none
500
[ { "input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .", "output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!" }, { "input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iapelala.\nCFPlbUgObrXLejPNu.F\nZSUfvisiHyrIMjMlala.\nmiao. lala.\nd,IWSeumytrVlala.", "output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's" }, { "input": "10\nmiao.,taUvXPVlala.\nmiao.txEeId.X_lala.\nLZIeAEd JaeBVlala.\ncKPIsWpwIlala.\nfYp.eSvn,g\nKMx,nFEslala.\nmiao.QtMyxYqiajjuM\nDutxNkCqywgcnCYskcd\ngFLKACjeqfD\n,Ss UmY.wJvcX", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nmiao.Plala.\nDVm,VYslala.\nmiao.rlala.\nmiao.,KQNL.fO_.QRc\nUBLCKEUePlala.\nIouS.Alala.\nmiao.lala.\nmiao.rlala.\nEJZwRJeKlala.\nmiao.Olala.", "output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nRainbow's\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!" }, { "input": "10\nmiao.grFTpju.jCLRnZ\ng.pVHYA_Usnm\nlloWONolcMFElala.\nAW,n.JJkOTe.Nd\n.bP.HvKlala.\nGziqPGQa,lala.\nmiao.,QkOCH.vFlala.\n.PUtOwImvUsoeh \nmiao.Z,KIds.R\nmiao.,_MDzoaAiJlala.", "output": "Rainbow's\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!" }, { "input": "10\nmiao.xWfjV\nHFVrGCDQXyZ,Sbm\nLMDS.xVkTCAY.vm\nmiao.lLBglala.\nnl,jRPyClala.\nFYnHoXlala.\nmiao. oxaHE\n.WTrw_mNpOQCa\nHOk..wHYoyMhl\nQX,XpMuPIROM", "output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nJBQqiXlala.\npUNUWQRiMPCXv\nAiLnfNHWznwkC.lala.\nmiao.Dl_Oy\nxJJJkVkdfOzQBH_SmKh\nfgD_IHvdHiorE,W\nmiao.usBKixglala.\nwCpqPUzEtD\nmiao.rlala.\nmiao.JylcGvWlala.", "output": "Freda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nmiao..FLhPl_Wjslala.\nmiao. tdEGtfdJlala.\nGAzEUlala.\nKCcmOa .aKBlZyYsdu.V\nmiao.lala.\njKylnM,FXK\nmiao.GBWqjGH.v\nmiao.RefxS Cni.\nOxaaEihuHQR_s,\nmiao.a,Axtlala.", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nNo.I_aTXlala.\nmiao.JKSCoRZS\nnOBMIlala.\nmiao.nlala.\nmiao._xqxoHIIlala.\nmiao.NJPy SWyiUDWc\nmiao.cCnahFaqqj.Xqp\nnreSMDeXPPYAQxI,W\nAktPajWimdd_qRn\nmiao.QHwKCYlala.", "output": "Freda's\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\n \n,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ \n \nmiao.miao.miao.\nlala.lala.lala.\nlala.miao.\nmiaolala. \nmiao.lala\nmiaolala_\n,.._ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nduClyjMIPsEuWmx_Ce.byVoizYlTM,sF\nuZHsNip_,Mwtg,FZjM_LzPC,_pSvEOyTHfAOvoZXvxCZdgYDTCDdCAoSVZWyxXGcLgWlala.\nEGtJFPAvTEcqjkhaGxdduaQ_rmUzF.WaU, EIuX B,aVzFFpFrxpwADXuayRD azDfj \n_tJqYzXyqc.,u.F,mUYukveBPWnPq,f,dJnPHuBazdnbRHfzwNUdRbheAIjcoaPcnLvocrzcioxCapb R\n.YUBeb_zmwUt.QQuUdQIiOXtqshcsycEe,HLytHlala.\ndJndLqGBHt.GfpN.BgvsbXoLh_DIzAJOtFDmLSCYEztvPcS_GHPxivzV,NPMmSAtfk.Mg.w,A UcCt_lCD.csEzyJJBYtSMkzqiA\nmiao.qlala.\nmiao.FmDlY\nmiao.UQI.aJmnanNvRLskuVaMybDMsOlala.\nmiao.lala.", "output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nmiao.vyscfysAtWcPkpFHdwZqAQ,UPPcjhKQTlala.\nmiao.KESqus DybUuYFoWVpo..LWZh.UqEdUsTHFlKfzqkThAUPklala.\nUNoE vfZIAdxkiWKhsHPfsqRPTNQoHgAxooVLYxRzugHjo jaEHWQFF\nCCmdIwr.UkoiYWK.Z,,ZesMpISTXNgnpYnJaWquCyL,gO\n.JvOayhXK_bgoYbfAtnXg\nbvdSzRrXoGxVgWvdXnsjEnEfxDzIQo_aZVGDGrzwuAMtzVAHioMBx_DHuTxyieGbGuSRNUojOREqxBBxvCgqAOMzwIWT\nMBuaWduZmRaOGyIPzWOsBVeqtDrblAbXxmM_uRfqMvnVlLEuhVKlhidN_aigiXyq,ZEDqQAx\nmiao.wCHVCuVKNePKmIUFLL_lala.\nmiao.iAqstXHUv\n pMO yvPkNtnNwmUCao W,wW.OvIMVaEeVYHmqaniWq.ivlala.", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's" }, { "input": "10\nmiao.\nmiao.jrwLBCpNaDCjyoK.PFzbwWU.h.. wfQquG_P..lala.\nmiao.LGlYdKjw__.Chlala.\nW.wtr qG KDOHj.xWxPbXIXjD_,GJZDaAZ,JBHphsjWJwSKcZAIAi\nmiao.pHsGAZQDWPJQwKC.zHjJituLgp.eUrzObTI.wrpect.FMUJqu,Zuslala.\nmiao.YVlOpXccUA_YU igbsbZbhOVwyYTyOjnWqgiTmxwAuFa.flCHn.,MtVbqxZQl_BGHXWkwijGjuL, ,ezyNlala.\nmiao.xCrVSz.aMv UOSOroDlQxWeBmlWe.FA.ZfUmviMlala.\nxebAlala.\nmiao.qVSxqf vOTlala.\nD.oBUwsLQRgXAoNkQJhQN.w.oMhuvtujnmiwgQYMfjlNTSHh .lSKgI.OEp", "output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nZXXzYlTiQU\nkXE.DdcbOojSaSgjMcFBPubKHefEVAzbi,PDFgSZIz,lala.\nxEfrTCjKhhwBC.UNmJXgTGUdkQeVDlala.\nLfaEw.jvMmuOBWtfoiJNtDIlQAVWNU,xWK_efBBtfkM\nqtBpqKZMWZMX_NKrUAEKYyQcLZWQlqbM\nmiao.PrJEbUtInremuaKRItqXOrfQEjQcAak VQ\nMpGCq awvQaHRvDr uvtVMKsvZI\nmiao.A.RVGu.szCEp.pXQJwL EuTltlN.WradoTvWHJyhcNSoulala.\nmiao.rzlUHzUdxtDRpWRuc,QZwEBfsKKGHMLGtFymPPQdptLFlzZ_ORWqrlfOrlntuDkpXEvz.CxwAsFYUvpnOnFWG\nmiao.VXUoNBwlgBwcna_n.CgAAcKKUuiVA.doOJKHpMdwNwlHAcLpdfN.Awa SthrlEWpUcuOonUTxIQNszYcHDXxnhArrM..A", "output": "OMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's" }, { "input": "10\nmiao.qbxBFzrjtWv.yOk\nDBgi,loApO AACrGnwssCHN\nmiao.LV.wbQEE_V.BSAtdTIHTQOJVJ_nGOthbL,nJvQ.UeWFpsa.GGsK_Uv,HQxHS,AN_bkrolala.\nmiao.tBEqk rIQuByGKhfq_iP.BW,nySZEfrfySEcqnnIzxC,lrjIiivbxlkoVXJFiegGFRn NO,txGPhVBcv.CVhMmNO zlala.\nmiao.aBZWDWxk.wkR ,NyCzGxJnJDqBZpetdUPAmmBZDXl_Tbflala.\nmiao. XN,uMwWm. VqloYr..jTLszlala.\n.rshcgfZ.eZOdMu_RMh\nmiao.ahiwpECEe.lala.\nLeoUSroTekQAMSO__M L_ZEeRD_tUihYvQETFB,RzJmFtFiKrU\nBtygQG_OoFEFBL.KsVWTYbtqtalXoStFCZ RINHda.NuLmlkRB.vAQJFvelbsfoJ.T,M sJn", "output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nYoYBCcaqhXLfvKKf.UYMODTHyPZlala.\ncxgWn J.Q\nmiao.nwH.IHntgKYDhdsjU DMTHXEVRyeJP ZaAecCIBJXuv.YjhEmtbjvjKnK.U,oc,x\nmiao.EcQ.FDtRJgmpAzxhq.RwXBLxjyC,IeMqaFoheMPFCGWBcwUAFnbiwlbz_fcsEGPfJaeryCtFocBNEWTlala.\nmiao.W\nmiao. ZQpIeyCXJSnFgAIzu.THfrmyoogYWQzFqblala.\nmiao.ifzdCwnTDcxpvdr OTC.YqPv.MKDp..utICtAsbfYyGlala.\nmiao.\nmiao.tS.U.wH.s,CxORZJsBAHLi,fXeoDJWVBH\nrcUMpeupOVRKrcIRAvU.rP kgUEfoeXcrFPQOBYG.BNvAQPg.XHMWizhLpZNljXc .LQmVXCi", "output": "Freda's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!" }, { "input": "10\nlala.\nmiao.milalala.lmmialamiao.la.o.iao.a.ao.\nmialala.o.\nmiao.millala.allala.amiao..miao.miao.lala.ao.miammiao.iao.o.\nmiao.miaomiao..\nlalmiao.amiao..\nmiao.lala.lamiamiaolala..o.lalala.miao..\nmlala.iao.lalamiao..\nlmlala.iao.alalamiao.lmialala.lala.miao.o.alala..lala..lalmiaomiao..lalmiao.a.lalamiao..miao.alala..\nlalllamiao.la.lala.alamiao.lalalala.lala..miao.lamiao.la.lallalamiao..a..a.", "output": "Freda's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nlalllala.ala.lala.a.mmimiao.aomiao.lllala.ala.amiao.la.mialalala.la.o..imiao.miao.amlala.iao.o.\nmilala.alllala.ala.amiao.lamiao..o.\nlala.lalalala..lalalala..\nlala.miao.\nmimiao.ao.lala.\nlalmiao.amlala.iamialala.o.o..\nlalammlala.iaolammiao.imiao.ao.la..iao..\nmiao.mialala.omiao..mlala.iaolala..\nmiamiao.o.llallala.ala.la.miao.ala.miao.mimialmiao.ala.o.alala.miaomiao..olala..\nmialala.lamiao.la.lala.miao.ollala.allala.ala.lmiaommiao.imiao.ao.lallallala.a.miao.a..a..", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "10\nlamiao.lamiao.mimiao.ao..\nllala.almiaomiao..lala.miao.a.\nlalala.lala.lalala.lala.lalala..la.\nlalala.la.miao.\nmiao.llalallala.miao.a.la.lala.almimiao.ao.a.\nmiao.mlala.ilala.aomilala.ao..\nmilala.ao.\nmmiao.iao.\nmlala.lala.ialalmiao.alala..olala.lala..\nlala.lmlalalalalala...iao.milala.aommiao.iao..alamiaolallala.milala.ao.a..lalalmiao.a..llala.amiao..", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "4\n \n miao. \n lala. \n ", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" }, { "input": "1\nMiao.", "output": "OMG>.< I don't know!" }, { "input": "1\nm", "output": "OMG>.< I don't know!" }, { "input": "1\nMiAo.sdsdlala.", "output": "Freda's" }, { "input": "1\nLalA.", "output": "OMG>.< I don't know!" }, { "input": "3\n.\nm\nl", "output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!" } ]
1,370,589,631
2,147,483,647
Python 3
OK
TESTS
36
93
0
n = int(input()) a = [] for x in range(n) : a.append(str(input())) for x in range(n): if (a[x][-5:] == 'lala.' and a[x][:5] == 'miao.'): print('OMG>.< I don\'t know!') elif (a[x][-5:] == 'lala.'): print('Freda\'s') elif (a[x][:5] == 'miao.'): print('Rainbow\'s') else: print('OMG>.< I don\'t know!')
Title: Whose sentence is it? Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. Output Specification: For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG&gt;.&lt; I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. Demo Input: ['5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n'] Demo Output: ["Freda's\nOMG&gt;.&lt; I don't know!\nOMG&gt;.&lt; I don't know!\nRainbow's\nOMG&gt;.&lt; I don't know!\n"] Note: none
```python n = int(input()) a = [] for x in range(n) : a.append(str(input())) for x in range(n): if (a[x][-5:] == 'lala.' and a[x][:5] == 'miao.'): print('OMG>.< I don\'t know!') elif (a[x][-5:] == 'lala.'): print('Freda\'s') elif (a[x][:5] == 'miao.'): print('Rainbow\'s') else: print('OMG>.< I don\'t know!') ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,680,696,520
2,147,483,647
PyPy 3-64
OK
TESTS
25
124
0
n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a = list(sorted(a)) ans = 0 for i in range(n): if a[i] < 0 and m != 0: ans += a[i] m -= 1 print(abs(ans))
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a = list(sorted(a)) ans = 0 for i in range(n): if a[i] < 0 and m != 0: ans += a[i] m -= 1 print(abs(ans)) ```
3.969
60
B
Serial Time!
PROGRAMMING
1,400
[ "dfs and similar", "dsu" ]
B. Serial Time!
2
256
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes.
The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*.
The answer should contain a single number, showing in how many minutes the plate will be filled.
[ "1 1 1\n\n.\n\n1 1\n", "2 1 1\n\n.\n\n#\n\n1 1\n", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n" ]
[ "1\n", "1\n", "5\n", "7\n", "13\n" ]
none
1,000
[ { "input": "1 1 1\n\n.\n\n1 1", "output": "1" }, { "input": "2 1 1\n\n.\n\n#\n\n1 1", "output": "1" }, { "input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "output": "5" }, { "input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "output": "7" }, { "input": "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1", "output": "13" }, { "input": "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1", "output": "4" }, { "input": "4 7 8\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n3 4", "output": "224" }, { "input": "6 5 4\n\n####\n####\n####\n####\n.###\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n5 1", "output": "1" }, { "input": "8 2 6\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n1 2", "output": "52" }, { "input": "9 1 9\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n1 6", "output": "49" }, { "input": "6 8 4\n\n.###\n.#..\n.#..\n####\n....\n.##.\n..#.\n...#\n\n....\n##.#\n....\n....\n##..\n#.##\n#.#.\n#..#\n\n..##\n####\n#...\n..##\n###.\n#..#\n..##\n##..\n\n.##.\n##..\n#.#.\n##..\n####\n####\n.#.#\n###.\n\n#.##\n..#.\n...#\n#.##\n##.#\n##..\n####\n###.\n\n.#.#\n#.#.\n#.##\n#.##\n....\n#.##\n..##\n.##.\n\n6 4", "output": "88" }, { "input": "8 1 8\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n1 3", "output": "64" }, { "input": "1 8 6\n\n######\n######\n.#####\n######\n######\n######\n######\n######\n\n3 1", "output": "1" }, { "input": "6 1 9\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n1 3", "output": "30" }, { "input": "1 1 10\n\n..........\n\n1 6", "output": "10" }, { "input": "5 2 8\n\n.##..#..\n.#.....#\n\n....##..\n#..###.#\n\n#..#.#..\n.#..#...\n\n###.#..#\n#......#\n\n#..#####\n##.....#\n\n1 7", "output": "45" }, { "input": "9 2 1\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n1 1", "output": "18" }, { "input": "5 8 2\n\n##\n##\n##\n#.\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n4 2", "output": "1" }, { "input": "6 10 2\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n2 2", "output": "63" }, { "input": "8 6 2\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n3 1", "output": "52" }, { "input": "4 1 3\n\n...\n\n...\n\n...\n\n...\n\n1 1", "output": "12" }, { "input": "4 6 2\n\n##\n##\n##\n##\n.#\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n5 1", "output": "1" }, { "input": "2 9 2\n\n##\n##\n##\n##\n.#\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n5 1", "output": "19" }, { "input": "10 6 5\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n2 4", "output": "155" }, { "input": "2 3 6\n\n......\n#..#..\n##.#.#\n\n#.##..\n.....#\n##..##\n\n1 3", "output": "22" }, { "input": "8 5 6\n\n######\n######\n######\n###.##\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n4 4", "output": "1" }, { "input": "1 3 10\n\n##########\n####.#####\n##########\n\n2 5", "output": "1" }, { "input": "8 3 3\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n3 3", "output": "40" }, { "input": "5 1 4\n\n#...\n\n####\n\n#.##\n\n.###\n\n###.\n\n1 4", "output": "3" }, { "input": "9 2 2\n\n##\n..\n\n##\n##\n\n#.\n#.\n\n..\n..\n\n##\n..\n\n..\n.#\n\n#.\n#.\n\n.#\n..\n\n#.\n.#\n\n2 1", "output": "2" }, { "input": "1 6 2\n\n##\n..\n##\n.#\n##\n#.\n\n6 2", "output": "1" }, { "input": "5 9 2\n\n##\n##\n##\n#.\n.#\n.#\n..\n##\n#.\n\n##\n..\n##\n##\n#.\n#.\n.#\n#.\n#.\n\n#.\n.#\n##\n.#\n..\n##\n##\n#.\n..\n\n#.\n..\n.#\n#.\n..\n#.\n..\n..\n##\n\n.#\n##\n..\n.#\n#.\n#.\n.#\n##\n##\n\n4 2", "output": "1" }, { "input": "5 8 7\n\n.#.#...\n##.#.##\n...#..#\n#####..\n......#\n..###..\n#.#..#.\n.##..#.\n\n##.....\n.##.#..\n.##.###\n...##..\n.#.###.\n##.#..#\n##..#.#\n.##....\n\n#.#...#\n##.....\n...###.\n...##..\n..#.###\n.#.#...\n.#.#..#\n..###..\n\n#..#...\n.####..\n###.#.#\n#..#.##\n....#..\n.#.#.##\n#.#.###\n.#..###\n\n..#.#.#\n##....#\n.#.####\n#.#.##.\n.#..##.\n##..#.#\n.##.##.\n...###.\n\n4 7", "output": "132" }, { "input": "4 3 2\n\n#.\n#.\n##\n\n.#\n.#\n##\n\n..\n#.\n##\n\n#.\n..\n.#\n\n1 2", "output": "2" }, { "input": "4 10 10\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n8 1", "output": "400" }, { "input": "4 10 10\n\n##########\n##########\n##########\n##########\n##########\n##########\n#########.\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n7 10", "output": "1" }, { "input": "3 10 10\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n1 8", "output": "102" }, { "input": "2 10 10\n\n#..#...#..\n###..#..##\n..#..#..#.\n#..#.#...#\n#####...#.\n#.####..#.\n###..##.##\n.###..#...\n##..##.##.\n..#.#.####\n\n..##..#.#.\n.##....#..\n..#.#.##..\n#.####....\n##..##.#..\n######...#\n..#...###.\n####.###.#\n#...##.#..\n##.#####.#\n\n6 7", "output": "57" } ]
1,590,869,329
2,147,483,647
PyPy 3
OK
TESTS
46
342
3,276,800
(k, n, m) = map(int, input().split()) a = [] for i in range(k): s = input() a.append([]) for j in range(n): a[-1].append(list(input())) s = input() (x, y) = map(int, input().split()) x -= 1 y -= 1 start = (0, x, y) sosed = set() sosed.add(start) posetil = set() posetil.add(start) while len(sosed) >0: sosed2 = set() for i in sosed: for dk in [-1,0,1]: for dx in [-1,0,1]: for dy in [-1,0,1]: if abs(dk)+abs(dx)+abs(dy) == 1: if (i[0]+dk <k) and (i[0]+dk>=0) and (i[1]+dx < n) and (i[1]+dx>=0) and (i[2]+dy < m) and (i[2]+dy >=0): if a[i[0]+dk][i[1]+dx][i[2]+dy] == '.': if (i[0]+dk, i[1]+dx, i[2]+dy) in posetil: continue else: posetil.add((i[0]+dk,i[1]+dx,i[2]+dy)) sosed2.add((i[0]+dk,i[1]+dx,i[2]+dy)) sosed = sosed2.copy() print(len(posetil))
Title: Serial Time! Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes. Input Specification: The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*. Output Specification: The answer should contain a single number, showing in how many minutes the plate will be filled. Demo Input: ['1 1 1\n\n.\n\n1 1\n', '2 1 1\n\n.\n\n#\n\n1 1\n', '2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n', '3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n', '3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n'] Demo Output: ['1\n', '1\n', '5\n', '7\n', '13\n'] Note: none
```python (k, n, m) = map(int, input().split()) a = [] for i in range(k): s = input() a.append([]) for j in range(n): a[-1].append(list(input())) s = input() (x, y) = map(int, input().split()) x -= 1 y -= 1 start = (0, x, y) sosed = set() sosed.add(start) posetil = set() posetil.add(start) while len(sosed) >0: sosed2 = set() for i in sosed: for dk in [-1,0,1]: for dx in [-1,0,1]: for dy in [-1,0,1]: if abs(dk)+abs(dx)+abs(dy) == 1: if (i[0]+dk <k) and (i[0]+dk>=0) and (i[1]+dx < n) and (i[1]+dx>=0) and (i[2]+dy < m) and (i[2]+dy >=0): if a[i[0]+dk][i[1]+dx][i[2]+dy] == '.': if (i[0]+dk, i[1]+dx, i[2]+dy) in posetil: continue else: posetil.add((i[0]+dk,i[1]+dx,i[2]+dy)) sosed2.add((i[0]+dk,i[1]+dx,i[2]+dy)) sosed = sosed2.copy() print(len(posetil)) ```
3.908396
391
A
Genetic Engineering
PROGRAMMING
0
[ "implementation", "two pointers" ]
null
null
You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'. Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length. Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}. This problem doesn't have subproblems. You will get 3 points for the correct submission.
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
[ "GTTAAAG\n", "AACCAACCAAAAC\n" ]
[ "1\n", "5\n" ]
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
3
[ { "input": "GTTAAAG", "output": "1" }, { "input": "AACCAACCAAAAC", "output": "5" }, { "input": "GTGAATTTCC", "output": "2" }, { "input": "CAGGGGGCCGCCCATGAAAAAAACCCGGCCCCTTGGGAAAACTTGGGTTA", "output": "7" }, { "input": "CCCTTCACCCGGATCCAAATCCCTTAGAAATAATCCCCGACGGCGTTGTATCACCTCTGCACTTGTTAGTAAGGTCAGGCGTCCATTACGGAAGAACGTA", "output": "19" }, { "input": "GCATTACATGGGGGGGTCCTACGAGCCCGGCATCCCGGAAACTAGCCGGTTAATTTGGTTTAAACCCTCCCACCCCGGATTGTAACCCCCCTCATTGGTT", "output": "17" }, { "input": "TTCCCAGAGAAAAAAAGGGGCCCAAATGCCCTAAAAACCCCCTTTGCCCCCCAACCCCTTTTTAAAATAAAAAGGGGCCCATTCCCTTAAAAATTTTTTG", "output": "10" }, { "input": "AGCCGCCCCCCCAAAAAAGGGGGAAAAAAAAAAAAAAAAAAAAACTTTTGGAAACCCCCCCCTTTTTTTTTTTTTTTTTTTTTTTTTGGGGAAGGGGGGG", "output": "7" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "1" }, { "input": "AAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGGAAAAATTTT", "output": "5" }, { "input": "AACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTCCGG", "output": "50" }, { "input": "A", "output": "0" }, { "input": "TTT", "output": "0" }, { "input": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "0" }, { "input": "G", "output": "0" }, { "input": "T", "output": "0" }, { "input": "C", "output": "0" }, { "input": "AA", "output": "1" }, { "input": "GGG", "output": "0" }, { "input": "AAG", "output": "1" } ]
1,583,151,842
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
S = input() ans = 0 count = 1 for i in range(1, len(S)): if(S[i] == S[i-1]): count += 1 else: if(not (count & 1)): ans += 1 count = 1 print(ans)
Title: Genetic Engineering Time Limit: None seconds Memory Limit: None megabytes Problem Description: You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'. Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length. Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein. Input Specification: The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}. This problem doesn't have subproblems. You will get 3 points for the correct submission. Output Specification: The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length. Demo Input: ['GTTAAAG\n', 'AACCAACCAAAAC\n'] Demo Output: ['1\n', '5\n'] Note: In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
```python S = input() ans = 0 count = 1 for i in range(1, len(S)): if(S[i] == S[i-1]): count += 1 else: if(not (count & 1)): ans += 1 count = 1 print(ans) ```
0
870
C
Maximum splitting
PROGRAMMING
1,300
[ "dp", "greedy", "math", "number theory" ]
null
null
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.
The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries. *q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
[ "1\n12\n", "2\n6\n8\n", "3\n1\n2\n3\n" ]
[ "3\n", "1\n2\n", "-1\n-1\n-1\n" ]
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
1,500
[ { "input": "1\n12", "output": "3" }, { "input": "2\n6\n8", "output": "1\n2" }, { "input": "3\n1\n2\n3", "output": "-1\n-1\n-1" }, { "input": "6\n1\n2\n3\n5\n7\n11", "output": "-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "3\n4\n6\n9", "output": "1\n1\n1" }, { "input": "20\n8\n13\n20\n12\n9\n16\n4\n19\n7\n15\n10\n6\n14\n11\n3\n2\n5\n17\n18\n1", "output": "2\n2\n5\n3\n1\n4\n1\n3\n-1\n2\n2\n1\n3\n-1\n-1\n-1\n-1\n3\n4\n-1" }, { "input": "100\n611\n513\n544\n463\n38\n778\n347\n317\n848\n664\n382\n108\n718\n33\n334\n876\n234\n22\n944\n305\n159\n245\n513\n691\n639\n135\n308\n324\n813\n459\n304\n116\n331\n993\n184\n224\n853\n769\n121\n687\n93\n930\n751\n308\n485\n914\n400\n695\n95\n981\n175\n972\n121\n654\n242\n610\n617\n999\n237\n548\n742\n767\n613\n172\n223\n391\n102\n907\n673\n116\n230\n355\n189\n552\n399\n493\n903\n201\n985\n459\n776\n641\n693\n919\n253\n540\n427\n394\n655\n101\n461\n854\n417\n249\n66\n380\n213\n906\n212\n528", "output": "151\n127\n136\n114\n9\n194\n85\n78\n212\n166\n95\n27\n179\n7\n83\n219\n58\n5\n236\n75\n38\n60\n127\n171\n158\n32\n77\n81\n202\n113\n76\n29\n81\n247\n46\n56\n212\n191\n29\n170\n22\n232\n186\n77\n120\n228\n100\n172\n22\n244\n42\n243\n29\n163\n60\n152\n153\n248\n58\n137\n185\n190\n152\n43\n54\n96\n25\n225\n167\n29\n57\n87\n46\n138\n98\n122\n224\n49\n245\n113\n194\n159\n172\n228\n62\n135\n105\n98\n162\n24\n114\n213\n103\n61\n16\n95\n52\n226\n53\n132" }, { "input": "1\n10000001", "output": "2499999" } ]
1,510,498,025
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
62
0
dp = [-1, -1, -1, 1, -1, 1, -1, 2, 1, 2, -1, 3, 2, 3, 2, 4, 3, 4, 3, 5, 4, 5, 4, 6, 5, 6, 5, 7, 6, 7, 6, 8, 7, 8, 7, 9, 8, 9, 8, 10, 9, 10, 9, 11, 10, 11, 10, 12, 11, 12, 11, 13, 12, 13, 12, 14, 13, 14, 13, 15, 14, 15, 14, 16, 15, 16, 15, 17, 16, 17, 16, 18, 17, 18, 17, 19, 18, 19, 18, 20, 19, 20, 19, 21, 20, 21, 20, 22, 21, 22, 21, 23, 22, 23, 22, 24, 23, 24, 23] def main(): n = int(input()) if n < len(dp): print(dp[n - 1]) return res = (n - len(dp)) // 4 n -= ((n - len(dp)) // 4) * 4 while n > len(dp): n -= 4 res += 1 res += dp[n] print(res) return q = int(input()) for i in range(q): main()
Title: Maximum splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input Specification: The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries. *q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query. Output Specification: For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Demo Input: ['1\n12\n', '2\n6\n8\n', '3\n1\n2\n3\n'] Demo Output: ['3\n', '1\n2\n', '-1\n-1\n-1\n'] Note: 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
```python dp = [-1, -1, -1, 1, -1, 1, -1, 2, 1, 2, -1, 3, 2, 3, 2, 4, 3, 4, 3, 5, 4, 5, 4, 6, 5, 6, 5, 7, 6, 7, 6, 8, 7, 8, 7, 9, 8, 9, 8, 10, 9, 10, 9, 11, 10, 11, 10, 12, 11, 12, 11, 13, 12, 13, 12, 14, 13, 14, 13, 15, 14, 15, 14, 16, 15, 16, 15, 17, 16, 17, 16, 18, 17, 18, 17, 19, 18, 19, 18, 20, 19, 20, 19, 21, 20, 21, 20, 22, 21, 22, 21, 23, 22, 23, 22, 24, 23, 24, 23] def main(): n = int(input()) if n < len(dp): print(dp[n - 1]) return res = (n - len(dp)) // 4 n -= ((n - len(dp)) // 4) * 4 while n > len(dp): n -= 4 res += 1 res += dp[n] print(res) return q = int(input()) for i in range(q): main() ```
-1
0
none
none
none
0
[ "none" ]
null
null
A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not. Print the number of 2-3-integers on the given segment [*l*,<=*r*], i. e. the number of sich 2-3-integers *t* that *l*<=≤<=*t*<=≤<=*r*.
The only line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=2·109).
Print a single integer the number of 2-3-integers on the segment [*l*,<=*r*].
[ "1 10\n", "100 200\n", "1 2000000000\n" ]
[ "7\n", "5\n", "326\n" ]
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9. In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
0
[ { "input": "1 10", "output": "7" }, { "input": "100 200", "output": "5" }, { "input": "1 2000000000", "output": "326" }, { "input": "1088391168 1934917632", "output": "17" }, { "input": "1088391167 1934917632", "output": "17" }, { "input": "1088391169 1934917632", "output": "16" }, { "input": "1088391168 1934917631", "output": "16" }, { "input": "1088391168 1934917633", "output": "17" }, { "input": "4 134217728", "output": "250" }, { "input": "209952 43046722", "output": "112" }, { "input": "25165825 43046719", "output": "13" }, { "input": "5183 25165825", "output": "153" }, { "input": "388645 455910", "output": "3" }, { "input": "472069 972050", "output": "14" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "12 1999999931", "output": "319" }, { "input": "1999999999 1999999999", "output": "0" }, { "input": "2000000000 2000000000", "output": "0" }, { "input": "1934917632 1934917632", "output": "1" }, { "input": "1836660096 1836660096", "output": "1" }, { "input": "1811939328 1811939328", "output": "1" }, { "input": "1719926784 1719926784", "output": "1" }, { "input": "1632586752 1632586752", "output": "1" }, { "input": "1610612736 1610612736", "output": "1" }, { "input": "1207959552 1207959552", "output": "1" }, { "input": "129140163 129140163", "output": "1" }, { "input": "12345 54321", "output": "21" }, { "input": "1889569 25165826", "output": "56" }, { "input": "73 7077888", "output": "165" }, { "input": "7077888 45349631", "output": "43" }, { "input": "6144 7077886", "output": "122" }, { "input": "3779135 4194302", "output": "2" }, { "input": "214 161243134", "output": "232" }, { "input": "214 18874369", "output": "180" }, { "input": "28 863", "output": "26" }, { "input": "1417174 172186886", "output": "112" }, { "input": "27 102036671", "output": "234" }, { "input": "147458 102036672", "output": "138" }, { "input": "33554431 102036671", "output": "28" }, { "input": "1572863 33554433", "output": "68" }, { "input": "33554434 181398528", "output": "43" }, { "input": "373247 17915905", "output": "81" }, { "input": "4251526 68024450", "output": "65" }, { "input": "553599 555493", "output": "0" }, { "input": "69739 671621", "output": "40" }, { "input": "618583 755045", "output": "4" }, { "input": "838469 943236", "output": "2" }, { "input": "509607936 1836660096", "output": "38" }, { "input": "509607935 1836660096", "output": "38" }, { "input": "509607937 1836660096", "output": "37" }, { "input": "509607936 1836660095", "output": "37" }, { "input": "509607936 1836660097", "output": "38" } ]
1,533,290,222
2,147,483,647
Python 3
OK
TESTS
53
124
307,200
l,r=map(int,input().split()) ans=0 for i in range(31): for j in range(20): if l <= 2**i * 3**j <= r: ans+=1 print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not. Print the number of 2-3-integers on the given segment [*l*,<=*r*], i. e. the number of sich 2-3-integers *t* that *l*<=≤<=*t*<=≤<=*r*. Input Specification: The only line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=2·109). Output Specification: Print a single integer the number of 2-3-integers on the segment [*l*,<=*r*]. Demo Input: ['1 10\n', '100 200\n', '1 2000000000\n'] Demo Output: ['7\n', '5\n', '326\n'] Note: In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9. In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
```python l,r=map(int,input().split()) ans=0 for i in range(31): for j in range(20): if l <= 2**i * 3**j <= r: ans+=1 print(ans) ```
3
499
A
Watching a movie
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*.
Output a single number — the answer to the problem.
[ "2 3\n5 6\n10 12\n", "1 1\n1 100000\n" ]
[ "6\n", "100000\n" ]
In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
500
[ { "input": "2 3\n5 6\n10 12", "output": "6" }, { "input": "1 1\n1 100000", "output": "100000" }, { "input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53974" }, { "input": "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53983" }, { "input": "10 10\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "54038" }, { "input": "10 1000\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "58728" }, { "input": "12 14\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41870" }, { "input": "12 17\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41872" }, { "input": "18 111\n1449 2156\n3497 4784\n7775 14575\n23857 24593\n29211 30739\n31932 33447\n35902 36426\n36991 38506\n39679 47202\n48772 60016\n60522 61868\n63340 63982\n68417 78537\n79445 86568\n86918 87940\n90081 90310\n90629 94325\n95728 96263", "output": "58967" }, { "input": "1 1\n14575 60522", "output": "45948" }, { "input": "1 10\n14575 60522", "output": "45952" }, { "input": "2 10\n14575 36426\n60522 79445", "output": "40785" }, { "input": "3 1\n14575 36426\n48772 60522\n79445 90081", "output": "44240" }, { "input": "1 100000\n1 100000", "output": "100000" }, { "input": "1 2\n2 100000", "output": "100000" }, { "input": "1 3\n4 100000", "output": "99997" }, { "input": "2 100\n5 6\n7 7", "output": "7" }, { "input": "1 10000\n500 600", "output": "600" }, { "input": "2 3\n1 3\n4 8", "output": "8" }, { "input": "3 1\n1 2\n3 4\n6 7", "output": "6" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 3\n5 6", "output": "3" }, { "input": "1 5\n7 10", "output": "5" }, { "input": "1 100\n5 6", "output": "6" }, { "input": "1 2\n1 1", "output": "1" }, { "input": "1 100000\n100000 100000", "output": "100000" }, { "input": "2 3\n1 1\n5 6", "output": "3" } ]
1,688,025,787
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
78
5,222,400
L1= [int(x) for x in input().split(" ")] n=L1[0] suru=L1[1] L3=[] time=1 currtime=0 for i in range(0,n): L2= [int(x) for x in input().split(" ")] L3.append(L2) usermax=L3[n-1][1] L5=[] ctr=0 string="" for i in range(1,usermax+1): L5.append(i) #print(L5) L6=[] for i in L3: skip=(i[0]-currtime)//suru num=skip*suru currtime=currtime+1 for j in range(0,num): L6.append(time) time=time+1 currtime=currtime+i[1] time=currtime #print(L6) for i in L6: if i in L5: L5.remove(i) if suru==1: print(len(L5)+1) else: print(len(L5))
Title: Watching a movie Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments? Input Specification: The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*. Output Specification: Output a single number — the answer to the problem. Demo Input: ['2 3\n5 6\n10 12\n', '1 1\n1 100000\n'] Demo Output: ['6\n', '100000\n'] Note: In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
```python L1= [int(x) for x in input().split(" ")] n=L1[0] suru=L1[1] L3=[] time=1 currtime=0 for i in range(0,n): L2= [int(x) for x in input().split(" ")] L3.append(L2) usermax=L3[n-1][1] L5=[] ctr=0 string="" for i in range(1,usermax+1): L5.append(i) #print(L5) L6=[] for i in L3: skip=(i[0]-currtime)//suru num=skip*suru currtime=currtime+1 for j in range(0,num): L6.append(time) time=time+1 currtime=currtime+i[1] time=currtime #print(L6) for i in L6: if i in L5: L5.remove(i) if suru==1: print(len(L5)+1) else: print(len(L5)) ```
0
190
A
Vasya and the Bus
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his *k* (*k*<=&gt;<=0) children, pays overall *k* rubles: a ticket for himself and (*k*<=-<=1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.
The input file consists of a single line containing two space-separated numbers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=105) — the number of the grown-ups and the number of the children in the bus, correspondingly.
If *n* grown-ups and *m* children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes).
[ "1 2\n", "0 5\n", "2 2\n" ]
[ "2 2", "Impossible", "2 3" ]
In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: - Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. - One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
500
[ { "input": "1 2", "output": "2 2" }, { "input": "0 5", "output": "Impossible" }, { "input": "2 2", "output": "2 3" }, { "input": "2 7", "output": "7 8" }, { "input": "4 10", "output": "10 13" }, { "input": "6 0", "output": "6 6" }, { "input": "7 1", "output": "7 7" }, { "input": "0 0", "output": "0 0" }, { "input": "71 24", "output": "71 94" }, { "input": "16 70", "output": "70 85" }, { "input": "0 1", "output": "Impossible" }, { "input": "1 0", "output": "1 1" }, { "input": "1 1", "output": "1 1" }, { "input": "63 82", "output": "82 144" }, { "input": "8 26", "output": "26 33" }, { "input": "21 27", "output": "27 47" }, { "input": "0 38", "output": "Impossible" }, { "input": "46 84", "output": "84 129" }, { "input": "59 96", "output": "96 154" }, { "input": "63028 0", "output": "63028 63028" }, { "input": "9458 0", "output": "9458 9458" }, { "input": "80236 0", "output": "80236 80236" }, { "input": "26666 0", "output": "26666 26666" }, { "input": "59617 0", "output": "59617 59617" }, { "input": "0 6048", "output": "Impossible" }, { "input": "63028 28217", "output": "63028 91244" }, { "input": "9458 39163", "output": "39163 48620" }, { "input": "80236 14868", "output": "80236 95103" }, { "input": "26666 52747", "output": "52747 79412" }, { "input": "59617 28452", "output": "59617 88068" }, { "input": "6048 4158", "output": "6048 10205" }, { "input": "76826 4210", "output": "76826 81035" }, { "input": "23256 15156", "output": "23256 38411" }, { "input": "56207 53035", "output": "56207 109241" }, { "input": "2637 28740", "output": "28740 31376" }, { "input": "73415 4445", "output": "73415 77859" }, { "input": "82019 4498", "output": "82019 86516" }, { "input": "28449 80204", "output": "80204 108652" }, { "input": "99227 53323", "output": "99227 152549" }, { "input": "45657 29028", "output": "45657 74684" }, { "input": "78608 4733", "output": "78608 83340" }, { "input": "25038 4786", "output": "25038 29823" }, { "input": "95816 80492", "output": "95816 176307" }, { "input": "42246 94024", "output": "94024 136269" }, { "input": "0 100000", "output": "Impossible" }, { "input": "100000 0", "output": "100000 100000" }, { "input": "1 100000", "output": "100000 100000" }, { "input": "100000 1", "output": "100000 100000" }, { "input": "63028 63028", "output": "63028 126055" }, { "input": "9458 9458", "output": "9458 18915" }, { "input": "80236 80236", "output": "80236 160471" }, { "input": "26666 26666", "output": "26666 53331" }, { "input": "59617 59617", "output": "59617 119233" }, { "input": "100000 100000", "output": "100000 199999" } ]
1,661,671,127
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
x = int(input('Enter a number: ')) if x%2 == 0 print('You have entered an even number.') else: print('You have entered an odd number.')
Title: Vasya and the Bus Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his *k* (*k*<=&gt;<=0) children, pays overall *k* rubles: a ticket for himself and (*k*<=-<=1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. Input Specification: The input file consists of a single line containing two space-separated numbers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=105) — the number of the grown-ups and the number of the children in the bus, correspondingly. Output Specification: If *n* grown-ups and *m* children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes). Demo Input: ['1 2\n', '0 5\n', '2 2\n'] Demo Output: ['2 2', 'Impossible', '2 3'] Note: In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: - Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. - One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
```python x = int(input('Enter a number: ')) if x%2 == 0 print('You have entered an even number.') else: print('You have entered an odd number.') ```
-1
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe reposted PoLyCaRp\n" ]
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "output": "2" }, { "input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp", "output": "2" }, { "input": "1\niuNtwVf reposted POlYcarP", "output": "2" }, { "input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS", "output": "11" }, { "input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl", "output": "6" }, { "input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj", "output": "9" }, { "input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI", "output": "3" } ]
1,425,753,420
13,020
PyPy 3
OK
TESTS
36
109
307,200
n = int(input()) a = {} a['polycarp'] = 1 for i in range(n): inp = input().split() a[inp[0].lower()] = a[inp[2].lower()] + 1 mx = 0 for key in a: mx = max(mx, a[key]) print(mx)
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. Output Specification: Print a single integer — the maximum length of a repost chain. Demo Input: ['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n'] Demo Output: ['6\n', '2\n', '2\n'] Note: none
```python n = int(input()) a = {} a['polycarp'] = 1 for i in range(n): inp = input().split() a[inp[0].lower()] = a[inp[2].lower()] + 1 mx = 0 for key in a: mx = max(mx, a[key]) print(mx) ```
3
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" }, { "input": "1024", "output": "10" }, { "input": "99999", "output": "11" }, { "input": "10007", "output": "1" }, { "input": "4096", "output": "12" }, { "input": "65536", "output": "16" }, { "input": "40320", "output": "95" }, { "input": "30030", "output": "63" }, { "input": "161", "output": "3" }, { "input": "1000", "output": "15" }, { "input": "10000", "output": "24" }, { "input": "777", "output": "7" }, { "input": "121", "output": "2" }, { "input": "25", "output": "2" }, { "input": "40000", "output": "34" }, { "input": "99990", "output": "47" }, { "input": "98765", "output": "3" }, { "input": "56789", "output": "3" }, { "input": "13579", "output": "3" }, { "input": "97531", "output": "3" }, { "input": "12345", "output": "7" }, { "input": "54321", "output": "7" }, { "input": "83160", "output": "127" }, { "input": "9", "output": "2" }, { "input": "21", "output": "3" }, { "input": "11", "output": "1" }, { "input": "15", "output": "3" } ]
1,655,791,689
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
n=int(input()) a="" for i in range(1,n,1): if n%i==0 : a=a+str(i) print(len(a))
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. Input Specification: The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. Output Specification: Print a single integer representing the answer to the problem. Demo Input: ['2\n', '10\n'] Demo Output: ['1\n', '3\n'] Note: In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
```python n=int(input()) a="" for i in range(1,n,1): if n%i==0 : a=a+str(i) print(len(a)) ```
0
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2", "output": "5\n7\n5\n5\n2\n7\n7\n13\n4" }, { "input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7", "output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326" }, { "input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29", "output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772" }, { "input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12", "output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195" }, { "input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1", "output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2" }, { "input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2", "output": "6\n1\n6\n1\n5\n6\n1\n5" }, { "input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4", "output": "22\n10\n10\n6\n12\n36\n6\n14\n16" }, { "input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4", "output": "11\n11\n2\n10\n1\n3\n10\n12\n12" }, { "input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5", "output": "8\n27\n1\n8\n26" }, { "input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8", "output": "10\n2\n13\n10" }, { "input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5", "output": "9\n24\n28" }, { "input": "1\n1\n2\n1 1 1\n2 1 1", "output": "1\n1" } ]
1,665,589,421
2,147,483,647
PyPy 3-64
OK
TESTS
46
1,153
17,817,600
n = int(input()) v = list(map(int,input().split())) u = sorted(v) dp = [0] dps = [0] for i in range(n): dp.append(dp[-1]+v[i]) dps.append(dps[-1]+u[i]) m = int(input()) for _ in range(m): type,l,r = map(int,input().split()) if type == 1: print(dp[r]-dp[l-1]) else: print(dps[r]-dps[l-1])
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. Output Specification: Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. Demo Input: ['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n'] Demo Output: ['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n'] Note: Please note that the answers to the questions may overflow 32-bit integer type.
```python n = int(input()) v = list(map(int,input().split())) u = sorted(v) dp = [0] dps = [0] for i in range(n): dp.append(dp[-1]+v[i]) dps.append(dps[-1]+u[i]) m = int(input()) for _ in range(m): type,l,r = map(int,input().split()) if type == 1: print(dp[r]-dp[l-1]) else: print(dps[r]-dps[l-1]) ```
3
779
C
Dishonest Sellers
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items.
In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week).
Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now.
[ "3 1\n5 4 6\n3 1 5\n", "5 3\n3 4 7 10 3\n4 5 5 12 5\n" ]
[ "10\n", "25\n" ]
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
1,000
[ { "input": "3 1\n5 4 6\n3 1 5", "output": "10" }, { "input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25" }, { "input": "1 0\n9\n8", "output": "8" }, { "input": "2 0\n4 10\n1 2", "output": "3" }, { "input": "4 2\n19 5 17 13\n3 18 8 10", "output": "29" }, { "input": "5 3\n28 17 20 45 45\n39 12 41 27 9", "output": "101" }, { "input": "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31", "output": "243" }, { "input": "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 166 114 53 144 106 141 106 191 123 44 199 35 18 84 169 46 52 129 102 155 130 63 169 116 145 154 41\n155 187 79 106 136 173 17 146 9 47 173 21 37 183 110 74 185 14 82 156 147 25 162 195 26 25 22 80 171 180 7 92 53 18 100 17 159 184 37 127 116 192 163 49 94 95 118 102 8 30", "output": "4680" }, { "input": "5 2\n1 1 1 1 1\n2 2 2 2 2", "output": "5" }, { "input": "5 2\n2 4 4 4 4\n3 1 1 1 1", "output": "9" }, { "input": "6 3\n9 9 9 2 2 2\n6 6 6 1 1 1", "output": "24" }, { "input": "5 3\n10 17 23 26 35\n7 18 18 29 32", "output": "103" }, { "input": "2 1\n10 12\n5 6", "output": "16" } ]
1,700,413,180
2,147,483,647
Python 3
OK
TESTS
67
218
35,840,000
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) d = sorted([b_el - a_el for b_el, a_el in zip(b, a) if b_el - a_el < 0]) print(sum(a) + sum(d[:n - k]))
Title: Dishonest Sellers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items. Input Specification: In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week). Output Specification: Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. Demo Input: ['3 1\n5 4 6\n3 1 5\n', '5 3\n3 4 7 10 3\n4 5 5 12 5\n'] Demo Output: ['10\n', '25\n'] Note: In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
```python n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) d = sorted([b_el - a_el for b_el, a_el in zip(b, a) if b_el - a_el < 0]) print(sum(a) + sum(d[:n - k])) ```
3
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "output": "3" }, { "input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32", "output": "6" }, { "input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30", "output": "10" }, { "input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20", "output": "8" }, { "input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49", "output": "1" }, { "input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16", "output": "5" }, { "input": "2\n0 24\n1 0", "output": "1" }, { "input": "1\n0 0", "output": "1" }, { "input": "1\n1 5", "output": "1" }, { "input": "1\n1 1", "output": "1" }, { "input": "3\n0 0\n0 0\n0 0", "output": "3" }, { "input": "1\n5 0", "output": "1" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5" }, { "input": "1\n10 10", "output": "1" }, { "input": "1\n8 0", "output": "1" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "10" }, { "input": "2\n0 0\n0 1", "output": "1" }, { "input": "2\n8 5\n8 5", "output": "2" } ]
1,680,777,726
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
def it(): return int(input()) def pr(a): return print(a) def li(): return list(map(int, input().split())) def ls(): return [str(i) for i in input()] def no(): return print('NO') def yes(): return print('YES') kol = 1 m = [] for i in range(it()): a, b = map(int, input().split()) m.append(a+b) for i in range(len(m)-1): if m[i] == m[i+1]: kol += 1 print(kol) '''??????????????????| -_- |???????????????????'''
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period. Output Specification: Print a single integer — the minimum number of cashes, needed to serve all clients next day. Demo Input: ['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
```python def it(): return int(input()) def pr(a): return print(a) def li(): return list(map(int, input().split())) def ls(): return [str(i) for i in input()] def no(): return print('NO') def yes(): return print('YES') kol = 1 m = [] for i in range(it()): a, b = map(int, input().split()) m.append(a+b) for i in range(len(m)-1): if m[i] == m[i+1]: kol += 1 print(kol) '''??????????????????| -_- |???????????????????''' ```
0
129
B
Students and Shoelaces
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one. To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student. Determine how many groups of students will be kicked out of the club.
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Print the single number — the number of groups of students that will be kicked out from the club.
[ "3 3\n1 2\n2 3\n3 1\n", "6 3\n1 2\n2 3\n3 4\n", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club. In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
1,000
[ { "input": "3 3\n1 2\n2 3\n3 1", "output": "0" }, { "input": "6 3\n1 2\n2 3\n3 4", "output": "2" }, { "input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4", "output": "1" }, { "input": "100 0", "output": "0" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "0" }, { "input": "5 4\n1 4\n4 3\n4 5\n5 2", "output": "2" }, { "input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11", "output": "4" }, { "input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7", "output": "2" }, { "input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6", "output": "0" }, { "input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3", "output": "0" }, { "input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5", "output": "0" }, { "input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6", "output": "1" }, { "input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4", "output": "0" }, { "input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4", "output": "0" }, { "input": "95 0", "output": "0" }, { "input": "100 0", "output": "0" }, { "input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39", "output": "2" }, { "input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51", "output": "3" }, { "input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41", "output": "3" }, { "input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65", "output": "5" }, { "input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7", "output": "4" }, { "input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35", "output": "4" }, { "input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65", "output": "8" }, { "input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36", "output": "4" }, { "input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70", "output": "4" }, { "input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66", "output": "3" }, { "input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27", "output": "8" }, { "input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51", "output": "4" }, { "input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75", "output": "5" }, { "input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31", "output": "3" }, { "input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35", "output": "8" }, { "input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37", "output": "3" }, { "input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41", "output": "4" }, { "input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53", "output": "5" } ]
1,661,801,409
2,147,483,647
Python 3
OK
TESTS
70
186
0
sn, ln = map(int, input().split()) laces = [list(map(int, input().split())) for _ in range(ln)] ans = 0 while True: deleted_list = [i for i in range(1, sn + 1) if sum([lace.count(i) for lace in laces]) == 1] if len(deleted_list) == 0: break laces = [lace for lace in laces if lace[0] not in deleted_list and lace[1] not in deleted_list] ans += 1 print(ans)
Title: Students and Shoelaces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one. To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student. Determine how many groups of students will be kicked out of the club. Input Specification: The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. Output Specification: Print the single number — the number of groups of students that will be kicked out from the club. Demo Input: ['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club. In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
```python sn, ln = map(int, input().split()) laces = [list(map(int, input().split())) for _ in range(ln)] ans = 0 while True: deleted_list = [i for i in range(1, sn + 1) if sum([lace.count(i) for lace in laces]) == 1] if len(deleted_list) == 0: break laces = [lace for lace in laces if lace[0] not in deleted_list and lace[1] not in deleted_list] ans += 1 print(ans) ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "output": "90" }, { "input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88", "output": "90" }, { "input": "90\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", "output": "90" }, { "input": "1\n1", "output": "16" }, { "input": "5\n15 30 45 60 75", "output": "90" }, { "input": "6\n14 29 43 59 70 74", "output": "58" }, { "input": "1\n15", "output": "30" }, { "input": "1\n16", "output": "15" }, { "input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89", "output": "90" }, { "input": "76\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 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", "output": "90" }, { "input": "1\n90", "output": "15" }, { "input": "6\n13 17 32 47 60 66", "output": "81" }, { "input": "84\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", "output": "90" }, { "input": "9\n6 20 27 28 40 53 59 70 85", "output": "90" }, { "input": "12\n14 22 27 31 35 44 62 69 74 79 88 89", "output": "59" }, { "input": "5\n15 30 45 60 74", "output": "89" }, { "input": "72\n3 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 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", "output": "54" }, { "input": "8\n1 16 30 31 32 33 34 50", "output": "49" }, { "input": "12\n1 3 6 10 15 21 28 36 45 55 66 78", "output": "90" }, { "input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90", "output": "80" }, { "input": "8\n5 17 20 35 42 53 67 76", "output": "90" }, { "input": "9\n15 28 39 48 55 60 63 64 74", "output": "89" }, { "input": "10\n15 28 39 48 55 60 63 64 74 82", "output": "90" }, { "input": "2\n1 18", "output": "16" }, { "input": "9\n10 20 30 40 50 60 70 80 84", "output": "90" }, { "input": "2\n16 50", "output": "15" }, { "input": "6\n15 30 45 60 75 84", "output": "90" }, { "input": "8\n15 20 30 40 50 60 73 83", "output": "90" }, { "input": "8\n10 20 30 40 50 60 70 80", "output": "90" }, { "input": "3\n1 20 90", "output": "16" }, { "input": "6\n15 30 45 60 74 89", "output": "90" } ]
1,629,176,403
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
6,758,400
N = input() T = list(map(int, input().split())) number_of_minutes = 0 for t in T: if t - number_of_minutes <= 15: number_of_minutes = t else: break if number_of_minutes < 90: number_of_minutes += 15 print(number_of_minutes)
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order. Output Specification: Print the number of minutes Limak will watch the game. Demo Input: ['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n'] Demo Output: ['35\n', '15\n', '90\n'] Note: In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
```python N = input() T = list(map(int, input().split())) number_of_minutes = 0 for t in T: if t - number_of_minutes <= 15: number_of_minutes = t else: break if number_of_minutes < 90: number_of_minutes += 15 print(number_of_minutes) ```
0
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,697,099,720
2,147,483,647
PyPy 3-64
OK
TESTS
40
186
2,764,800
k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) lst = [0]*(d+1) w,x,y,z = 1,1,1,1 while w*k<=d or x*l<=d or y*m<=d or z*n<=d: if w*k<=d: lst[w*k] = 1 w+=1 if x*l<=d: lst[x*l] = 1 x+=1 if y*m<=d: lst[y*m] = 1 y+=1 if z*n<=d: lst[z*n] = 1 z+=1 cnt = 0 for i in range(1,d+1): if lst[i] == 1: cnt+=1 print(cnt)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
```python k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) lst = [0]*(d+1) w,x,y,z = 1,1,1,1 while w*k<=d or x*l<=d or y*m<=d or z*n<=d: if w*k<=d: lst[w*k] = 1 w+=1 if x*l<=d: lst[x*l] = 1 x+=1 if y*m<=d: lst[y*m] = 1 y+=1 if z*n<=d: lst[z*n] = 1 z+=1 cnt = 0 for i in range(1,d+1): if lst[i] == 1: cnt+=1 print(cnt) ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481 554 1000 821", "output": "15" }, { "input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396", "output": "144" }, { "input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366", "output": "145" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n2", "output": "2" }, { "input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19", "output": "63" }, { "input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386", "output": "31" }, { "input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518", "output": "75" }, { "input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397", "output": "41" }, { "input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118", "output": "116" } ]
1,692,211,626
2,147,483,647
Python 3
OK
TESTS
29
46
0
r,c=map(int,input().split()) lst=list(map(int,input().split())) count=0 for ele in lst: if ele> c: count=count+2 else: count=count+1 print(count)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? Input Specification: The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. Output Specification: Print a single integer — the minimum possible valid width of the road. Demo Input: ['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n'] Demo Output: ['4\n', '6\n', '11\n'] Note: In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
```python r,c=map(int,input().split()) lst=list(map(int,input().split())) count=0 for ele in lst: if ele> c: count=count+2 else: count=count+1 print(count) ```
3
583
A
Asphalting Roads
PROGRAMMING
1,000
[ "implementation" ]
null
null
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted. Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads. According to the schedule of road works tell in which days at least one road will be asphalted.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
[ "2\n1 1\n1 2\n2 1\n2 2\n", "1\n1 1\n" ]
[ "1 4 \n", "1 \n" ]
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.
500
[ { "input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4 " }, { "input": "1\n1 1", "output": "1 " }, { "input": "2\n1 1\n2 2\n1 2\n2 1", "output": "1 2 " }, { "input": "2\n1 2\n2 2\n2 1\n1 1", "output": "1 3 " }, { "input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 1", "output": "1 4 5 " }, { "input": "3\n1 3\n3 1\n2 1\n1 1\n1 2\n2 2\n3 2\n3 3\n2 3", "output": "1 2 6 " }, { "input": "4\n1 3\n2 3\n2 4\n4 4\n3 1\n1 1\n3 4\n2 1\n1 4\n4 3\n4 1\n3 2\n1 2\n4 2\n2 2\n3 3", "output": "1 3 5 14 " }, { "input": "4\n3 3\n4 2\n2 3\n3 4\n4 4\n1 2\n3 2\n2 2\n1 4\n3 1\n4 1\n2 1\n1 3\n1 1\n4 3\n2 4", "output": "1 2 9 12 " }, { "input": "9\n4 5\n2 3\n8 3\n5 6\n9 3\n4 4\n5 4\n4 7\n1 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n9 9\n8 7\n7 5\n3 7\n6 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n1 1\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 2\n3 9\n2 9\n7 7\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n3 3\n3 8\n5 5\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n8 8\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8", "output": "1 2 4 9 10 14 16 32 56 " }, { "input": "8\n1 1\n1 2\n1 3\n1 4\n1 5\n8 6\n1 7\n1 8\n2 1\n8 5\n2 3\n2 4\n2 5\n2 6\n4 3\n2 2\n3 1\n3 2\n3 3\n3 4\n3 5\n3 6\n5 6\n3 8\n4 1\n4 2\n2 7\n4 4\n8 8\n4 6\n4 7\n4 8\n5 1\n5 2\n5 3\n6 5\n5 5\n3 7\n5 7\n5 8\n6 1\n6 2\n6 3\n6 4\n5 4\n6 6\n6 7\n6 8\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n7 8\n8 1\n8 2\n8 3\n8 4\n2 8\n1 6\n8 7\n4 5", "output": "1 6 11 18 28 36 39 56 " }, { "input": "9\n9 9\n5 5\n8 8\n3 3\n2 2\n6 6\n4 4\n1 1\n7 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n1 7\n8 7\n7 5\n3 7\n5 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n4 5\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 3\n3 9\n2 9\n5 4\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n8 3\n3 8\n9 3\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n4 7\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8", "output": "1 2 3 4 5 6 7 8 9 " } ]
1,461,495,779
2,147,483,647
Python 3
OK
TESTS
39
92
5,120,000
n = int(input()) G = []; V = []; res = [] for i in range(n*n): h,v = map(int, input().split()) if G.count(h)==0 and V.count(v)==0: G.append(h) V.append(v) res.append(i+1) print(*res)
Title: Asphalting Roads Time Limit: None seconds Memory Limit: None megabytes Problem Description: City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted. Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads. According to the schedule of road works tell in which days at least one road will be asphalted. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct. Output Specification: In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. Demo Input: ['2\n1 1\n1 2\n2 1\n2 2\n', '1\n1 1\n'] Demo Output: ['1 4 \n', '1 \n'] Note: In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.
```python n = int(input()) G = []; V = []; res = [] for i in range(n*n): h,v = map(int, input().split()) if G.count(h)==0 and V.count(v)==0: G.append(h) V.append(v) res.append(i+1) print(*res) ```
3
0
none
none
none
0
[ "none" ]
null
null
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor. While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged. If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*. All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office. Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line. Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child.
In the first line print number *k* — the number of children whose teeth Gennady will cure. In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order.
[ "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n" ]
[ "2\n1 3 ", "4\n1 2 4 5 " ]
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit. In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
0
[ { "input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "output": "2\n1 3 " }, { "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "output": "4\n1 2 4 5 " }, { "input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "output": "3\n1 2 5 " }, { "input": "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "output": "6\n1 2 3 4 5 7 " }, { "input": "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 30\n8 7 38\n6 5 5\n6 9 37", "output": "8\n1 2 3 4 5 7 8 10 " }, { "input": "10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6", "output": "5\n1 2 3 5 8 " }, { "input": "10\n5 6 1\n9 2 6\n4 1 5\n4 10 5\n1 8 23\n9 4 21\n3 9 6\n7 8 34\n7 4 24\n8 9 21", "output": "5\n1 2 5 6 8 " }, { "input": "4\n2 10 1\n1 2 2\n2 1 1\n5 5 1", "output": "3\n1 2 4 " }, { "input": "1\n1 1 1", "output": "1\n1 " }, { "input": "2\n5 1 1\n1 1 5", "output": "2\n1 2 " }, { "input": "2\n5 1 1\n1 1 4", "output": "1\n1 " }, { "input": "2\n5 1 1\n1 1 6", "output": "2\n1 2 " }, { "input": "3\n5 1 1\n1 1 4\n1 1 4", "output": "1\n1 " }, { "input": "3\n5 1 1\n1 1 4\n1 1 5", "output": "2\n1 3 " }, { "input": "3\n5 1 1\n1 1 5\n1 1 3", "output": "2\n1 2 " }, { "input": "3\n5 1 1\n10 1 5\n1000 1000 14", "output": "3\n1 2 3 " }, { "input": "10\n9 8 8\n2 9 33\n10 7 42\n7 2 18\n3 5 82\n9 9 25\n3 2 86\n3 5 49\n5 3 72\n4 4 71", "output": "10\n1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n9 8 8\n2 9 8\n10 7 16\n7 2 9\n3 5 23\n9 9 25\n3 2 35\n3 5 36\n5 3 40\n4 4 42", "output": "1\n1 " } ]
1,460,524,639
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
0
a=int(input()) b=[]*a c=list() c.append(1) for i in range(a): b.append(list(map(int,input().split()))) def cry(p,a,b): for i in range(p+1,a): b[i][2] -= b[p][0]-i+1+p for i in range(p+1,a): if b[i][2] <0: for j in range(i+1,a): b[j][2] -= b[i][1] cry(0,a,b) t=1 while t<a: for i in range(t,a): if b[i][2]>=0: c.append(i+1) t=i break cry(t,a,b) t=t+1 print(len(c)) for i in range(len(c)): print(c[i],end=' ')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor. While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged. If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*. All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office. Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line. Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child. Output Specification: In the first line print number *k* — the number of children whose teeth Gennady will cure. In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order. Demo Input: ['5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n', '5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n'] Demo Output: ['2\n1 3 ', '4\n1 2 4 5 '] Note: In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit. In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
```python a=int(input()) b=[]*a c=list() c.append(1) for i in range(a): b.append(list(map(int,input().split()))) def cry(p,a,b): for i in range(p+1,a): b[i][2] -= b[p][0]-i+1+p for i in range(p+1,a): if b[i][2] <0: for j in range(i+1,a): b[j][2] -= b[i][1] cry(0,a,b) t=1 while t<a: for i in range(t,a): if b[i][2]>=0: c.append(i+1) t=i break cry(t,a,b) t=t+1 print(len(c)) for i in range(len(c)): print(c[i],end=' ') ```
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,695,123,460
2,147,483,647
Python 3
OK
TESTS
20
46
0
import math n,m,a=map(int,input().split()) leng=math.ceil(n/a) bre=math.ceil(m/a) total=leng*bre print(total)
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 import math n,m,a=map(int,input().split()) leng=math.ceil(n/a) bre=math.ceil(m/a) total=leng*bre print(total) ```
3.977
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,615,526,530
2,147,483,647
PyPy 3
OK
TESTS
44
248
512,000
#!/usr/bin/env python from __future__ import division, print_function import math import os import sys from sys import stdin,stdout from io import BytesIO, IOBase from itertools import accumulate from collections import deque #sys.setrecursionlimit(10**5) if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #----------------------------------------------------------------- def regularbracket(t): p=0 for i in t: if i=="(": p+=1 else: p-=1 if p<0: return False else: if p>0: return False else: return True #------------------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] <= key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count #------------------------------reverse string(pallindrome) def reverse1(string): pp="" for i in string[::-1]: pp+=i if pp==string: return True return False #--------------------------------reverse list(paindrome) def reverse2(list1): l=[] for i in list1[::-1]: l.append(i) if l==list1: return True return False # endregion import math def mex(list1): #list1 = sorted(list1) p = max(list1)+1 for i in range(len(list1)): if list1[i]!=i: p = i break return p #----endregion """ def main(): n,m = map(int,input().split()) np = list(map(int,input().split())) mp = list(map(int,input().split())) np = sorted(np) mp = sorted(mp) cnt=0 for i in np: if len(mp)==0: cnt+=1 elif i in mp: continue elif i>max(mp): cnt+=1 elif i<max(mp): #cnt-=1 for j in mp: if j>i: mp.remove(j) break print(cnt) """ """ def main(): n = int(input()) arr = list(map(int,input().split())) max=0 if len(arr)==1: print(1) elif len(arr)==2: print(2) else: cnt=2 for i in range(n-2): if arr[i+2]==arr[i+1]+arr[i]: cnt+=1 else: if cnt>max: max = cnt cnt=2 if cnt>max: max=cnt print(max) """ def main(): n = int(input()) arr = list(map(int,input().split())) arr = sorted(arr) p=0 if len(arr)%2!=0: c = (math.pi)*(pow(arr[0],2)) arr.pop(0) i=0 p=0 while(i<len(arr)-1): p+=(math.pi*(pow(arr[i+1],2))) - ((math.pi*(pow(arr[i],2)))) i+=2 print(p+c) else: i=0 while(i<len(arr)-1): p += (math.pi * (pow(arr[i + 1], 2))) - ((math.pi * (pow(arr[i], 2)))) i+=2 print(p) if __name__ == '__main__': main()
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 #!/usr/bin/env python from __future__ import division, print_function import math import os import sys from sys import stdin,stdout from io import BytesIO, IOBase from itertools import accumulate from collections import deque #sys.setrecursionlimit(10**5) if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #----------------------------------------------------------------- def regularbracket(t): p=0 for i in t: if i=="(": p+=1 else: p-=1 if p<0: return False else: if p>0: return False else: return True #------------------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] <= key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count #------------------------------reverse string(pallindrome) def reverse1(string): pp="" for i in string[::-1]: pp+=i if pp==string: return True return False #--------------------------------reverse list(paindrome) def reverse2(list1): l=[] for i in list1[::-1]: l.append(i) if l==list1: return True return False # endregion import math def mex(list1): #list1 = sorted(list1) p = max(list1)+1 for i in range(len(list1)): if list1[i]!=i: p = i break return p #----endregion """ def main(): n,m = map(int,input().split()) np = list(map(int,input().split())) mp = list(map(int,input().split())) np = sorted(np) mp = sorted(mp) cnt=0 for i in np: if len(mp)==0: cnt+=1 elif i in mp: continue elif i>max(mp): cnt+=1 elif i<max(mp): #cnt-=1 for j in mp: if j>i: mp.remove(j) break print(cnt) """ """ def main(): n = int(input()) arr = list(map(int,input().split())) max=0 if len(arr)==1: print(1) elif len(arr)==2: print(2) else: cnt=2 for i in range(n-2): if arr[i+2]==arr[i+1]+arr[i]: cnt+=1 else: if cnt>max: max = cnt cnt=2 if cnt>max: max=cnt print(max) """ def main(): n = int(input()) arr = list(map(int,input().split())) arr = sorted(arr) p=0 if len(arr)%2!=0: c = (math.pi)*(pow(arr[0],2)) arr.pop(0) i=0 p=0 while(i<len(arr)-1): p+=(math.pi*(pow(arr[i+1],2))) - ((math.pi*(pow(arr[i],2)))) i+=2 print(p+c) else: i=0 while(i<len(arr)-1): p += (math.pi * (pow(arr[i + 1], 2))) - ((math.pi * (pow(arr[i], 2)))) i+=2 print(p) if __name__ == '__main__': main() ```
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,661,578
4,878
Python 3
OK
TESTS
46
77
4,608,000
inp = str(input()); s = '' for s in inp: s = inp.split(' ') n = int(s[0]) m = int(s[1]) k = int(s[2]) i = 0 r = 1 d = 1; p = 0 while(k > 2 * m * r): p = 2 * m * r r += 1; while(k > p): p += 1 if (i == 2): i = 0; d += 1; i += 1 if(k % 2 == 0): print(r,d,'R') else:print(r,d,'L')
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 inp = str(input()); s = '' for s in inp: s = inp.split(' ') n = int(s[0]) m = int(s[1]) k = int(s[2]) i = 0 r = 1 d = 1; p = 0 while(k > 2 * m * r): p = 2 * m * r r += 1; while(k > p): p += 1 if (i == 2): i = 0; d += 1; i += 1 if(k % 2 == 0): print(r,d,'R') else:print(r,d,'L') ```
3
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros.
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 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> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "1000000000000000000 1000000000000000000", "output": "0" }, { "input": "1 1000000000000000000", "output": "1712" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 7", "output": "3" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "2" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "3" }, { "input": "3 3", "output": "0" }, { "input": "3 4", "output": "0" }, { "input": "3 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "2" }, { "input": "4 4", "output": "0" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "2" }, { "input": "5 7", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "7 7", "output": "0" }, { "input": "1 8", "output": "3" }, { "input": "6 8", "output": "1" }, { "input": "7 8", "output": "0" }, { "input": "8 8", "output": "0" }, { "input": "1 1022", "output": "45" }, { "input": "1 1023", "output": "45" }, { "input": "1 1024", "output": "45" }, { "input": "1 1025", "output": "45" }, { "input": "1 1026", "output": "45" }, { "input": "509 1022", "output": "11" }, { "input": "510 1022", "output": "10" }, { "input": "511 1022", "output": "9" }, { "input": "512 1022", "output": "9" }, { "input": "513 1022", "output": "9" }, { "input": "509 1023", "output": "11" }, { "input": "510 1023", "output": "10" }, { "input": "511 1023", "output": "9" }, { "input": "512 1023", "output": "9" }, { "input": "513 1023", "output": "9" }, { "input": "509 1024", "output": "11" }, { "input": "510 1024", "output": "10" }, { "input": "511 1024", "output": "9" }, { "input": "512 1024", "output": "9" }, { "input": "513 1024", "output": "9" }, { "input": "509 1025", "output": "11" }, { "input": "510 1025", "output": "10" }, { "input": "511 1025", "output": "9" }, { "input": "512 1025", "output": "9" }, { "input": "513 1025", "output": "9" }, { "input": "1 1000000000", "output": "408" }, { "input": "10000000000 70000000000000000", "output": "961" }, { "input": "1 935829385028502935", "output": "1712" }, { "input": "500000000000000000 1000000000000000000", "output": "58" }, { "input": "500000000000000000 576460752303423488", "output": "57" }, { "input": "576460752303423488 1000000000000000000", "output": "1" }, { "input": "999999999999999999 1000000000000000000", "output": "0" }, { "input": "1124800395214847 36011204832919551", "output": "257" }, { "input": "1124800395214847 36011204832919550", "output": "256" }, { "input": "1124800395214847 36011204832919552", "output": "257" }, { "input": "1124800395214846 36011204832919551", "output": "257" }, { "input": "1124800395214848 36011204832919551", "output": "256" }, { "input": "1 287104476244869119", "output": "1603" }, { "input": "1 287104476244869118", "output": "1602" }, { "input": "1 287104476244869120", "output": "1603" }, { "input": "492581209243647 1000000000000000000", "output": "583" }, { "input": "492581209243646 1000000000000000000", "output": "583" }, { "input": "492581209243648 1000000000000000000", "output": "582" }, { "input": "1099444518911 1099444518911", "output": "1" }, { "input": "1099444518910 1099444518911", "output": "1" }, { "input": "1099444518911 1099444518912", "output": "1" }, { "input": "1099444518910 1099444518912", "output": "1" }, { "input": "864691128455135231 864691128455135231", "output": "1" }, { "input": "864691128455135231 864691128455135232", "output": "1" }, { "input": "864691128455135230 864691128455135232", "output": "1" }, { "input": "864691128455135230 864691128455135231", "output": "1" }, { "input": "864691128455135231 1000000000000000000", "output": "1" }, { "input": "864691128455135232 1000000000000000000", "output": "0" }, { "input": "864691128455135230 1000000000000000000", "output": "1" }, { "input": "576460752303423487 576460752303423487", "output": "0" }, { "input": "1 576460752303423487", "output": "1711" }, { "input": "1 576460752303423486", "output": "1711" }, { "input": "2 1000000000000000000", "output": "1712" }, { "input": "3 1000000000000000000", "output": "1711" }, { "input": "4 1000000000000000000", "output": "1711" }, { "input": "5 1000000000000000000", "output": "1711" }, { "input": "6 1000000000000000000", "output": "1710" }, { "input": "5 6", "output": "2" }, { "input": "1 2", "output": "1" } ]
1,564,159,486
2,147,483,647
Python 3
OK
TESTS
103
109
0
n, m = map(int,input().split()) a = len(bin(n))-2 b = len(bin(m))-2 count = 0 for i in range(a, b+1): for j in range(i-1): if n <= 2**i-1-2**j <= m: count+=1 print(count)
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros. Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. Output Specification: Print one integer – the number of years Limak will count in his chosen interval. Demo Input: ['5 10\n', '2015 2015\n', '100 105\n', '72057594000000000 72057595000000000\n'] Demo Output: ['2\n', '1\n', '0\n', '26\n'] Note: In the first sample Limak's interval contains numbers 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> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
```python n, m = map(int,input().split()) a = len(bin(n))-2 b = len(bin(m))-2 count = 0 for i in range(a, b+1): for j in range(i-1): if n <= 2**i-1-2**j <= m: count+=1 print(count) ```
3
735
A
Ostap and Grasshopper
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
[ "5 2\n#G#T#\n", "6 1\nT....G\n", "7 3\nT..#..G\n", "6 2\n..GT..\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
500
[ { "input": "5 2\n#G#T#", "output": "YES" }, { "input": "6 1\nT....G", "output": "YES" }, { "input": "7 3\nT..#..G", "output": "NO" }, { "input": "6 2\n..GT..", "output": "NO" }, { "input": "2 1\nGT", "output": "YES" }, { "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####", "output": "YES" }, { "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####", "output": "NO" }, { "input": "2 1\nTG", "output": "YES" }, { "input": "99 1\n...T.............................................................................................G.", "output": "YES" }, { "input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.", "output": "NO" }, { "input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##", "output": "YES" }, { "input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.", "output": "NO" }, { "input": "100 3\nG..................................................................................................T", "output": "YES" }, { "input": "100 3\nG..................................................................................................T", "output": "YES" }, { "input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T", "output": "NO" }, { "input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T", "output": "NO" }, { "input": "100 3\nG##################################################################################################T", "output": "NO" }, { "input": "100 33\nG..................................................................................................T", "output": "YES" }, { "input": "100 33\nG..................................................................................................T", "output": "YES" }, { "input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T", "output": "YES" }, { "input": "100 33\nG.......#..................#..............................#............................#..........T.", "output": "NO" }, { "input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T", "output": "YES" }, { "input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.", "output": "NO" }, { "input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T", "output": "NO" }, { "input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T", "output": "NO" }, { "input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T", "output": "NO" }, { "input": "100 99\nT..................................................................................................G", "output": "YES" }, { "input": "100 99\nT..................................................................................................G", "output": "YES" }, { "input": "100 99\nT.#...............................#............#..............................##...................G", "output": "YES" }, { "input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G", "output": "YES" }, { "input": "100 99\nG##################################################################################################T", "output": "YES" }, { "input": "100 9\nT..................................................................................................G", "output": "YES" }, { "input": "100 9\nT.................................................................................................G.", "output": "NO" }, { "input": "100 9\nT................................................................................................G..", "output": "NO" }, { "input": "100 1\nG..................................................................................................T", "output": "YES" }, { "input": "100 1\nT..................................................................................................G", "output": "YES" }, { "input": "100 1\n##########G.........T###############################################################################", "output": "YES" }, { "input": "100 1\n#################################################################################################G.T", "output": "YES" }, { "input": "100 17\n##########G################.################.################.################T#####################", "output": "YES" }, { "input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########", "output": "YES" }, { "input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##", "output": "YES" }, { "input": "100 1\nG.............................................#....................................................T", "output": "NO" }, { "input": "100 1\nT.#................................................................................................G", "output": "NO" }, { "input": "100 1\n##########G....#....T###############################################################################", "output": "NO" }, { "input": "100 1\n#################################################################################################G#T", "output": "NO" }, { "input": "100 17\nG################.#################################.################T###############################", "output": "NO" }, { "input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####", "output": "NO" }, { "input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#", "output": "NO" }, { "input": "48 1\nT..............................................G", "output": "YES" }, { "input": "23 1\nT.....................G", "output": "YES" }, { "input": "49 1\nG...............................................T", "output": "YES" }, { "input": "3 1\nTG#", "output": "YES" }, { "input": "6 2\n..TG..", "output": "NO" }, { "input": "14 3\n...G.....#..T.", "output": "NO" }, { "input": "5 4\n##GT#", "output": "NO" }, { "input": "6 2\nT#..G.", "output": "YES" }, { "input": "5 2\nT.G.#", "output": "YES" }, { "input": "6 1\nT...G#", "output": "YES" }, { "input": "5 1\nTG###", "output": "YES" }, { "input": "5 4\n.G..T", "output": "NO" }, { "input": "7 2\nT#...#G", "output": "YES" }, { "input": "7 1\n##TG###", "output": "YES" }, { "input": "7 1\n###GT##", "output": "YES" }, { "input": "5 2\nG..T.", "output": "NO" }, { "input": "5 1\nG.T##", "output": "YES" }, { "input": "6 2\nG.T###", "output": "YES" }, { "input": "6 2\nG#T###", "output": "YES" }, { "input": "10 2\n####T..G..", "output": "NO" }, { "input": "3 1\nGT#", "output": "YES" }, { "input": "4 1\nTG##", "output": "YES" }, { "input": "6 1\n.G..T.", "output": "YES" }, { "input": "10 3\n......G..T", "output": "YES" }, { "input": "3 2\nG.T", "output": "YES" }, { "input": "4 1\n#G.T", "output": "YES" }, { "input": "5 2\nT#G##", "output": "YES" }, { "input": "4 2\nG#.T", "output": "NO" }, { "input": "4 1\nGT##", "output": "YES" } ]
1,662,415,351
2,147,483,647
PyPy 3-64
OK
TESTS
83
62
0
import sys ONLINE_JUDGE = True if not ONLINE_JUDGE: sys.stdin = open("input.txt", "r") ############ ---- Input Functions ---- ############ def inp(): # integer return(int(input())) def inlt(): # lists return(list(map(int,input().split()))) def insr(): # list of characters s = input() return(list(s)) def invr(): # space seperate integers return(map(int,input().split())) ############ ---- Solution ---- ############ n, k = inlt() line = insr() start = line.index("G") end = line.index("T") if start > end: k = -k def valid_dir(): if k > 0: return start <= end else: return start >= end res = "NO" while valid_dir() and (start < n and start >= 0): if start == end: res = "YES" break if line[start] == "#": res = "NO" break start += k sys.stdout.write(res)
Title: Ostap and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. Input Specification: The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. Output Specification: If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). Demo Input: ['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
```python import sys ONLINE_JUDGE = True if not ONLINE_JUDGE: sys.stdin = open("input.txt", "r") ############ ---- Input Functions ---- ############ def inp(): # integer return(int(input())) def inlt(): # lists return(list(map(int,input().split()))) def insr(): # list of characters s = input() return(list(s)) def invr(): # space seperate integers return(map(int,input().split())) ############ ---- Solution ---- ############ n, k = inlt() line = insr() start = line.index("G") end = line.index("T") if start > end: k = -k def valid_dir(): if k > 0: return start <= end else: return start >= end res = "NO" while valid_dir() and (start < n and start >= 0): if start == end: res = "YES" break if line[start] == "#": res = "NO" break start += k sys.stdout.write(res) ```
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,694,179,870
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
import math k=int(input()) y1 = 0 y = 0 y2 = 0 y3 = 0 y4= 0 y=k/1 y1=k/2 y2=k/3 y3=k/4 y4=k/5 l=[y,y1,y2,y3,y4] print(math.ceil(min(l)))
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 import math k=int(input()) y1 = 0 y = 0 y2 = 0 y3 = 0 y4= 0 y=k/1 y1=k/2 y2=k/3 y3=k/4 y4=k/5 l=[y,y1,y2,y3,y4] print(math.ceil(min(l))) ```
-1
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
500
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
1,520,658,460
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
62
5,632,000
a=sorted(list(map(int,input().split()))) if (a[0]+a[3]+a[5]==a[1]+a[2]+a[4]) or (a[0]+a[2]+a[5]==a[1]+a[3]+a[4]) or (a[1]+a[2]+a[5]==a[0]+a[3]+a[4]): print('YES') else: print('NO')
Title: ACM ICPC Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input Specification: The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants Output Specification: Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['1 3 2 1 2 1\n', '1 1 1 1 1 99\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
```python a=sorted(list(map(int,input().split()))) if (a[0]+a[3]+a[5]==a[1]+a[2]+a[4]) or (a[0]+a[2]+a[5]==a[1]+a[3]+a[4]) or (a[1]+a[2]+a[5]==a[0]+a[3]+a[4]): print('YES') else: print('NO') ```
0
264
B
Good Sequences
PROGRAMMING
1,500
[ "dp", "number theory" ]
null
null
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good. Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions: - The sequence is strictly increasing, i.e. *x**i*<=&lt;<=*x**i*<=+<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1). - No two adjacent elements are coprime, i.e. *gcd*(*x**i*,<=*x**i*<=+<=1)<=&gt;<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1) (where *gcd*(*p*,<=*q*) denotes the greatest common divisor of the integers *p* and *q*). - All elements of the sequence are good integers. Find the length of the longest good sequence.
The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=&lt;<=*a**i*<=+<=1).
Print a single integer — the length of the longest good sequence.
[ "5\n2 3 4 6 9\n", "9\n1 2 3 5 6 7 8 9 10\n" ]
[ "4\n", "4\n" ]
In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.
1,000
[ { "input": "5\n2 3 4 6 9", "output": "4" }, { "input": "9\n1 2 3 5 6 7 8 9 10", "output": "4" }, { "input": "4\n1 2 4 6", "output": "3" }, { "input": "7\n1 2 3 4 7 9 10", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "8\n3 4 5 6 7 8 9 10", "output": "4" }, { "input": "5\n2 3 7 9 10", "output": "2" }, { "input": "3\n1 4 7", "output": "1" }, { "input": "1\n4", "output": "1" }, { "input": "9\n1 2 3 4 5 6 7 9 10", "output": "4" }, { "input": "49\n10 34 58 72 126 166 176 180 198 200 208 228 238 248 302 332 340 344 350 354 380 406 418 428 438 442 482 532 536 544 546 554 596 626 642 682 684 704 714 792 804 820 862 880 906 946 954 966 970", "output": "49" }, { "input": "44\n1 5 37 97 107 147 185 187 195 241 249 295 311 323 341 345 363 391 425 431 473 525 539 541 555 577 595 611 647 695 757 759 775 779 869 877 927 935 963 965 967 969 973 975", "output": "15" }, { "input": "3\n21 67 243", "output": "2" }, { "input": "3\n150 358 382", "output": "3" }, { "input": "10\n13 2187 2197 4567 5200 29873 67866 98798 99999 100000", "output": "6" }, { "input": "10\n1 2 4 8 16 32 33 64 128 256", "output": "8" }, { "input": "10\n2 4 8 67 128 324 789 1296 39877 98383", "output": "7" }, { "input": "10\n2 3 4 5 6 8 9 10 17 92", "output": "6" }, { "input": "10\n2 3 10 40 478 3877 28787 88888 99999 100000", "output": "6" }, { "input": "10\n2 3 45 67 89 101 234 567 890 1234", "output": "5" }, { "input": "10\n2 3 4 5 6 7 8 9 10 11", "output": "5" }, { "input": "2\n5101 10202", "output": "2" }, { "input": "1\n99991", "output": "1" }, { "input": "2\n1009 2018", "output": "2" }, { "input": "2\n601 1202", "output": "2" }, { "input": "3\n3 14 22", "output": "2" } ]
1,595,221,400
2,147,483,647
PyPy 3
OK
TESTS
86
684
31,027,200
#iterate through numbers #find prime factorization for each number #compute max value among each prime factor #increment each by 1 from collections import defaultdict import math def primeFactors(n): prime = set() while n % 2 == 0: prime.add(2) n = n//2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: prime.add(i) n = n//i if n > 2: prime.add(n) return list(prime) n = int(input()) a = list(map(int, input().split())) l = defaultdict(int) for i in range(n): pf = primeFactors(a[i]) mx = 0 for j in pf: mx = max(mx, l[j]) for j in pf: l[j] = mx+1 mx = 1 for k,v in l.items(): mx = max(mx, v) print(mx)
Title: Good Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good. Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions: - The sequence is strictly increasing, i.e. *x**i*<=&lt;<=*x**i*<=+<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1). - No two adjacent elements are coprime, i.e. *gcd*(*x**i*,<=*x**i*<=+<=1)<=&gt;<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1) (where *gcd*(*p*,<=*q*) denotes the greatest common divisor of the integers *p* and *q*). - All elements of the sequence are good integers. Find the length of the longest good sequence. Input Specification: The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=&lt;<=*a**i*<=+<=1). Output Specification: Print a single integer — the length of the longest good sequence. Demo Input: ['5\n2 3 4 6 9\n', '9\n1 2 3 5 6 7 8 9 10\n'] Demo Output: ['4\n', '4\n'] Note: In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.
```python #iterate through numbers #find prime factorization for each number #compute max value among each prime factor #increment each by 1 from collections import defaultdict import math def primeFactors(n): prime = set() while n % 2 == 0: prime.add(2) n = n//2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: prime.add(i) n = n//i if n > 2: prime.add(n) return list(prime) n = int(input()) a = list(map(int, input().split())) l = defaultdict(int) for i in range(n): pf = primeFactors(a[i]) mx = 0 for j in pf: mx = max(mx, l[j]) for j in pf: l[j] = mx+1 mx = 1 for k,v in l.items(): mx = max(mx, v) print(mx) ```
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,678,009,922
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
93
0
n = int(input()) c = [int(l) for l in input().split()] c.sort(reverse=True) s = 0 d = 0 for i in range(n): if i % 2 == 0: s += c[i] else: d += c[i] print(s, d)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n = int(input()) c = [int(l) for l in input().split()] c.sort(reverse=True) s = 0 d = 0 for i in range(n): if i % 2 == 0: s += c[i] else: d += c[i] print(s, d) ```
0
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149", "output": "47" }, { "input": "1 1000000000\n-1000000000", "output": "2" }, { "input": "2 1000000000\n-1000000000 1000000000", "output": "3" }, { "input": "100 2\n1 3 5 6 8 9 12 13 14 17 18 21 22 23 24 25 26 27 29 30 34 35 36 39 41 44 46 48 52 53 55 56 57 59 61 63 64 66 68 69 70 71 72 73 75 76 77 79 80 81 82 87 88 91 92 93 94 95 96 97 99 100 102 103 104 106 109 110 111 112 113 114 115 117 118 119 120 122 124 125 127 128 129 130 131 132 133 134 136 137 139 140 141 142 143 145 146 148 149 150", "output": "6" }, { "input": "100 3\n0 1 3 6 7 8 9 10 13 14 16 17 18 20 21 22 24 26 27 30 33 34 35 36 37 39 42 43 44 45 46 48 53 54 55 56 57 58 61 63 64 65 67 69 70 72 73 76 77 78 79 81 82 83 85 86 87 88 90 92 93 95 96 97 98 99 100 101 104 105 108 109 110 113 114 115 116 118 120 121 123 124 125 128 130 131 132 133 134 135 136 137 139 140 141 142 146 147 148 150", "output": "2" }, { "input": "1 1000000000\n1000000000", "output": "2" }, { "input": "10 2\n-93 -62 -53 -42 -38 11 57 58 87 94", "output": "17" }, { "input": "2 500000000\n-1000000000 1000000000", "output": "4" }, { "input": "100 10\n-489 -476 -445 -432 -430 -421 -420 -418 -412 -411 -404 -383 -356 -300 -295 -293 -287 -276 -265 -263 -258 -251 -249 -246 -220 -219 -205 -186 -166 -157 -143 -137 -136 -130 -103 -86 -80 -69 -67 -55 -43 -41 -40 -26 -19 -9 16 29 41 42 54 76 84 97 98 99 101 115 134 151 157 167 169 185 197 204 208 226 227 232 234 249 259 266 281 282 293 298 300 306 308 313 319 328 331 340 341 344 356 362 366 380 390 399 409 411 419 444 455 498", "output": "23" }, { "input": "1 1000000000\n999999999", "output": "2" }, { "input": "1 1\n-5", "output": "2" }, { "input": "2 1\n-1000000000 1000000000", "output": "4" }, { "input": "1 2\n1", "output": "2" }, { "input": "4 5\n0 20 40 60", "output": "8" }, { "input": "1 1\n-10", "output": "2" }, { "input": "1 1\n-1000000000", "output": "2" }, { "input": "1 1000000000\n0", "output": "2" }, { "input": "1 2\n-10", "output": "2" }, { "input": "1 1\n2", "output": "2" }, { "input": "1 5\n-100", "output": "2" }, { "input": "2 1000000000\n999999999 1000000000", "output": "2" }, { "input": "2 2\n0 5", "output": "4" }, { "input": "1 2\n-5", "output": "2" }, { "input": "1 1\n1", "output": "2" }, { "input": "1 5\n-20", "output": "2" }, { "input": "2 100000000\n-1000000000 1000000000", "output": "4" }, { "input": "1 1000000000\n147483641", "output": "2" }, { "input": "3 3\n1 8 9", "output": "4" }, { "input": "2 1\n1 1000000000", "output": "4" }, { "input": "1 2\n-4", "output": "2" }, { "input": "2 1\n-1000000000 -1", "output": "4" } ]
1,532,144,754
2,147,483,647
Python 3
OK
TESTS
45
124
0
n,d=map(int,input().split()) a=list(map(int,input().split())) ans=2 for i in range(n-1): z=a[i+1]-a[i] if z>2*d: ans+=2 else: if z==2*d: ans+=1 print(ans)
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. Input Specification: The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. Output Specification: Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. Demo Input: ['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n'] Demo Output: ['6\n', '5\n'] Note: In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
```python n,d=map(int,input().split()) a=list(map(int,input().split())) ans=2 for i in range(n-1): z=a[i+1]-a[i] if z>2*d: ans+=2 else: if z==2*d: ans+=1 print(ans) ```
3
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball. Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.). Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball?
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n0", "output": "1" }, { "input": "2\n0", "output": "1" }, { "input": "2\n1", "output": "2" }, { "input": "4\n0", "output": "2" }, { "input": "4\n1", "output": "0" }, { "input": "5\n0", "output": "0" }, { "input": "5\n1", "output": "2" }, { "input": "5\n2", "output": "1" }, { "input": "6\n0", "output": "0" }, { "input": "6\n1", "output": "1" }, { "input": "6\n2", "output": "2" }, { "input": "7\n0", "output": "1" }, { "input": "7\n1", "output": "0" }, { "input": "7\n2", "output": "2" }, { "input": "100000\n0", "output": "2" }, { "input": "100000\n1", "output": "0" }, { "input": "100000\n2", "output": "1" }, { "input": "99999\n1", "output": "1" }, { "input": "99998\n1", "output": "2" }, { "input": "99997\n1", "output": "0" }, { "input": "99996\n1", "output": "1" }, { "input": "99995\n1", "output": "2" }, { "input": "1999999995\n0", "output": "2" }, { "input": "1999999995\n1", "output": "1" }, { "input": "1999999995\n2", "output": "0" }, { "input": "1999999996\n0", "output": "2" }, { "input": "1999999996\n1", "output": "0" }, { "input": "1999999996\n2", "output": "1" }, { "input": "1999999997\n0", "output": "0" }, { "input": "1999999997\n1", "output": "2" }, { "input": "1999999997\n2", "output": "1" }, { "input": "1999999998\n0", "output": "0" }, { "input": "1999999998\n1", "output": "1" }, { "input": "1999999998\n2", "output": "2" }, { "input": "1999999999\n0", "output": "1" }, { "input": "1999999999\n1", "output": "0" }, { "input": "1999999999\n2", "output": "2" }, { "input": "2000000000\n1", "output": "2" }, { "input": "2000000000\n2", "output": "0" }, { "input": "1234567890\n0", "output": "0" }, { "input": "1234567890\n1", "output": "1" }, { "input": "1234567890\n2", "output": "2" }, { "input": "123456789\n0", "output": "2" }, { "input": "123456789\n1", "output": "1" }, { "input": "123456789\n2", "output": "0" }, { "input": "123456790\n0", "output": "2" }, { "input": "12\n2", "output": "2" }, { "input": "32\n1", "output": "2" }, { "input": "20\n2", "output": "0" }, { "input": "10\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "76994383\n1", "output": "0" }, { "input": "25\n2", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "12\n0", "output": "0" }, { "input": "150\n2", "output": "2" }, { "input": "15\n0", "output": "2" }, { "input": "21\n2", "output": "0" }, { "input": "18\n2", "output": "2" }, { "input": "8\n2", "output": "0" }, { "input": "10\n0", "output": "2" }, { "input": "16\n0", "output": "2" } ]
1,613,320,862
4,262
PyPy 3
OK
TESTS
68
109
0
n = int(input()) x = int(input()) a = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]] print(a[n % 6][x])
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball. Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.). Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball? Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. Output Specification: Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. Demo Input: ['4\n2\n', '1\n1\n'] Demo Output: ['1\n', '0\n'] Note: In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
```python n = int(input()) x = int(input()) a = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]] print(a[n % 6][x]) ```
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,493,284,239
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
4,608,000
import sys [_, k, *nums] = (int(x) for x in sys.stdin.read().split()) smallest = min(nums) steps = 0 for num in nums: dist = num - smallest if dist % k != 0: steps = -1 break steps += dist / k print(str(steps), end='')
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 import sys [_, k, *nums] = (int(x) for x in sys.stdin.read().split()) smallest = min(nums) steps = 0 for num in nums: dist = num - smallest if dist % k != 0: steps = -1 break steps += dist / k print(str(steps), end='') ```
0
658
A
Bear and Reverse Radewoosh
PROGRAMMING
800
[ "implementation" ]
null
null
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by difficulty — it's guaranteed that *p**i*<=&lt;<=*p**i*<=+<=1 and *t**i*<=&lt;<=*t**i*<=+<=1. A constant *c* is given too, representing the speed of loosing points. Then, submitting the *i*-th problem at time *x* (*x* minutes after the start of the contest) gives *max*(0,<= *p**i*<=-<=*c*·*x*) points. Limak is going to solve problems in order 1,<=2,<=...,<=*n* (sorted increasingly by *p**i*). Radewoosh is going to solve them in order *n*,<=*n*<=-<=1,<=...,<=1 (sorted decreasingly by *p**i*). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie. You may assume that the duration of the competition is greater or equal than the sum of all *t**i*. That means both Limak and Radewoosh will accept all *n* problems.
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1) — initial scores. The third line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000,<=*t**i*<=&lt;<=*t**i*<=+<=1) where *t**i* denotes the number of minutes one needs to solve the *i*-th problem.
Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.
[ "3 2\n50 85 250\n10 15 25\n", "3 6\n50 85 250\n10 15 25\n", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n" ]
[ "Limak\n", "Radewoosh\n", "Tie\n" ]
In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. 1. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points. Radewoosh solves problem in the reversed order: 1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. 1. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. 1. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets *max*(0, 50 - 2·50) = *max*(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins. In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway. In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.
500
[ { "input": "3 2\n50 85 250\n10 15 25", "output": "Limak" }, { "input": "3 6\n50 85 250\n10 15 25", "output": "Radewoosh" }, { "input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76", "output": "Tie" }, { "input": "4 1\n3 5 6 9\n1 2 4 8", "output": "Limak" }, { "input": "4 1\n1 3 6 10\n1 5 7 8", "output": "Radewoosh" }, { "input": "4 1\n2 4 5 10\n2 3 9 10", "output": "Tie" }, { "input": "18 4\n68 97 121 132 146 277 312 395 407 431 458 461 595 634 751 855 871 994\n1 2 3 4 9 10 13 21 22 29 31 34 37 38 39 41 48 49", "output": "Radewoosh" }, { "input": "50 1\n5 14 18 73 137 187 195 197 212 226 235 251 262 278 287 304 310 322 342 379 393 420 442 444 448 472 483 485 508 515 517 523 559 585 618 627 636 646 666 682 703 707 780 853 937 951 959 989 991 992\n30 84 113 173 199 220 235 261 266 277 300 306 310 312 347 356 394 396 397 409 414 424 446 462 468 487 507 517 537 566 594 643 656 660 662 668 706 708 773 774 779 805 820 827 868 896 929 942 961 995", "output": "Tie" }, { "input": "4 1\n4 6 9 10\n2 3 4 5", "output": "Radewoosh" }, { "input": "4 1\n4 6 9 10\n3 4 5 7", "output": "Radewoosh" }, { "input": "4 1\n1 6 7 10\n2 7 8 10", "output": "Tie" }, { "input": "4 1\n4 5 7 9\n1 4 5 8", "output": "Limak" }, { "input": "50 1\n6 17 44 82 94 127 134 156 187 211 212 252 256 292 294 303 352 355 379 380 398 409 424 434 480 524 584 594 631 714 745 756 777 778 789 793 799 821 841 849 859 878 879 895 925 932 944 952 958 990\n15 16 40 42 45 71 99 100 117 120 174 181 186 204 221 268 289 332 376 394 403 409 411 444 471 487 499 539 541 551 567 589 619 623 639 669 689 722 735 776 794 822 830 840 847 907 917 927 936 988", "output": "Radewoosh" }, { "input": "50 10\n25 49 52 73 104 117 127 136 149 164 171 184 226 251 257 258 286 324 337 341 386 390 428 453 464 470 492 517 543 565 609 634 636 660 678 693 710 714 729 736 739 749 781 836 866 875 956 960 977 979\n2 4 7 10 11 22 24 26 27 28 31 35 37 38 42 44 45 46 52 53 55 56 57 59 60 61 64 66 67 68 69 71 75 76 77 78 79 81 83 85 86 87 89 90 92 93 94 98 99 100", "output": "Limak" }, { "input": "50 10\n11 15 25 71 77 83 95 108 143 150 182 183 198 203 213 223 279 280 346 348 350 355 375 376 412 413 415 432 470 545 553 562 589 595 607 633 635 637 688 719 747 767 771 799 842 883 905 924 942 944\n1 3 5 6 7 10 11 12 13 14 15 16 19 20 21 23 25 32 35 36 37 38 40 41 42 43 47 50 51 54 55 56 57 58 59 60 62 63 64 65 66 68 69 70 71 72 73 75 78 80", "output": "Radewoosh" }, { "input": "32 6\n25 77 141 148 157 159 192 196 198 244 245 255 332 392 414 457 466 524 575 603 629 700 738 782 838 841 845 847 870 945 984 985\n1 2 4 5 8 9 10 12 13 14 15 16 17 18 20 21 22 23 24 26 28 31 38 39 40 41 42 43 45 47 48 49", "output": "Radewoosh" }, { "input": "5 1\n256 275 469 671 842\n7 9 14 17 26", "output": "Limak" }, { "input": "2 1000\n1 2\n1 2", "output": "Tie" }, { "input": "3 1\n1 50 809\n2 8 800", "output": "Limak" }, { "input": "1 13\n866\n10", "output": "Tie" }, { "input": "15 1\n9 11 66 128 199 323 376 386 393 555 585 718 935 960 971\n3 11 14 19 20 21 24 26 32 38 40 42 44 47 50", "output": "Limak" }, { "input": "1 10\n546\n45", "output": "Tie" }, { "input": "50 20\n21 43 51 99 117 119 158 167 175 190 196 244 250 316 335 375 391 403 423 428 451 457 460 480 487 522 539 559 566 584 598 602 604 616 626 666 675 730 771 787 828 841 861 867 886 889 898 970 986 991\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", "output": "Limak" }, { "input": "50 21\n13 20 22 38 62 84 118 135 141 152 170 175 194 218 227 229 232 253 260 263 278 313 329 357 396 402 422 452 454 533 575 576 580 594 624 644 653 671 676 759 789 811 816 823 831 833 856 924 933 987\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", "output": "Tie" }, { "input": "1 36\n312\n42", "output": "Tie" }, { "input": "1 1000\n1\n1000", "output": "Tie" }, { "input": "1 1\n1000\n1", "output": "Tie" }, { "input": "50 35\n9 17 28 107 136 152 169 174 186 188 201 262 291 312 324 330 341 358 385 386 393 397 425 431 479 498 502 523 530 540 542 554 578 588 622 623 684 696 709 722 784 819 836 845 850 932 945 969 983 984\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", "output": "Tie" }, { "input": "50 20\n12 113 116 120 138 156 167 183 185 194 211 228 234 261 278 287 310 317 346 361 364 397 424 470 496 522 527 536 611 648 668 704 707 712 717 752 761 766 815 828 832 864 872 885 889 901 904 929 982 993\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", "output": "Limak" } ]
1,606,064,525
2,147,483,647
Python 3
OK
TESTS
29
109
307,200
# https://codeforces.com/problemset/problem/658/A n, c = map(int, input().split()) p = tuple(map(int, input().split())) t = list(map(int, input().split())) limak_t = 0 radewoosh_t = 0 limak = 0 radewoosh = 0 for i in range(n): limak_t += t[i] radewoosh_t += t[n - i - 1] limak += max(0, p[i] - c * limak_t) radewoosh += max(0, p[n - i - 1] - c * radewoosh_t) if limak > radewoosh: print("Limak") elif limak < radewoosh: print("Radewoosh") else: print("Tie")
Title: Bear and Reverse Radewoosh Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by difficulty — it's guaranteed that *p**i*<=&lt;<=*p**i*<=+<=1 and *t**i*<=&lt;<=*t**i*<=+<=1. A constant *c* is given too, representing the speed of loosing points. Then, submitting the *i*-th problem at time *x* (*x* minutes after the start of the contest) gives *max*(0,<= *p**i*<=-<=*c*·*x*) points. Limak is going to solve problems in order 1,<=2,<=...,<=*n* (sorted increasingly by *p**i*). Radewoosh is going to solve them in order *n*,<=*n*<=-<=1,<=...,<=1 (sorted decreasingly by *p**i*). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie. You may assume that the duration of the competition is greater or equal than the sum of all *t**i*. That means both Limak and Radewoosh will accept all *n* problems. Input Specification: The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=&lt;<=*p**i*<=+<=1) — initial scores. The third line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000,<=*t**i*<=&lt;<=*t**i*<=+<=1) where *t**i* denotes the number of minutes one needs to solve the *i*-th problem. Output Specification: Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. Demo Input: ['3 2\n50 85 250\n10 15 25\n', '3 6\n50 85 250\n10 15 25\n', '8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n'] Demo Output: ['Limak\n', 'Radewoosh\n', 'Tie\n'] Note: In the first sample, there are 3 problems. Limak solves them as follows: 1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. 1. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points. Radewoosh solves problem in the reversed order: 1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. 1. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. 1. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets *max*(0, 50 - 2·50) = *max*(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins. In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway. In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.
```python # https://codeforces.com/problemset/problem/658/A n, c = map(int, input().split()) p = tuple(map(int, input().split())) t = list(map(int, input().split())) limak_t = 0 radewoosh_t = 0 limak = 0 radewoosh = 0 for i in range(n): limak_t += t[i] radewoosh_t += t[n - i - 1] limak += max(0, p[i] - c * limak_t) radewoosh += max(0, p[n - i - 1] - c * radewoosh_t) if limak > radewoosh: print("Limak") elif limak < radewoosh: print("Radewoosh") else: print("Tie") ```
3
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day.
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "12" }, { "input": "1 1\n86399", "output": "1" }, { "input": "6 1200\n86400 86400 86000 86000 86000 86400", "output": "5" }, { "input": "6 1200\n86400 86400 86000 86000 86001 86399", "output": "6" }, { "input": "4 172799\n1 1 86400 0", "output": "4" }, { "input": "4 172799\n0 86400 86399 0", "output": "4" }, { "input": "6 1\n1 1 86400 1 86399 1", "output": "1" }, { "input": "4 1\n86400 86399 86400 86400", "output": "2" }, { "input": "4 1\n86400 86400 0 86400", "output": "3" } ]
1,585,404,679
2,147,483,647
Python 3
OK
TESTS
16
109
0
i=lambda:map(int,input().split()) _,d=i();r=0 for x in i(): r+=1 d-=86400-x if d<1:break print(r)
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. Output Specification: Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*. Demo Input: ['2 2\n86400 86398\n', '2 86400\n0 86400\n'] Demo Output: ['2\n', '1\n'] Note: none
```python i=lambda:map(int,input().split()) _,d=i();r=0 for x in i(): r+=1 d-=86400-x if d<1:break print(r) ```
3
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,697,993,243
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
t = int(input()) for _ in range(t): a = int(input()) found = False for n in range(3, 181): angle = (n - 2) * 180 / n if abs(angle - a) < 1e-9: # Comparing angles with a small epsilon for floating-point precision found = True break if found: print("YES") else: print("NO")
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? Input Specification: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. Output Specification: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Demo Input: ['3\n30\n60\n90\n'] Demo Output: ['NO\nYES\nYES\n'] Note: In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
```python t = int(input()) for _ in range(t): a = int(input()) found = False for n in range(3, 181): angle = (n - 2) * 180 / n if abs(angle - a) < 1e-9: # Comparing angles with a small epsilon for floating-point precision found = True break if found: print("YES") else: print("NO") ```
0
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,681,253,734
2,147,483,647
PyPy 3-64
OK
TESTS
33
62
1,331,200
n = int(input()) l = [] def is_prime(n): is_prime = True for i in range(2,n): if n%i == 0: is_prime = False return is_prime for i in range(2,n-1): if not is_prime(i): if not is_prime(n-i): l.append(i) l.append(n-i) break print(*l, sep = ' ')
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python n = int(input()) l = [] def is_prime(n): is_prime = True for i in range(2,n): if n%i == 0: is_prime = False return is_prime for i in range(2,n-1): if not is_prime(i): if not is_prime(n-i): l.append(i) l.append(n-i) break print(*l, sep = ' ') ```
3
625
A
Guest From the Past
PROGRAMMING
1,700
[ "implementation", "math" ]
null
null
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=&lt;<=*b*) rubles back, but you cannot return plastic bottles. Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning. Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=&lt;<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
[ "10\n11\n9\n8\n", "10\n5\n6\n1\n" ]
[ "2\n", "2\n" ]
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir. In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.
750
[ { "input": "10\n11\n9\n8", "output": "2" }, { "input": "10\n5\n6\n1", "output": "2" }, { "input": "2\n2\n2\n1", "output": "1" }, { "input": "10\n3\n3\n1", "output": "4" }, { "input": "10\n1\n2\n1", "output": "10" }, { "input": "10\n2\n3\n1", "output": "5" }, { "input": "9\n2\n4\n1", "output": "4" }, { "input": "9\n2\n2\n1", "output": "8" }, { "input": "9\n10\n10\n1", "output": "0" }, { "input": "10\n2\n2\n1", "output": "9" }, { "input": "1000000000000000000\n2\n10\n9", "output": "999999999999999995" }, { "input": "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000", "output": "2" }, { "input": "10\n1\n9\n8", "output": "10" }, { "input": "10\n8\n8\n7", "output": "3" }, { "input": "10\n5\n5\n1", "output": "2" }, { "input": "29\n3\n3\n1", "output": "14" }, { "input": "45\n9\n9\n8", "output": "37" }, { "input": "45\n9\n9\n1", "output": "5" }, { "input": "100\n10\n10\n9", "output": "91" }, { "input": "179\n10\n9\n1", "output": "22" }, { "input": "179\n2\n2\n1", "output": "178" }, { "input": "179\n179\n179\n1", "output": "1" }, { "input": "179\n59\n59\n58", "output": "121" }, { "input": "500\n250\n250\n1", "output": "2" }, { "input": "500\n1\n250\n1", "output": "500" }, { "input": "501\n500\n500\n499", "output": "2" }, { "input": "501\n450\n52\n1", "output": "9" }, { "input": "501\n300\n301\n100", "output": "2" }, { "input": "500\n179\n10\n1", "output": "55" }, { "input": "1000\n500\n10\n9", "output": "991" }, { "input": "1000\n2\n10\n9", "output": "995" }, { "input": "1001\n1000\n1000\n999", "output": "2" }, { "input": "10000\n10000\n10000\n1", "output": "1" }, { "input": "10000\n10\n5000\n4999", "output": "5500" }, { "input": "1000000000\n999999998\n999999999\n999999998", "output": "3" }, { "input": "1000000000\n50\n50\n49", "output": "999999951" }, { "input": "1000000000\n500\n5000\n4999", "output": "999995010" }, { "input": "1000000000\n51\n100\n98", "output": "499999952" }, { "input": "1000000000\n100\n51\n50", "output": "999999950" }, { "input": "1000000000\n2\n5\n4", "output": "999999998" }, { "input": "1000000000000000000\n999999998000000000\n999999999000000000\n999999998000000000", "output": "3" }, { "input": "1000000000\n2\n2\n1", "output": "999999999" }, { "input": "999999999\n2\n999999998\n1", "output": "499999999" }, { "input": "999999999999999999\n2\n2\n1", "output": "999999999999999998" }, { "input": "999999999999999999\n10\n10\n9", "output": "999999999999999990" }, { "input": "999999999999999999\n999999999999999998\n999999999999999998\n999999999999999997", "output": "2" }, { "input": "999999999999999999\n501\n501\n1", "output": "1999999999999999" }, { "input": "999999999999999999\n2\n50000000000000000\n49999999999999999", "output": "974999999999999999" }, { "input": "999999999999999999\n180\n180\n1", "output": "5586592178770949" }, { "input": "1000000000000000000\n42\n41\n1", "output": "24999999999999999" }, { "input": "1000000000000000000\n41\n40\n1", "output": "25641025641025641" }, { "input": "100000000000000000\n79\n100\n25", "output": "1333333333333333" }, { "input": "1\n100\n5\n4", "output": "0" }, { "input": "1000000000000000000\n1000000000000000000\n10000000\n9999999", "output": "999999999990000001" }, { "input": "999999999999999999\n999999999000000000\n900000000000000000\n899999999999999999", "output": "100000000000000000" }, { "input": "13\n10\n15\n11", "output": "1" }, { "input": "1\n1000\n5\n4", "output": "0" }, { "input": "10\n100\n10\n1", "output": "1" }, { "input": "3\n2\n100000\n99999", "output": "1" }, { "input": "4\n2\n4\n2", "output": "2" }, { "input": "5\n3\n6\n4", "output": "1" }, { "input": "1\n7\n65\n49", "output": "0" }, { "input": "10\n20\n100\n99", "output": "0" }, { "input": "10000000000\n10000000000\n9000000000\n8999999999", "output": "1000000001" }, { "input": "90\n30\n101\n100", "output": "3" }, { "input": "999999999999999\n5\n500000000000000\n499999999999999", "output": "599999999999999" }, { "input": "1000000000000000000\n1000000000000000000\n1000000000\n999999999", "output": "999999999000000001" }, { "input": "1\n1000000000000000000\n1000000000\n999999999", "output": "0" }, { "input": "100000000000000000\n100000000000000000\n1000000000\n999999999", "output": "99999999000000001" }, { "input": "100000000000000009\n100\n1000000000000000\n999999999999999", "output": "99010000000000009" }, { "input": "10\n20\n10\n9", "output": "1" }, { "input": "10\n4\n14\n13", "output": "2" }, { "input": "11\n3\n9\n7", "output": "4" }, { "input": "1000000000\n5\n7\n4", "output": "333333332" }, { "input": "12155\n1943\n28717\n24074", "output": "6" }, { "input": "1000000000000000000\n10\n20\n5", "output": "100000000000000000" }, { "input": "98\n33\n440\n314", "output": "2" }, { "input": "1070252292\n57449678\n237309920\n221182550", "output": "56" }, { "input": "100\n3\n102\n101", "output": "33" }, { "input": "100000000000000000\n100000000000000001\n1000000000000000\n999999999999999", "output": "99000000000000001" }, { "input": "66249876257975628\n302307316\n406102416\n182373516", "output": "296116756" }, { "input": "10\n5\n10\n1", "output": "2" }, { "input": "1000000000000000000\n10\n1000000000\n999999998", "output": "499999999600000000" } ]
1,696,692,798
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n = int(input()) a = int(input()) b = int(input()) c = int(input()) # Calculate the maximum number of glass bottles Kolya can buy with the initial money max_glass_bottles = n // b # Calculate the maximum number of plastic bottles Kolya can buy with the initial money max_plastic_bottles = n // a # Calculate the maximum number of glass bottles Kolya can buy with the refunded money max_glass_with_refund = (n % b + c) // (b - c) # Calculate the maximum number of kefir liters Kolya can drink using glass bottles max_kefir_glass = max_glass_bottles * b # Calculate the maximum number of kefir liters Kolya can drink using plastic bottles max_kefir_plastic = max_plastic_bottles * a # Calculate the maximum number of kefir liters Kolya can drink using glass bottles with refund max_kefir_refund = max_glass_with_refund * b # Find the maximum of the three possibilities max_kefir_liters = max(max_kefir_glass, max_kefir_plastic, max_kefir_refund) # Output the result print(max_kefir_liters)
Title: Guest From the Past Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=&lt;<=*b*) rubles back, but you cannot return plastic bottles. Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help. Input Specification: First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning. Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=&lt;<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively. Output Specification: Print the only integer — maximum number of liters of kefir, that Kolya can drink. Demo Input: ['10\n11\n9\n8\n', '10\n5\n6\n1\n'] Demo Output: ['2\n', '2\n'] Note: In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir. In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.
```python n = int(input()) a = int(input()) b = int(input()) c = int(input()) # Calculate the maximum number of glass bottles Kolya can buy with the initial money max_glass_bottles = n // b # Calculate the maximum number of plastic bottles Kolya can buy with the initial money max_plastic_bottles = n // a # Calculate the maximum number of glass bottles Kolya can buy with the refunded money max_glass_with_refund = (n % b + c) // (b - c) # Calculate the maximum number of kefir liters Kolya can drink using glass bottles max_kefir_glass = max_glass_bottles * b # Calculate the maximum number of kefir liters Kolya can drink using plastic bottles max_kefir_plastic = max_plastic_bottles * a # Calculate the maximum number of kefir liters Kolya can drink using glass bottles with refund max_kefir_refund = max_glass_with_refund * b # Find the maximum of the three possibilities max_kefir_liters = max(max_kefir_glass, max_kefir_plastic, max_kefir_refund) # Output the result print(max_kefir_liters) ```
0
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,563,721,458
2,147,483,647
Python 3
OK
TESTS
102
202
0
a=str(input()) b=str(input()) c="" for i in range(0, len(a)): if a[i]==b[i]: c+="0" else: c+="1" for i in range(0, len(c)): print(c[i], end="")
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 a=str(input()) b=str(input()) c="" for i in range(0, len(a)): if a[i]==b[i]: c+="0" else: c+="1" for i in range(0, len(c)): print(c[i], end="") ```
3.9495
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "/a//aa/a//", "output": "/a/aa/a" }, { "input": "/aa//b/aa", "output": "/aa/b/aa" }, { "input": "////////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/" }, { "input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb" }, { "input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt" }, { "input": "///a//a////a/a//a//a//a/////", "output": "/a/a/a/a/a/a/a" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a" }, { "input": "///////////////////////////////////////////////////////////////////////////////////////////////////z", "output": "/z" }, { "input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/z" } ]
1,612,377,663
2,147,483,647
Python 3
OK
TESTS
19
154
819,200
#***************20A - BerOS file system***************# #author - @Divyesh Chhabra from math import * import os import random import re import sys from itertools import * path = input() new = re.split("/",path) new_path = "" for i in new: if i == "": continue new_path += (i+"/") new_path = new_path[:-1] print("/"+new_path)
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input Specification: The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output Specification: The path in normalized form. Demo Input: ['//usr///local//nginx/sbin\n'] Demo Output: ['/usr/local/nginx/sbin\n'] Note: none
```python #***************20A - BerOS file system***************# #author - @Divyesh Chhabra from math import * import os import random import re import sys from itertools import * path = input() new = re.split("/",path) new_path = "" for i in new: if i == "": continue new_path += (i+"/") new_path = new_path[:-1] print("/"+new_path) ```
3.955396
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,697,883,343
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
30
0
n = int(input()) if n >= 0: print(n) else: num1 = [] num2 = [] num11 = "" num22 = "" for x in str(n): num1.append(x) num2.append(x) num1.remove(num1[len(num1)-1]) num1.remove(num1[len(num1)-2]) print(num1) print(num2)
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python n = int(input()) if n >= 0: print(n) else: num1 = [] num2 = [] num11 = "" num22 = "" for x in str(n): num1.append(x) num2.append(x) num1.remove(num1[len(num1)-1]) num1.remove(num1[len(num1)-2]) print(num1) print(num2) ```
-1
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "6 0\n10\n102\n120\n1032\n1212103\n1999999", "output": "5" }, { "input": "1 3\n1000000000", "output": "0" }, { "input": "1 9\n1000000000", "output": "0" }, { "input": "1 0\n1", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 3\n1", "output": "0" }, { "input": "1 9\n1", "output": "0" }, { "input": "2 8\n123456780\n123", "output": "1" }, { "input": "2 8\n12345678\n1230", "output": "0" }, { "input": "6 1\n10\n102\n120\n1032\n1212103\n1999999", "output": "5" }, { "input": "6 2\n10\n102\n120\n1032\n1212103\n1999999", "output": "4" }, { "input": "6 3\n10\n102\n120\n1032\n1212103\n1999999", "output": "2" }, { "input": "6 9\n10\n102\n120\n1032\n1212103\n1999999", "output": "0" }, { "input": "1 2\n2220", "output": "0" } ]
1,648,318,879
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
n,k=map(int,input().split(" ")) con=0 l=[] flag=False for i in range(n): x=list(map(int,input())) z=max(x) for j in range(len(x)): if (x[j]<=k and min(x)==0): flag=True if flag==True: con+=1 print(con)
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). Input Specification: The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the number of *k*-good numbers in *a*. Demo Input: ['10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n', '2 1\n1\n10\n'] Demo Output: ['10\n', '1\n'] Note: none
```python n,k=map(int,input().split(" ")) con=0 l=[] flag=False for i in range(n): x=list(map(int,input())) z=max(x) for j in range(len(x)): if (x[j]<=k and min(x)==0): flag=True if flag==True: con+=1 print(con) ```
0
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "output": "16" }, { "input": "10\n2 3 0 1 3 1 2 2 1 0", "output": "3" }, { "input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3", "output": "6" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1 3", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n3 3", "output": "0" }, { "input": "3\n3 3 3", "output": "0" }, { "input": "2\n3 2", "output": "0" }, { "input": "2\n0 2", "output": "1" }, { "input": "10\n2 2 3 3 3 3 2 1 3 2", "output": "2" }, { "input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0", "output": "11" }, { "input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1", "output": "4" }, { "input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2", "output": "3" }, { "input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0", "output": "12" }, { "input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3", "output": "5" }, { "input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2", "output": "4" }, { "input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1", "output": "16" }, { "input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3", "output": "5" }, { "input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3", "output": "3" }, { "input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0", "output": "22" }, { "input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2", "output": "9" }, { "input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3", "output": "2" }, { "input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0", "output": "21" }, { "input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2", "output": "11" }, { "input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2", "output": "7" }, { "input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0", "output": "28" }, { "input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1", "output": "10" }, { "input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3", "output": "8" }, { "input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2", "output": "29" }, { "input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3", "output": "8" }, { "input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0", "output": "32" }, { "input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2", "output": "16" }, { "input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3", "output": "7" }, { "input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0", "output": "40" }, { "input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2", "output": "13" }, { "input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3", "output": "7" }, { "input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0", "output": "44" }, { "input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2", "output": "15" }, { "input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3", "output": "8" }, { "input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1", "output": "35" }, { "input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3", "output": "13" }, { "input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3", "output": "6" }, { "input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1", "output": "43" }, { "input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1", "output": "16" }, { "input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1", "output": "10" }, { "input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0", "output": "51" }, { "input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1", "output": "16" }, { "input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1", "output": "11" }, { "input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1", "output": "56" }, { "input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0", "output": "17" }, { "input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3", "output": "9" }, { "input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0", "output": "54" }, { "input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3", "output": "19" }, { "input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3", "output": "9" }, { "input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1", "output": "57" }, { "input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1", "output": "17" }, { "input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2", "output": "9" }, { "input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1", "output": "61" }, { "input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2", "output": "15" }, { "input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2", "output": "14" }, { "input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2", "output": "63" }, { "input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3", "output": "15" }, { "input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2", "output": "0" }, { "input": "100\n3 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 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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "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 1", "output": "50" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "50" }, { "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 1", "output": "49" }, { "input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "2\n0 3", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n2 0", "output": "1" }, { "input": "2\n2 1", "output": "0" }, { "input": "2\n2 3", "output": "0" }, { "input": "2\n3 0", "output": "1" }, { "input": "2\n3 1", "output": "0" }, { "input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0", "output": "50" } ]
1,645,038,430
2,147,483,647
Python 3
OK
TESTS
88
62
0
n = int(input()) a = list(map(int, input().split())) lp, ls, lo = [0, 1], [0, 1], 0 for i in range(n): if a[i] == 0: lo = max(lo, lp[0]*lp[1], ls[0]*ls[1]) ls[1], lp[1] = 0, 0 elif a[i] == 1: lo, lp = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, ls[0] * ls[1]), 1] ls[1], lp[1] = 0, 1 elif a[i] == 2: lo, ls = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, lp[0] * lp[1]), 1] ls[1], lp[1] = 1, 0 else: lo, ls, lp = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, lp[0] * lp[1]), 1], [1 + max(lo, ls[0] * ls[1]), 1] ls[1], lp[1] = 1, 1 print(n-max(lo, ls[0], lp[0]))
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Output Specification: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Demo Input: ['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
```python n = int(input()) a = list(map(int, input().split())) lp, ls, lo = [0, 1], [0, 1], 0 for i in range(n): if a[i] == 0: lo = max(lo, lp[0]*lp[1], ls[0]*ls[1]) ls[1], lp[1] = 0, 0 elif a[i] == 1: lo, lp = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, ls[0] * ls[1]), 1] ls[1], lp[1] = 0, 1 elif a[i] == 2: lo, ls = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, lp[0] * lp[1]), 1] ls[1], lp[1] = 1, 0 else: lo, ls, lp = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, lp[0] * lp[1]), 1], [1 + max(lo, ls[0] * ls[1]), 1] ls[1], lp[1] = 1, 1 print(n-max(lo, ls[0], lp[0])) ```
3
808
C
Tea Party
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that: - Every cup will contain tea for at least half of its volume - Every cup will contain integer number of milliliters of tea - All the tea from the teapot will be poured into cups - All friends will be satisfied. Friend with cup *i* won't be satisfied, if there exists such cup *j* that cup *i* contains less tea than cup *j* but *a**i*<=&gt;<=*a**j*. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.
The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1.
[ "2 10\n8 7\n", "4 4\n1 1 1 1\n", "3 10\n9 8 10\n" ]
[ "6 4 \n", "1 1 1 1 \n", "-1\n" ]
In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
0
[ { "input": "2 10\n8 7", "output": "6 4 " }, { "input": "4 4\n1 1 1 1", "output": "1 1 1 1 " }, { "input": "3 10\n9 8 10", "output": "-1" }, { "input": "1 1\n1", "output": "1 " }, { "input": "1 1\n2", "output": "1 " }, { "input": "1 10\n20", "output": "10 " }, { "input": "3 10\n8 4 8", "output": "4 2 4 " }, { "input": "3 100\n37 26 37", "output": "37 26 37 " }, { "input": "3 60\n43 23 24", "output": "36 12 12 " }, { "input": "20 14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 8\n1 2 1 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2", "output": "-1" }, { "input": "50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39 45 31 10 12 48 2 19 37 47 45 30 24 21 42 36 14 31 30 31 50 6 3 33 49", "output": "13 11 12 37 28 12 10 18 3 6 2 6 46 50 7 50 4 1 4 40 2 3 34 27 6 39 45 31 5 6 48 1 10 37 47 45 30 12 11 42 36 7 31 30 31 50 3 2 33 49 " }, { "input": "50 440\n14 69 33 38 83 65 21 66 89 3 93 60 31 16 61 20 42 64 13 1 50 50 74 58 67 61 52 22 69 68 18 33 28 59 4 8 96 32 84 85 87 87 61 89 2 47 15 64 88 18", "output": "-1" }, { "input": "100 640\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91", "output": "-1" }, { "input": "100 82\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": "-1" }, { "input": "100 55\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1", "output": "-1" }, { "input": "30 50\n3 1 2 4 1 2 2 4 3 4 4 3 3 3 3 5 3 2 5 4 3 3 5 3 3 5 4 5 3 5", "output": "-1" }, { "input": "40 100\n3 3 3 3 4 1 1 1 1 1 2 2 1 3 1 2 3 2 1 2 2 2 1 4 2 2 3 3 3 2 4 6 4 4 3 2 2 2 4 5", "output": "3 3 3 3 4 1 1 1 1 1 2 2 1 3 1 2 3 2 1 2 2 2 1 4 2 2 3 3 3 2 4 6 4 4 3 2 2 2 4 5 " }, { "input": "100 10000\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": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 " }, { "input": "2 5\n3 4", "output": "2 3 " }, { "input": "2 6\n2 6", "output": "1 5 " }, { "input": "23 855\n5 63 94 57 38 84 77 79 83 36 47 31 60 79 75 48 88 17 46 33 23 15 27", "output": "3 32 94 29 19 84 39 72 83 18 24 16 30 79 38 24 88 9 23 17 12 8 14 " }, { "input": "52 2615\n73 78 70 92 94 74 46 19 55 20 70 3 1 42 68 10 66 80 1 31 65 19 73 74 56 35 53 38 92 35 65 81 6 98 74 51 27 49 76 19 86 76 5 60 14 75 64 99 43 7 36 79", "output": "73 78 70 92 94 74 46 10 55 10 70 2 1 42 68 5 66 80 1 16 65 10 73 74 56 18 53 38 92 30 65 81 3 98 74 51 14 49 76 10 86 76 3 60 7 75 64 99 43 4 36 79 " }, { "input": "11 287\n34 30 69 86 22 53 11 91 62 44 5", "output": "17 15 35 43 11 27 6 77 31 22 3 " }, { "input": "55 1645\n60 53 21 20 87 48 10 21 76 35 52 41 82 86 93 11 93 86 34 15 37 63 57 3 57 57 32 8 55 25 29 38 46 22 13 87 27 35 40 83 5 7 6 18 88 25 4 59 95 62 31 93 98 50 62", "output": "30 27 11 10 82 24 5 11 38 18 26 21 41 43 93 6 93 43 17 8 19 32 29 2 29 29 16 4 28 13 15 19 23 11 7 87 14 18 20 42 3 4 3 9 88 13 2 30 95 31 16 93 98 25 31 " }, { "input": "71 3512\n97 46 76 95 81 96 99 83 10 50 19 18 73 5 41 60 12 73 60 31 21 64 88 61 43 57 61 19 75 35 41 85 12 59 32 47 37 43 35 92 90 47 3 98 21 18 61 79 39 86 74 8 52 33 39 27 93 54 35 38 96 36 83 51 97 10 8 66 75 87 68", "output": "97 46 76 95 81 96 99 83 5 50 10 9 73 3 41 60 6 73 60 16 11 64 88 61 43 57 61 10 75 18 41 85 6 59 16 47 19 43 18 92 90 47 2 98 11 9 61 79 20 86 74 4 52 17 21 14 93 54 18 19 96 18 83 51 97 5 4 66 75 87 68 " }, { "input": "100 2633\n99 50 64 81 75 73 26 31 31 36 95 12 100 2 70 72 78 56 76 23 94 8 91 1 39 82 97 67 64 25 71 90 48 34 31 46 64 37 46 50 99 93 14 56 1 89 95 89 50 52 12 58 43 65 45 88 90 14 38 19 6 15 91 67 43 48 82 20 11 48 33 20 39 52 73 5 25 84 26 54 42 56 10 28 9 63 60 98 30 1 25 74 86 56 85 9 12 94 80 95", "output": "50 25 32 41 38 37 13 16 16 18 48 6 61 1 35 36 39 28 38 12 47 4 46 1 20 41 49 34 32 13 36 45 24 17 16 23 32 19 23 25 50 47 7 28 1 45 48 45 25 26 6 29 22 33 23 44 45 7 19 10 3 8 46 34 22 24 41 10 6 24 17 10 20 26 37 3 13 42 13 27 21 28 5 14 5 32 30 49 15 1 13 37 43 28 43 5 6 47 40 48 " }, { "input": "71 1899\n23 55 58 87 69 85 100 21 19 72 81 68 20 25 29 92 18 74 89 70 53 7 78 57 41 79 64 87 63 76 95 84 1 28 32 1 79 34 77 17 71 61 35 31 62 92 69 99 60 26 2 18 61 9 27 77 82 6 30 65 52 3 51 43 13 77 41 59 19 29 86", "output": "12 28 29 44 35 43 95 11 10 36 41 34 10 13 15 46 9 37 45 35 27 4 39 29 21 40 32 44 32 38 48 42 1 14 16 1 40 17 39 9 36 31 18 16 31 46 35 50 30 13 1 9 31 5 14 39 41 3 15 33 26 2 26 22 7 39 21 30 10 15 43 " }, { "input": "10 21\n3 3 3 3 4 3 3 3 3 3", "output": "2 2 2 2 3 2 2 2 2 2 " } ]
1,502,909,307
2,147,483,647
Python 3
OK
TESTS
29
62
0
cilv_sk, tejas_daudz=[int(x) for x in input().split()] s=input().split() tilpumi = [ [int(s[i]),i] for i in range(cilv_sk)] aizpildijums = [0 for i in range(cilv_sk)] for i in range(cilv_sk): cur_t = tilpumi[i][0]//2 + tilpumi[i][0]%2 aizpildijums[i] = cur_t tejas_daudz -= (cur_t) if(tejas_daudz<0): #print("Nevar!!!!") print(-1) exit(0) tilpumi.sort(key=lambda a: a[0], reverse=True) for i in range(cilv_sk): starp=tilpumi[i][0]-aizpildijums[ tilpumi[i][1] ] if(starp<tejas_daudz): aizpildijums[ tilpumi[i][1] ]+=starp tejas_daudz-=starp else: aizpildijums[ tilpumi[i][1] ]+=tejas_daudz tejas_daudz=0 break if(tejas_daudz!=0): print(-1) else: for i in aizpildijums: print(i, end=" ")
Title: Tea Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that: - Every cup will contain tea for at least half of its volume - Every cup will contain integer number of milliliters of tea - All the tea from the teapot will be poured into cups - All friends will be satisfied. Friend with cup *i* won't be satisfied, if there exists such cup *j* that cup *i* contains less tea than cup *j* but *a**i*<=&gt;<=*a**j*. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input Specification: The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Demo Input: ['2 10\n8 7\n', '4 4\n1 1 1 1\n', '3 10\n9 8 10\n'] Demo Output: ['6 4 \n', '1 1 1 1 \n', '-1\n'] Note: In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
```python cilv_sk, tejas_daudz=[int(x) for x in input().split()] s=input().split() tilpumi = [ [int(s[i]),i] for i in range(cilv_sk)] aizpildijums = [0 for i in range(cilv_sk)] for i in range(cilv_sk): cur_t = tilpumi[i][0]//2 + tilpumi[i][0]%2 aizpildijums[i] = cur_t tejas_daudz -= (cur_t) if(tejas_daudz<0): #print("Nevar!!!!") print(-1) exit(0) tilpumi.sort(key=lambda a: a[0], reverse=True) for i in range(cilv_sk): starp=tilpumi[i][0]-aizpildijums[ tilpumi[i][1] ] if(starp<tejas_daudz): aizpildijums[ tilpumi[i][1] ]+=starp tejas_daudz-=starp else: aizpildijums[ tilpumi[i][1] ]+=tejas_daudz tejas_daudz=0 break if(tejas_daudz!=0): print(-1) else: for i in aizpildijums: print(i, end=" ") ```
3
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
1,480,514,367
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
5,529,600
num = eval(input()); data = [eval(i) for i in input().split()] data = sorted(data) score = 0 for i in range(num): score += data[i] * (i + 2) print(score - data[-1])
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 num = eval(input()); data = [eval(i) for i in input().split()] data = sorted(data) score = 0 for i in range(num): score += data[i] * (i + 2) print(score - data[-1]) ```
0
514
B
Han Solo and Lazer Gun
PROGRAMMING
1,400
[ "brute force", "data structures", "geometry", "implementation", "math" ]
null
null
There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (*x*0,<=*y*0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
[ "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "2 1 2\n1 1\n1 0\n" ]
[ "2\n", "1\n" ]
Explanation to the first and second samples from the statement, respectively:
1,000
[ { "input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1", "output": "2" }, { "input": "2 1 2\n1 1\n1 0", "output": "1" }, { "input": "1 1 1\n0 0", "output": "1" }, { "input": "2 0 0\n10000 -10000\n-10000 10000", "output": "1" }, { "input": "2 0 0\n10000 -10000\n10000 10000", "output": "2" }, { "input": "10 -4 -4\n2 -4\n2 0\n-4 2\n5 -4\n-3 -5\n1 4\n-4 2\n-3 5\n0 -3\n2 4", "output": "8" }, { "input": "10 5 -3\n1 1\n2 -1\n2 2\n1 -2\n4 -5\n1 4\n0 1\n1 -4\n-2 0\n-4 -5", "output": "10" }, { "input": "10 -3 3\n3 -5\n4 3\n0 -2\n0 0\n3 -3\n3 5\n4 1\n5 5\n4 -5\n4 -4", "output": "8" }, { "input": "2 -10000 -10000\n10000 10000\n10000 9999", "output": "2" }, { "input": "2 -10000 -10000\n9998 9999\n9999 10000", "output": "2" }, { "input": "2 0 0\n0 1337\n3 9000", "output": "2" }, { "input": "2 0 -1\n0 1\n1 10000", "output": "2" }, { "input": "2 0 0\n0 10\n1 2000", "output": "2" }, { "input": "2 0 0\n0 2\n1 90", "output": "2" }, { "input": "2 0 0\n1001 0\n1001 1", "output": "2" } ]
1,680,189,359
2,147,483,647
Python 3
OK
TESTS
29
46
102,400
from collections import defaultdict n, x, y = map(int, input().split()) dic = defaultdict(int) cnt = ok = 0 while n: n -= 1 a, b = map(int, input().split()) if x == a: ok = 1 else: dic[(b - y) / (a - x)] += 1 for i in dic: cnt += dic[i] != 0 print(cnt + ok)
Title: Han Solo and Lazer Gun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (*x*0,<=*y*0). Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers. The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. Input Specification: The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. Output Specification: Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. Demo Input: ['4 0 0\n1 1\n2 2\n2 0\n-1 -1\n', '2 1 2\n1 1\n1 0\n'] Demo Output: ['2\n', '1\n'] Note: Explanation to the first and second samples from the statement, respectively:
```python from collections import defaultdict n, x, y = map(int, input().split()) dic = defaultdict(int) cnt = ok = 0 while n: n -= 1 a, b = map(int, input().split()) if x == a: ok = 1 else: dic[(b - y) / (a - x)] += 1 for i in dic: cnt += dic[i] != 0 print(cnt + ok) ```
3
515
A
Drazil and Date
PROGRAMMING
1,000
[ "math" ]
null
null
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes".
[ "5 5 11\n", "10 15 25\n", "0 5 1\n", "0 0 2\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "5 5 11", "output": "No" }, { "input": "10 15 25", "output": "Yes" }, { "input": "0 5 1", "output": "No" }, { "input": "0 0 2", "output": "Yes" }, { "input": "999999999 999999999 2000000000", "output": "Yes" }, { "input": "-606037695 998320124 820674098", "output": "No" }, { "input": "948253616 -83299062 1031552680", "output": "Yes" }, { "input": "711980199 216568284 928548487", "output": "Yes" }, { "input": "-453961301 271150176 725111473", "output": "No" }, { "input": "0 0 2000000000", "output": "Yes" }, { "input": "0 0 1999999999", "output": "No" }, { "input": "1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 1000000000", "output": "No" }, { "input": "-1 -1 3", "output": "No" }, { "input": "919785634 216774719 129321944", "output": "No" }, { "input": "-467780354 -721273539 1369030008", "output": "No" }, { "input": "-232833910 -880680184 1774549792", "output": "Yes" }, { "input": "45535578 402686155 1011249824", "output": "No" }, { "input": "-203250176 -30379840 233630015", "output": "No" }, { "input": "-814516648 -75830576 890347222", "output": "No" }, { "input": "869184175 -511854751 1381038923", "output": "No" }, { "input": "552884998 -262338193 815223187", "output": "No" }, { "input": "-133874494 857573117 991447611", "output": "Yes" }, { "input": "169406792 786701289 956108082", "output": "No" }, { "input": "30237137 -989203246 1019440385", "output": "Yes" }, { "input": "576608216 -617624133 1194232352", "output": "No" }, { "input": "-662360368 97618995 759979367", "output": "Yes" }, { "input": "-115989290 321714461 437703756", "output": "No" }, { "input": "-1 -3 2", "output": "No" }, { "input": "-2 -2 2", "output": "No" }, { "input": "0 0 1", "output": "No" }, { "input": "0 -1 7", "output": "Yes" }, { "input": "1 2 7", "output": "Yes" }, { "input": "0 5 6", "output": "No" }, { "input": "0 -4 2", "output": "No" }, { "input": "-5 5 2", "output": "No" }, { "input": "-5 -2 7", "output": "Yes" }, { "input": "5 -5 2", "output": "No" } ]
1,658,838,105
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
62
0
a, b, c = map(int, input().split()) if not (a + b) or a+b == c: print('YES') else: print('NO')
Title: Drazil and Date Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? Input Specification: You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. Output Specification: If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes". Demo Input: ['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n'] Demo Output: ['No\n', 'Yes\n', 'No\n', 'Yes\n'] Note: In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a, b, c = map(int, input().split()) if not (a + b) or a+b == c: print('YES') else: print('NO') ```
0
581
C
Developing Skills
PROGRAMMING
1,400
[ "implementation", "math", "sortings" ]
null
null
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has *n* different skills, each of which is characterized by an integer *a**i* from 0 to 100. The higher the number *a**i* is, the higher is the *i*-th skill of the character. The total rating of the character is calculated as the sum of the values ​​of for all *i* from 1 to *n*. The expression ⌊ *x*⌋ denotes the result of rounding the number *x* down to the nearest integer. At the beginning of the game Petya got *k* improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if *a*4<==<=46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused. Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of *n* integers *a**i* (0<=≤<=*a**i*<=≤<=100), where *a**i* characterizes the level of the *i*-th skill of the character.
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using *k* or less improvement units.
[ "2 4\n7 9\n", "3 8\n17 15 19\n", "2 2\n99 100\n" ]
[ "2\n", "5\n", "20\n" ]
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to *lfloor* *frac*{100}{10} *rfloor* +  *lfloor* *frac*{100}{10} *rfloor* = 10 + 10 =  20. In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ccaa4e1e435ea3a339c322e03a32de69d214a257.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b246630ca7d1b95b91970759bd8455cb3e930bf9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,500
[ { "input": "2 4\n7 9", "output": "2" }, { "input": "3 8\n17 15 19", "output": "5" }, { "input": "2 2\n99 100", "output": "20" }, { "input": "100 10000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1000" }, { "input": "100 10000\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": "1000" }, { "input": "1 16\n78", "output": "9" }, { "input": "2 33\n30 88", "output": "15" }, { "input": "3 9\n93 62 7", "output": "16" }, { "input": "5 145\n19 77 59 1 63", "output": "36" }, { "input": "7 168\n2 71 56 58 42 61 39", "output": "49" }, { "input": "10 217\n48 30 82 70 10 5 34 11 90 90", "output": "68" }, { "input": "15 204\n19 81 24 22 59 46 48 8 1 66 100 20 46 56 61", "output": "86" }, { "input": "20 484\n24 72 72 13 85 50 52 3 81 79 71 57 57 75 6 52 54 41 61 73", "output": "156" }, { "input": "30 825\n33 25 61 69 92 38 2 62 73 78 83 32 25 5 5 82 64 93 38 25 52 9 40 52 38 90 25 85 99 20", "output": "232" }, { "input": "40 700\n43 35 51 91 44 51 86 20 64 10 50 40 16 25 37 89 18 44 94 99 18 30 11 27 73 3 90 78 28 98 87 43 85 88 29 93 6 81 78 16", "output": "276" }, { "input": "50 1607\n19 55 52 35 18 39 3 12 55 78 62 83 85 56 36 86 96 28 70 40 40 83 27 2 51 49 87 28 58 75 27 69 36 82 78 29 99 87 29 78 82 78 15 85 52 32 90 6 1 76", "output": "424" }, { "input": "60 2213\n17 98 74 91 59 84 87 71 13 9 74 48 75 76 36 25 49 80 25 92 41 24 99 45 98 95 27 54 88 63 25 50 19 43 15 90 58 48 58 83 37 88 35 63 63 23 27 82 80 7 82 93 71 18 85 17 13 2 50 74", "output": "552" }, { "input": "70 1313\n27 7 64 45 44 29 37 63 38 9 85 56 43 74 46 55 59 97 13 33 75 78 2 88 32 7 24 36 86 40 66 42 26 48 64 14 50 21 20 10 50 73 21 29 17 46 97 90 81 73 61 25 95 82 93 94 72 38 80 13 3 3 20 90 34 20 24 49 96 51", "output": "468" }, { "input": "40 108\n20 100 99 50 8 78 44 67 91 75 93 53 96 81 96 86 81 0 58 9 51 63 70 73 80 79 28 82 4 15 60 74 19 17 54 81 11 67 71 66", "output": "245" }, { "input": "50 284\n61 25 82 73 57 61 90 22 63 99 58 4 27 54 8 29 46 99 73 73 60 42 45 17 75 86 38 83 4 1 67 44 74 87 32 33 14 95 87 46 40 3 37 6 42 38 51 39 98 48", "output": "282" }, { "input": "60 1947\n46 29 55 97 37 32 24 22 35 66 24 78 92 5 55 41 21 30 88 24 13 89 77 30 71 15 58 26 39 10 42 36 28 66 21 28 51 55 91 4 94 59 63 46 1 39 46 1 70 7 46 37 96 41 70 19 55 80 59 83", "output": "471" }, { "input": "70 2454\n88 23 5 86 53 48 60 78 97 90 0 18 57 78 68 28 87 39 70 9 0 35 18 53 67 56 0 71 7 86 39 96 83 45 99 92 43 38 40 63 81 59 89 86 28 62 53 97 53 2 73 93 38 49 51 62 93 3 63 49 47 85 72 98 43 91 7 20 47 66", "output": "632" }, { "input": "80 1879\n36 27 86 90 18 85 99 54 29 8 64 31 34 26 45 51 13 48 58 6 98 30 74 63 78 53 88 98 15 17 29 67 78 8 2 7 42 26 72 83 5 59 8 7 27 59 34 65 93 71 50 34 63 45 21 81 19 30 99 41 25 11 83 62 17 29 80 61 91 22 19 95 80 73 15 39 10 37 88 42", "output": "570" }, { "input": "90 1191\n46 37 76 11 60 29 49 13 88 41 65 7 2 13 44 58 23 10 45 48 63 83 79 5 89 99 28 80 34 6 37 92 61 70 51 0 34 67 68 77 62 69 27 86 71 83 72 73 93 92 62 68 86 76 28 24 67 66 61 12 3 52 45 44 58 83 0 84 18 50 75 51 41 25 21 53 39 20 36 45 62 24 12 33 61 81 9 13 27 22", "output": "554" }, { "input": "100 1257\n80 15 39 54 98 10 65 77 55 98 15 25 78 40 25 16 17 60 25 60 56 29 91 16 14 60 47 31 15 59 83 77 10 54 27 21 50 34 64 69 43 81 32 14 30 93 0 91 75 51 19 84 88 14 30 4 99 59 94 69 24 51 35 99 22 25 41 77 64 97 10 4 56 75 97 54 4 55 29 8 14 16 88 34 80 47 66 30 80 60 45 45 93 85 49 91 37 16 49 56", "output": "619" }, { "input": "100 3852\n71 34 1 77 97 36 66 78 95 47 47 15 50 100 43 47 20 23 61 92 49 86 29 92 100 85 5 58 59 19 16 81 16 89 93 75 46 86 9 50 9 49 61 88 76 13 14 99 47 64 39 42 63 5 57 8 51 21 21 62 92 84 84 56 9 37 72 19 99 19 8 60 25 21 4 0 98 80 29 63 52 87 91 30 79 79 96 22 32 63 87 73 51 89 81 84 69 30 55 31", "output": "922" }, { "input": "100 2533\n16 32 22 100 52 10 43 28 87 72 69 84 26 0 74 46 28 34 46 47 90 18 49 6 42 30 18 33 86 38 94 78 8 39 54 46 72 45 83 68 38 4 14 6 86 24 71 36 22 8 37 99 28 7 88 49 4 69 46 81 30 95 92 18 81 21 14 7 43 14 80 59 14 72 93 6 78 43 56 12 66 21 81 80 39 5 54 69 40 12 41 35 23 58 1 75 40 3 36 97", "output": "706" }, { "input": "100 2239\n95 9 31 56 96 85 88 79 78 63 68 95 1 91 94 56 57 88 30 92 64 52 91 11 17 99 65 63 35 68 82 18 66 57 26 62 32 70 89 98 42 17 68 93 53 79 50 6 30 76 69 10 4 41 18 56 81 49 14 10 91 6 32 80 85 94 2 95 66 9 18 58 71 23 23 48 68 72 39 51 0 23 71 73 10 89 13 15 16 30 27 44 63 93 22 77 12 12 28 5", "output": "737" }, { "input": "100 1689\n40 18 85 79 18 70 44 62 37 21 68 6 9 60 13 55 98 98 82 80 4 75 44 83 60 44 10 60 28 65 59 82 48 41 20 100 57 62 28 60 3 5 54 91 31 89 6 44 38 20 34 90 14 99 82 96 57 97 39 73 30 96 41 42 56 33 45 83 78 15 79 25 27 7 43 54 14 90 22 68 3 1 27 88 49 37 84 61 92 37 14 41 81 62 10 36 73 86 9 4", "output": "666" }, { "input": "1 44\n56", "output": "10" }, { "input": "5 136\n65 53 80 92 74", "output": "50" }, { "input": "20 964\n70 82 81 14 73 35 40 21 73 70 71 35 32 43 26 51 51 62 45 61", "output": "200" }, { "input": "80 4124\n14 37 6 11 63 59 43 72 88 0 53 43 42 95 65 61 9 69 9 95 49 64 27 34 53 31 34 26 30 48 85 97 35 60 74 45 35 86 11 34 45 72 95 95 95 13 58 2 0 38 37 13 61 47 85 77 96 10 34 3 54 55 91 23 57 13 33 16 2 17 80 61 36 57 79 81 90 33 82 48", "output": "800" }, { "input": "100 4899\n66 100 11 81 19 55 96 14 66 10 49 75 1 58 64 80 47 95 45 79 36 89 31 30 61 96 93 86 50 61 64 32 82 13 57 75 5 46 96 49 3 98 34 6 91 7 50 62 46 31 100 4 2 16 20 47 86 41 73 17 43 71 84 47 18 100 55 23 10 37 4 19 84 61 27 61 42 29 95 41 93 5 72 58 24 10 80 45 78 68 19 18 30 28 95 91 15 90 87 47", "output": "1000" }, { "input": "1 7035769\n1", "output": "10" }, { "input": "5 5012340\n10 63 89 25 29", "output": "50" }, { "input": "20 5527187\n15 91 34 37 16 77 85 4 31 28 2 47 8 45 57 51 58 72 97 16", "output": "200" }, { "input": "80 8000114\n27 46 16 80 85 11 20 22 80 24 85 22 17 86 96 60 16 12 94 39 23 86 12 49 28 78 80 23 92 78 62 38 27 43 35 62 60 89 85 63 39 27 70 13 73 91 82 73 98 83 70 93 5 37 15 85 39 58 92 34 93 44 31 86 28 86 43 3 25 12 18 61 25 7 67 87 37 29 65 98", "output": "800" }, { "input": "100 9455943\n44 8 21 71 7 29 40 65 91 70 48 19 77 48 16 22 54 4 29 34 9 22 73 34 47 41 5 83 32 91 52 6 74 64 18 23 9 4 36 78 98 20 20 3 69 86 41 67 54 76 87 84 47 6 52 87 61 100 98 80 14 14 24 99 90 73 97 79 22 65 65 51 29 44 15 67 21 58 79 80 96 40 63 73 96 59 72 24 87 85 74 49 81 30 16 61 87 30 0 13", "output": "1000" }, { "input": "1 6\n27", "output": "3" }, { "input": "1 10\n88", "output": "9" }, { "input": "1 3\n93", "output": "9" }, { "input": "2 22\n48 44", "output": "11" }, { "input": "1 48\n52", "output": "10" }, { "input": "1 2135072\n72", "output": "10" }, { "input": "3 5\n2 3 1", "output": "0" }, { "input": "5 1\n8 8 8 8 8", "output": "0" }, { "input": "3 150\n1 1 1", "output": "15" }, { "input": "4 3\n7 9 9 9", "output": "3" }, { "input": "1 10\n100", "output": "10" }, { "input": "3 11\n100 100 100", "output": "30" }, { "input": "2 11\n99 100", "output": "20" } ]
1,699,928,418
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
31
0
arr = input().split(" ") points = int(arr[1]) shops = input().split(" ") buckets = [int(i) for i in shops] mods = [10 - i%10 for i in buckets] startPoints = sum([i//10 for i in buckets]) mods = sorted(mods) ctr = 0 while points != 0: if points < mods[ctr]: break else: points -= mods[ctr] ctr += 1 print(ctr + startPoints)
Title: Developing Skills Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has *n* different skills, each of which is characterized by an integer *a**i* from 0 to 100. The higher the number *a**i* is, the higher is the *i*-th skill of the character. The total rating of the character is calculated as the sum of the values ​​of for all *i* from 1 to *n*. The expression ⌊ *x*⌋ denotes the result of rounding the number *x* down to the nearest integer. At the beginning of the game Petya got *k* improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if *a*4<==<=46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused. Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. Input Specification: The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of *n* integers *a**i* (0<=≤<=*a**i*<=≤<=100), where *a**i* characterizes the level of the *i*-th skill of the character. Output Specification: The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using *k* or less improvement units. Demo Input: ['2 4\n7 9\n', '3 8\n17 15 19\n', '2 2\n99 100\n'] Demo Output: ['2\n', '5\n', '20\n'] Note: In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to *lfloor* *frac*{100}{10} *rfloor* +  *lfloor* *frac*{100}{10} *rfloor* = 10 + 10 =  20. In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ccaa4e1e435ea3a339c322e03a32de69d214a257.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b246630ca7d1b95b91970759bd8455cb3e930bf9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python arr = input().split(" ") points = int(arr[1]) shops = input().split(" ") buckets = [int(i) for i in shops] mods = [10 - i%10 for i in buckets] startPoints = sum([i//10 for i in buckets]) mods = sorted(mods) ctr = 0 while points != 0: if points < mods[ctr]: break else: points -= mods[ctr] ctr += 1 print(ctr + startPoints) ```
-1
288
A
Polo the Penguin and Strings
PROGRAMMING
1,300
[ "greedy" ]
null
null
Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbouring letters of a string coincide; that is, if we represent a string as *s*<==<=*s*1*s*2... *s**n*, then the following inequality holds, *s**i*<=≠<=*s**i*<=+<=1(1<=≤<=*i*<=&lt;<=*n*). 1. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String *x*<==<=*x*1*x*2... *x**p* is lexicographically less than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=&lt;<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there is such number *r* (*r*<=&lt;<=*p*,<=*r*<=&lt;<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=&lt;<=*y**r*<=+<=1. The characters of the strings are compared by their ASCII codes.
A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters.
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
[ "7 4\n", "4 7\n" ]
[ "ababacd\n", "-1\n" ]
none
500
[ { "input": "7 4", "output": "ababacd" }, { "input": "4 7", "output": "-1" }, { "input": "10 5", "output": "abababacde" }, { "input": "47 2", "output": "abababababababababababababababababababababababa" }, { "input": "10 7", "output": "ababacdefg" }, { "input": "20 7", "output": "abababababababacdefg" }, { "input": "26 26", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "47 1", "output": "-1" }, { "input": "128 26", "output": "ababababababababababababababababababababababababababababababababababababababababababababababababababababcdefghijklmnopqrstuvwxyz" }, { "input": "999 7", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "4585 1", "output": "-1" }, { "input": "6875 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "7642 3", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "100000 7", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "68754 25", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "1000000 1", "output": "-1" }, { "input": "999999 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "1000000 26", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "100000 20", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "579466 17", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "679854 9", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "978458 16", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "6791 21", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..." }, { "input": "6795 1", "output": "-1" }, { "input": "12 17", "output": "-1" }, { "input": "1 1", "output": "a" }, { "input": "2 2", "output": "ab" }, { "input": "1 2", "output": "-1" }, { "input": "1 26", "output": "-1" }, { "input": "26 2", "output": "ababababababababababababab" }, { "input": "123 21", "output": "ababababababababababababababababababababababababababababababababababababababababababababababababababababcdefghijklmnopqrstu" }, { "input": "3 3", "output": "abc" } ]
1,622,334,528
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
218
2,048,000
import collections import functools import math import sys import bisect def In(): return map(int, sys.stdin.readline().split()) input = sys.stdin.readline def pologen(): n, k = In() if n < k: return -1 ans = [] for i in range(n - k + 2): ans.append(chr(97 + i % 2)) for i in range(2,k): ans.append(chr(97 + i)) return ''.join(ans) print(pologen())
Title: Polo the Penguin and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbouring letters of a string coincide; that is, if we represent a string as *s*<==<=*s*1*s*2... *s**n*, then the following inequality holds, *s**i*<=≠<=*s**i*<=+<=1(1<=≤<=*i*<=&lt;<=*n*). 1. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String *x*<==<=*x*1*x*2... *x**p* is lexicographically less than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=&lt;<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there is such number *r* (*r*<=&lt;<=*p*,<=*r*<=&lt;<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=&lt;<=*y**r*<=+<=1. The characters of the strings are compared by their ASCII codes. Input Specification: A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters. Output Specification: In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Demo Input: ['7 4\n', '4 7\n'] Demo Output: ['ababacd\n', '-1\n'] Note: none
```python import collections import functools import math import sys import bisect def In(): return map(int, sys.stdin.readline().split()) input = sys.stdin.readline def pologen(): n, k = In() if n < k: return -1 ans = [] for i in range(n - k + 2): ans.append(chr(97 + i % 2)) for i in range(2,k): ans.append(chr(97 + i)) return ''.join(ans) print(pologen()) ```
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,509,551,273
2,147,483,647
Python 3
OK
TESTS
55
62
0
name = ['Danil','Olya','Slava','Ann','Nikita'] real = [] word = input() for i in name: if word.find(i) != -1: real.append(i) if len(real) == 1: if word.find(real[0],word.find(real[0])+len(real[0])) == -1: print("YES") else: print("NO") 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 name = ['Danil','Olya','Slava','Ann','Nikita'] real = [] word = input() for i in name: if word.find(i) != -1: real.append(i) if len(real) == 1: if word.find(real[0],word.find(real[0])+len(real[0])) == -1: print("YES") else: print("NO") else: print("NO") ```
3
900
B
Position in Fraction
PROGRAMMING
1,300
[ "math", "number theory" ]
null
null
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=&lt;<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9).
Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
[ "1 2 0\n", "2 3 7\n" ]
[ "2", "-1" ]
The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction.
1,000
[ { "input": "1 2 0", "output": "2" }, { "input": "2 3 7", "output": "-1" }, { "input": "1 100000 1", "output": "5" }, { "input": "1 7 7", "output": "6" }, { "input": "99999 100000 8", "output": "-1" }, { "input": "44102 73848 2", "output": "132" }, { "input": "7 31 3", "output": "15" }, { "input": "8880 81608 9", "output": "161" }, { "input": "4942 62768 5", "output": "122" }, { "input": "69168 84860 4", "output": "107" }, { "input": "971 1883 3", "output": "130" }, { "input": "1636 3269 6", "output": "150" }, { "input": "6873 7769 3", "output": "163" }, { "input": "13805 15538 3", "output": "164" }, { "input": "10958 21926 3", "output": "117" }, { "input": "8 51 0", "output": "10" }, { "input": "1 10 1", "output": "1" }, { "input": "1 9 0", "output": "-1" }, { "input": "53 101 6", "output": "-1" }, { "input": "1 10001 9", "output": "5" }, { "input": "25102 31579 2", "output": "174" }, { "input": "38790 39359 0", "output": "212" }, { "input": "47117 78718 0", "output": "213" }, { "input": "1 57 0", "output": "1" }, { "input": "1 3 0", "output": "-1" }, { "input": "1 100 0", "output": "1" }, { "input": "2 3 0", "output": "-1" }, { "input": "99971 99989 0", "output": "9" }, { "input": "567 1580 0", "output": "6" }, { "input": "45 97 0", "output": "39" }, { "input": "35 111 4", "output": "-1" }, { "input": "1 2 5", "output": "1" }, { "input": "1 7 0", "output": "-1" } ]
1,513,387,876
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
17
77
5,529,600
def Decimals(a, b): denom = list() while a != 0 and a not in denom: denom.append(a) a *= 10 yield a // b a = a % b def main(): a, b, c = map(int, input().strip().split()) for (i, n) in enumerate(Decimals(a, b)): if n == c: print(i + 1) return if c == 0: print(i + 2) else: print(-1) if __name__ == "__main__": main()
Title: Position in Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. Input Specification: The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=&lt;<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). Output Specification: Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Demo Input: ['1 2 0\n', '2 3 7\n'] Demo Output: ['2', '-1'] Note: The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction.
```python def Decimals(a, b): denom = list() while a != 0 and a not in denom: denom.append(a) a *= 10 yield a // b a = a % b def main(): a, b, c = map(int, input().strip().split()) for (i, n) in enumerate(Decimals(a, b)): if n == c: print(i + 1) return if c == 0: print(i + 2) else: print(-1) if __name__ == "__main__": main() ```
0
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU", "output": "80" }, { "input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR", "output": "84" }, { "input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD", "output": "76" }, { "input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR", "output": "86" }, { "input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR", "output": "84" }, { "input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL", "output": "86" }, { "input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU", "output": "86" }, { "input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL", "output": "84" }, { "input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR", "output": "82" }, { "input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD", "output": "92" }, { "input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD", "output": "86" }, { "input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL", "output": "88" }, { "input": "1\nU", "output": "0" }, { "input": "5\nUUULD", "output": "2" }, { "input": "1\nD", "output": "0" }, { "input": "5\nURLUL", "output": "2" }, { "input": "5\nDDDRU", "output": "2" }, { "input": "2\nLR", "output": "2" }, { "input": "8\nDDRDLDUR", "output": "4" }, { "input": "6\nLLLLUD", "output": "2" }, { "input": "13\nRRRLLLLLLLLLL", "output": "6" } ]
1,690,397,888
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
a=int(input()) s=input() dict1={'U':1,'D':-1} dict2={'L':-1,'R':1} c1=0 s1=0 c2=0 s2=0 l=[] for k in s: if k in dict1: s1=s1+dict1[k] c1+=1 else: s2=s2+dict2[k] c2+=1 if s1+s2==0: l.append(c1+c2) if len(l)>0: print(max(l)) else: print(0)
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! Input Specification: The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. Output Specification: Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. Demo Input: ['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n'] Demo Output: ['4\n', '0\n', '4\n'] Note: none
```python a=int(input()) s=input() dict1={'U':1,'D':-1} dict2={'L':-1,'R':1} c1=0 s1=0 c2=0 s2=0 l=[] for k in s: if k in dict1: s1=s1+dict1[k] c1+=1 else: s2=s2+dict2[k] c2+=1 if s1+s2==0: l.append(c1+c2) if len(l)>0: print(max(l)) else: print(0) ```
0
675
A
Infinite Sequence
PROGRAMMING
1,100
[ "math" ]
null
null
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
500
[ { "input": "1 7 3", "output": "YES" }, { "input": "10 10 0", "output": "YES" }, { "input": "1 -4 5", "output": "NO" }, { "input": "0 60 50", "output": "NO" }, { "input": "1 -4 -5", "output": "YES" }, { "input": "0 1 0", "output": "NO" }, { "input": "10 10 42", "output": "YES" }, { "input": "-1000000000 1000000000 -1", "output": "NO" }, { "input": "10 16 4", "output": "NO" }, { "input": "-1000000000 1000000000 5", "output": "YES" }, { "input": "1000000000 -1000000000 5", "output": "NO" }, { "input": "1000000000 -1000000000 0", "output": "NO" }, { "input": "1000000000 1000000000 0", "output": "YES" }, { "input": "115078364 -899474523 -1", "output": "YES" }, { "input": "-245436499 416383245 992", "output": "YES" }, { "input": "-719636354 536952440 2", "output": "YES" }, { "input": "-198350539 963391024 68337739", "output": "YES" }, { "input": "-652811055 875986516 1091", "output": "YES" }, { "input": "119057893 -516914539 -39748277", "output": "YES" }, { "input": "989140430 731276607 -36837689", "output": "YES" }, { "input": "677168390 494583489 -985071853", "output": "NO" }, { "input": "58090193 777423708 395693923", "output": "NO" }, { "input": "479823846 -403424770 -653472589", "output": "NO" }, { "input": "-52536829 -132023273 -736287999", "output": "NO" }, { "input": "-198893776 740026818 -547885271", "output": "NO" }, { "input": "-2 -2 -2", "output": "YES" }, { "input": "-2 -2 -1", "output": "YES" }, { "input": "-2 -2 0", "output": "YES" }, { "input": "-2 -2 1", "output": "YES" }, { "input": "-2 -2 2", "output": "YES" }, { "input": "-2 -1 -2", "output": "NO" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "-2 -1 0", "output": "NO" }, { "input": "-2 -1 1", "output": "YES" }, { "input": "-2 -1 2", "output": "NO" }, { "input": "-2 0 -2", "output": "NO" }, { "input": "-2 0 -1", "output": "NO" }, { "input": "-2 0 0", "output": "NO" }, { "input": "-2 0 1", "output": "YES" }, { "input": "-2 0 2", "output": "YES" }, { "input": "-2 1 -2", "output": "NO" }, { "input": "-2 1 -1", "output": "NO" }, { "input": "-2 1 0", "output": "NO" }, { "input": "-2 1 1", "output": "YES" }, { "input": "-2 1 2", "output": "NO" }, { "input": "-2 2 -2", "output": "NO" }, { "input": "-2 2 -1", "output": "NO" }, { "input": "-2 2 0", "output": "NO" }, { "input": "-2 2 1", "output": "YES" }, { "input": "-2 2 2", "output": "YES" }, { "input": "-1 -2 -2", "output": "NO" }, { "input": "-1 -2 -1", "output": "YES" }, { "input": "-1 -2 0", "output": "NO" }, { "input": "-1 -2 1", "output": "NO" }, { "input": "-1 -2 2", "output": "NO" }, { "input": "-1 -1 -2", "output": "YES" }, { "input": "-1 -1 -1", "output": "YES" }, { "input": "-1 -1 0", "output": "YES" }, { "input": "-1 -1 1", "output": "YES" }, { "input": "-1 -1 2", "output": "YES" }, { "input": "-1 0 -2", "output": "NO" }, { "input": "-1 0 -1", "output": "NO" }, { "input": "-1 0 0", "output": "NO" }, { "input": "-1 0 1", "output": "YES" }, { "input": "-1 0 2", "output": "NO" }, { "input": "-1 1 -2", "output": "NO" }, { "input": "-1 1 -1", "output": "NO" }, { "input": "-1 1 0", "output": "NO" }, { "input": "-1 1 1", "output": "YES" }, { "input": "-1 1 2", "output": "YES" }, { "input": "-1 2 -2", "output": "NO" }, { "input": "-1 2 -1", "output": "NO" }, { "input": "-1 2 0", "output": "NO" }, { "input": "-1 2 1", "output": "YES" }, { "input": "-1 2 2", "output": "NO" }, { "input": "0 -2 -2", "output": "YES" }, { "input": "0 -2 -1", "output": "YES" }, { "input": "0 -2 0", "output": "NO" }, { "input": "0 -2 1", "output": "NO" }, { "input": "0 -2 2", "output": "NO" }, { "input": "0 -1 -2", "output": "NO" }, { "input": "0 -1 -1", "output": "YES" }, { "input": "0 -1 0", "output": "NO" }, { "input": "0 -1 1", "output": "NO" }, { "input": "0 -1 2", "output": "NO" }, { "input": "0 0 -2", "output": "YES" }, { "input": "0 0 -1", "output": "YES" }, { "input": "0 0 0", "output": "YES" }, { "input": "0 0 1", "output": "YES" }, { "input": "0 0 2", "output": "YES" }, { "input": "0 1 -2", "output": "NO" }, { "input": "0 1 -1", "output": "NO" }, { "input": "0 1 0", "output": "NO" }, { "input": "0 1 1", "output": "YES" }, { "input": "0 1 2", "output": "NO" }, { "input": "0 2 -2", "output": "NO" }, { "input": "0 2 -1", "output": "NO" }, { "input": "0 2 0", "output": "NO" }, { "input": "0 2 1", "output": "YES" }, { "input": "0 2 2", "output": "YES" }, { "input": "1 -2 -2", "output": "NO" }, { "input": "1 -2 -1", "output": "YES" }, { "input": "1 -2 0", "output": "NO" }, { "input": "1 -2 1", "output": "NO" }, { "input": "1 -2 2", "output": "NO" }, { "input": "1 -1 -2", "output": "YES" }, { "input": "1 -1 -1", "output": "YES" }, { "input": "1 -1 0", "output": "NO" }, { "input": "1 -1 1", "output": "NO" }, { "input": "1 -1 2", "output": "NO" }, { "input": "1 0 -2", "output": "NO" }, { "input": "1 0 -1", "output": "YES" }, { "input": "1 0 0", "output": "NO" }, { "input": "1 0 1", "output": "NO" }, { "input": "1 0 2", "output": "NO" }, { "input": "1 1 -2", "output": "YES" }, { "input": "1 1 -1", "output": "YES" }, { "input": "1 1 0", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "1 1 2", "output": "YES" }, { "input": "1 2 -2", "output": "NO" }, { "input": "1 2 -1", "output": "NO" }, { "input": "1 2 0", "output": "NO" }, { "input": "1 2 1", "output": "YES" }, { "input": "1 2 2", "output": "NO" }, { "input": "2 -2 -2", "output": "YES" }, { "input": "2 -2 -1", "output": "YES" }, { "input": "2 -2 0", "output": "NO" }, { "input": "2 -2 1", "output": "NO" }, { "input": "2 -2 2", "output": "NO" }, { "input": "2 -1 -2", "output": "NO" }, { "input": "2 -1 -1", "output": "YES" }, { "input": "2 -1 0", "output": "NO" }, { "input": "2 -1 1", "output": "NO" }, { "input": "2 -1 2", "output": "NO" }, { "input": "2 0 -2", "output": "YES" }, { "input": "2 0 -1", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "2 0 1", "output": "NO" }, { "input": "2 0 2", "output": "NO" }, { "input": "2 1 -2", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "2 1 0", "output": "NO" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input": "2 2 -2", "output": "YES" }, { "input": "2 2 -1", "output": "YES" }, { "input": "2 2 0", "output": "YES" }, { "input": "2 2 1", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "-1000000000 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 2", "output": "YES" }, { "input": "1000000000 -1000000000 -1", "output": "YES" }, { "input": "5 2 3", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "3 2 1", "output": "NO" }, { "input": "0 -5 -3", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "0 10 1", "output": "YES" }, { "input": "15 5 -5", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "20 10 0", "output": "NO" }, { "input": "20 15 5", "output": "NO" }, { "input": "1 6 1", "output": "YES" }, { "input": "1000000000 0 -1000000000", "output": "YES" }, { "input": "1 1 -5", "output": "YES" }, { "input": "4 6 1", "output": "YES" }, { "input": "-5 -10 -5", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "10 9 -1", "output": "YES" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "1 13 3", "output": "YES" }, { "input": "2 3 0", "output": "NO" }, { "input": "1 1 -1", "output": "YES" }, { "input": "5 -10 -5", "output": "YES" }, { "input": "5 3 1", "output": "NO" }, { "input": "1 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 1000000000", "output": "YES" } ]
1,593,742,166
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
0
a,b,c=[int(x) for x in input().split()] if c>0: while a<b: a+=c else: while b<a: a+=c if a==b: print('YES') else: print('NO')
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. Input Specification: The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. Output Specification: If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). Demo Input: ['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
```python a,b,c=[int(x) for x in input().split()] if c>0: while a<b: a+=c else: while b<a: a+=c if a==b: print('YES') else: print('NO') ```
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,602,645,903
2,147,483,647
Python 3
OK
TESTS
40
109
0
sample=list("hello") counter=0 word=input() for i in range(len(word)): if word[i]==sample[counter]: counter+=1 if counter==5: print ("YES") break if counter<5: print ("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python sample=list("hello") counter=0 word=input() for i in range(len(word)): if word[i]==sample[counter]: counter+=1 if counter==5: print ("YES") break if counter<5: print ("NO") ```
3.9455
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 87 200 62 168 51 185 192 118", "output": "48" }, { "input": "1 1\n10000", "output": "5000" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "2 2\n2 2", "output": "1" } ]
1,490,805,170
1,670
Python 3
OK
TESTS
31
124
12,902,400
"""def main(): n, k = map(int, input().split()) lst = [int(i) for i in input().split()] counter = 0 while sum(lst) > 0: max_c = max(lst) if max_c >= 2*k: lst[lst.index(max_c)] -= 2 * k elif k<=max_c <= 2*k: lst[lst.index(max_c)] = 0 else: lst[lst.index(max_c)] = 0 counter += 1 print(main()) """ n, k = map(int, input().split()) lst = [int(i) for i in input().split()] count = 0 for i in range(n): count += (lst[i] + k -1)//k count = (count + 1)//2 print(count)
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. Output Specification: The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. Demo Input: ['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n'] Demo Output: ['3\n', '5\n'] Note: In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
```python """def main(): n, k = map(int, input().split()) lst = [int(i) for i in input().split()] counter = 0 while sum(lst) > 0: max_c = max(lst) if max_c >= 2*k: lst[lst.index(max_c)] -= 2 * k elif k<=max_c <= 2*k: lst[lst.index(max_c)] = 0 else: lst[lst.index(max_c)] = 0 counter += 1 print(main()) """ n, k = map(int, input().split()) lst = [int(i) for i in input().split()] count = 0 for i in range(n): count += (lst[i] + k -1)//k count = (count + 1)//2 print(count) ```
3
830
B
Cards Sorting
PROGRAMMING
1,600
[ "data structures", "implementation", "sortings" ]
null
null
Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is. You are to determine the total number of times Vasily takes the top card from the deck.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cards in the deck. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), where *a**i* is the number written on the *i*-th from top card in the deck.
Print the total number of times Vasily takes the top card from the deck.
[ "4\n6 3 1 2\n", "1\n1000\n", "7\n3 3 3 3 3 3 3\n" ]
[ "7\n", "1\n", "7\n" ]
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
1,000
[ { "input": "4\n6 3 1 2", "output": "7" }, { "input": "1\n1000", "output": "1" }, { "input": "7\n3 3 3 3 3 3 3", "output": "7" }, { "input": "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256 404 852 496 373 322 716 202 689 857 936 806 556 153 137 863 1047 678 564 474 282 135 610 176 855 360 814 144 77 112 354 154", "output": "1042" }, { "input": "87\n12 2 2 10 12 1 5 9 15 2 4 7 7 14 8 10 1 6 7 6 13 15 10 6 2 11 13 1 15 14 8 8 4 7 11 12 3 15 9 2 13 1 7 11 2 1 13 11 8 14 2 2 12 7 13 4 13 3 13 3 11 1 7 13 15 8 12 4 12 4 1 4 9 3 13 12 10 15 14 10 7 7 7 2 7 6 10", "output": "580" }, { "input": "10\n4 3 4 3 3 3 4 4 4 3", "output": "15" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "20" }, { "input": "30\n6283 14661 69188 39640 41261 48019 86266 70517 4592 69008 20602 33339 29980 96844 76008 96294 27120 22671 5243 742 33692 18068 29056 48033 1223 82728 99765 38350 36425 10671", "output": "235" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14", "output": "1805" } ]
1,503,470,619
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
7,270,400
n = int(input()) l = list(map(int, input().split())) z = sorted(list(map(int, set(l)))) q = [] for i in z: q.append(l.count(i)) k = 0 g = 0 while len(l) != 0: g += 1 if q[k] == 0: k += 1 if l[0] == z[k]: q[k] -= 1 l = l[1:] else: l = l[1:] + l[:1] print(g)
Title: Cards Sorting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is. You are to determine the total number of times Vasily takes the top card from the deck. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cards in the deck. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), where *a**i* is the number written on the *i*-th from top card in the deck. Output Specification: Print the total number of times Vasily takes the top card from the deck. Demo Input: ['4\n6 3 1 2\n', '1\n1000\n', '7\n3 3 3 3 3 3 3\n'] Demo Output: ['7\n', '1\n', '7\n'] Note: In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
```python n = int(input()) l = list(map(int, input().split())) z = sorted(list(map(int, set(l)))) q = [] for i in z: q.append(l.count(i)) k = 0 g = 0 while len(l) != 0: g += 1 if q[k] == 0: k += 1 if l[0] == z[k]: q[k] -= 1 l = l[1:] else: l = l[1:] + l[:1] print(g) ```
0
814
C
An impassioned circulation of affection
PROGRAMMING
1,600
[ "brute force", "dp", "strings", "two pointers" ]
null
null
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* from left to right, and the *i*-th piece has a colour *s**i*, denoted by a lowercase English letter. Nadeko will repaint at most *m* of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour *c* — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland. For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3. But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has *q* plans on this, each of which can be expressed as a pair of an integer *m**i* and a lowercase letter *c**i*, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan.
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=500) — the length of the garland. The second line contains *n* lowercase English letters *s*1*s*2... *s**n* as a string — the initial colours of paper pieces on the garland. The third line contains a positive integer *q* (1<=≤<=*q*<=≤<=200<=000) — the number of plans Nadeko has. The next *q* lines describe one plan each: the *i*-th among them contains an integer *m**i* (1<=≤<=*m**i*<=≤<=*n*) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter *c**i* — Koyomi's possible favourite colour.
Output *q* lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.
[ "6\nkoyomi\n3\n1 o\n4 o\n4 m\n", "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n", "10\naaaaaaaaaa\n2\n10 b\n10 z\n" ]
[ "3\n6\n5\n", "3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n", "10\n10\n" ]
In the first sample, there are three plans: - In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; - In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; - In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.
1,750
[ { "input": "6\nkoyomi\n3\n1 o\n4 o\n4 m", "output": "3\n6\n5" }, { "input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b", "output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5" }, { "input": "10\naaaaaaaaaa\n2\n10 b\n10 z", "output": "10\n10" }, { "input": "1\nc\n4\n1 x\n1 a\n1 e\n1 t", "output": "1\n1\n1\n1" }, { "input": "20\naaaaaaaaaaaaaaaaaaaa\n1\n11 a", "output": "20" }, { "input": "4\ncbcc\n12\n4 b\n4 c\n1 b\n2 a\n3 b\n2 c\n4 a\n1 a\n2 b\n3 a\n1 c\n3 c", "output": "4\n4\n2\n2\n4\n4\n4\n1\n3\n3\n4\n4" }, { "input": "4\nddbb\n16\n3 c\n3 b\n1 a\n1 b\n4 d\n4 a\n3 d\n2 a\n2 d\n4 c\n3 a\n2 c\n4 b\n1 c\n2 b\n1 d", "output": "3\n4\n1\n3\n4\n4\n4\n2\n4\n4\n3\n2\n4\n1\n4\n3" }, { "input": "4\nabcc\n24\n1 c\n4 d\n3 c\n1 d\n1 c\n1 b\n3 b\n2 c\n3 d\n3 d\n4 c\n2 a\n4 d\n1 a\n1 b\n4 a\n4 d\n3 b\n4 b\n3 c\n3 a\n2 d\n1 a\n2 b", "output": "3\n4\n4\n1\n3\n2\n4\n4\n3\n3\n4\n3\n4\n2\n2\n4\n4\n4\n4\n4\n4\n2\n2\n3" }, { "input": "40\ncbbcbcccccacccccbbacbaabccbbabbaaaaacccc\n10\n40 a\n28 c\n25 c\n21 a\n18 c\n27 a\n9 c\n37 c\n15 a\n18 b", "output": "40\n40\n40\n31\n35\n37\n23\n40\n24\n27" }, { "input": "100\ndddddccccdddddaaaaabbbbbbbbbbbbbaaacdcabbacccacccccbdbbadddbbddddbdaaccacdddbbbaddddbbbbdcbbbdddddda\n50\n54 b\n48 d\n45 b\n52 c\n52 a\n48 a\n54 b\n45 a\n47 d\n50 d\n53 a\n34 a\n51 b\n48 d\n47 d\n47 a\n48 d\n53 b\n52 d\n54 d\n46 a\n38 a\n52 b\n49 a\n49 b\n46 c\n54 a\n45 b\n35 c\n55 c\n51 c\n46 d\n54 d\n50 a\n33 c\n46 a\n50 b\n50 a\n54 a\n32 b\n55 b\n49 c\n53 d\n49 a\n46 b\n48 c\n47 b\n47 b\n47 a\n46 b", "output": "85\n72\n76\n69\n68\n63\n85\n60\n71\n74\n69\n46\n82\n72\n71\n62\n72\n84\n76\n78\n61\n50\n83\n64\n80\n60\n70\n76\n49\n72\n68\n70\n78\n66\n47\n61\n81\n66\n70\n53\n86\n63\n77\n64\n77\n62\n78\n78\n62\n77" }, { "input": "200\nddeecdbbbeeeeebbbbbaaaaaaaaaaaaaaaaaaaaaaabbcaacccbeeeeddddddddddddccccccdffeeeeecccccbbbbaaaaedfffffaadeeeeeeeedddddaaaaaaaaaaaaaabbbbbcaadddeefffbbbbcccccccccccbbbbbbeeeeeeeffffffdffffffffffffaaaaab\n10\n43 f\n118 d\n165 f\n72 f\n48 f\n2 a\n61 e\n94 d\n109 f\n16 a", "output": "64\n144\n193\n98\n69\n25\n79\n117\n137\n41" }, { "input": "5\naaaaa\n1\n1 b", "output": "1" } ]
1,499,701,361
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
46
5,529,600
def im(i=None): if not i: i = input() if i.isdigit(): return int(i) else: return map(int, i.split(' ')) n = int(input()) s = input() q = int(input()) smb = {} for c in set(s): smb[c] = [0]*n i = 0 while i < n: repl_cnt = 0 j = i while j < n: if s[j] != c: repl_cnt += 1 smb[c][repl_cnt] = max(smb[c][repl_cnt], j-i+1) j += 1 i += 1 for i in range(1, n): smb[c][i] = max(smb[c][i], smb[c][i-1]) for _ in range(q): buf = input().split(' ') m = int(buf[0]) c = buf[1] if c not in smb: print(m) else: print(smb[c][m])
Title: An impassioned circulation of affection Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* from left to right, and the *i*-th piece has a colour *s**i*, denoted by a lowercase English letter. Nadeko will repaint at most *m* of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour *c* — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland. For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3. But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has *q* plans on this, each of which can be expressed as a pair of an integer *m**i* and a lowercase letter *c**i*, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan. Input Specification: The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=500) — the length of the garland. The second line contains *n* lowercase English letters *s*1*s*2... *s**n* as a string — the initial colours of paper pieces on the garland. The third line contains a positive integer *q* (1<=≤<=*q*<=≤<=200<=000) — the number of plans Nadeko has. The next *q* lines describe one plan each: the *i*-th among them contains an integer *m**i* (1<=≤<=*m**i*<=≤<=*n*) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter *c**i* — Koyomi's possible favourite colour. Output Specification: Output *q* lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it. Demo Input: ['6\nkoyomi\n3\n1 o\n4 o\n4 m\n', '15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n', '10\naaaaaaaaaa\n2\n10 b\n10 z\n'] Demo Output: ['3\n6\n5\n', '3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n', '10\n10\n'] Note: In the first sample, there are three plans: - In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; - In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; - In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.
```python def im(i=None): if not i: i = input() if i.isdigit(): return int(i) else: return map(int, i.split(' ')) n = int(input()) s = input() q = int(input()) smb = {} for c in set(s): smb[c] = [0]*n i = 0 while i < n: repl_cnt = 0 j = i while j < n: if s[j] != c: repl_cnt += 1 smb[c][repl_cnt] = max(smb[c][repl_cnt], j-i+1) j += 1 i += 1 for i in range(1, n): smb[c][i] = max(smb[c][i], smb[c][i-1]) for _ in range(q): buf = input().split(' ') m = int(buf[0]) c = buf[1] if c not in smb: print(m) else: print(smb[c][m]) ```
-1
519
A
A and B and Chess
PROGRAMMING
900
[ "implementation" ]
null
null
A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board. As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
[ "...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n" ]
[ "White\n", "Draw\n", "Black\n" ]
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5. In the second test sample the weights of the positions of the black and the white pieces are equal to 39. In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
500
[ { "input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "output": "Draw" }, { "input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..", "output": "White" }, { "input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\n..K..rNn\nP.....p.\n...Q..B.", "output": "White" }, { "input": "...Nn...\n........\n........\n........\n.R....b.\n........\n........\n......p.", "output": "White" }, { "input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq", "output": "Black" }, { "input": "QQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ", "output": "White" }, { "input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ", "output": "Draw" }, { "input": "QQQQQQQQ\nQQQQQQQQ\n........\n........\n........\n........\nrrrrrr..\nrrrrrrrr", "output": "White" }, { "input": "........\n........\n........\n........\n........\n........\n........\n.......n", "output": "Black" }, { "input": "........\n...b....\n........\n........\n........\n........\n........\n.......K", "output": "Black" }, { "input": "........\n........\n........\n........\n........\n........\n........\n......Kp", "output": "Black" }, { "input": "........\n........\n........\n........\n........\n........\n........\n.......Q", "output": "White" }, { "input": "........\n........\n........\n........\n........\n........\n........\n......Bp", "output": "White" }, { "input": "........\n........\n........\n........\n........\n........\n........\nkkkkkB..", "output": "White" }, { "input": "QqPQNN.Q\n.qBbr.qB\np.RKBpNK\nPknBr.nq\nKqKRNKKk\n.BqPqkb.\nPBNPr.rk\nBpBKrPRR", "output": "Black" }, { "input": "........\n........\n........\n........\n........\n........\n........\n.......K", "output": "Draw" } ]
1,668,531,253
2,147,483,647
PyPy 3-64
OK
TESTS
65
61
0
w=b=0 for i in range(8): s=input() for j in s: if j!=".": if j=="p": b+=1 elif j=="n": b+=3 elif j=="b": b+=3 elif j=="r": b+=5 elif j=="q": b+=9 elif j=="P": w+=1 elif j=="N": w+=3 elif j=="B": w+=3 elif j=="R": w+=5 elif j=="Q": w+=9 if w<b: print("Black") elif w==b: print("Draw") else : print("White")
Title: A and B and Chess Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board. As A doesn't like counting, he asked you to help him determine which player has the larger position weight. Input Specification: The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on. Output Specification: Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. Demo Input: ['...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n', 'rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n', 'rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n'] Demo Output: ['White\n', 'Draw\n', 'Black\n'] Note: In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5. In the second test sample the weights of the positions of the black and the white pieces are equal to 39. In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
```python w=b=0 for i in range(8): s=input() for j in s: if j!=".": if j=="p": b+=1 elif j=="n": b+=3 elif j=="b": b+=3 elif j=="r": b+=5 elif j=="q": b+=9 elif j=="P": w+=1 elif j=="N": w+=3 elif j=="B": w+=3 elif j=="R": w+=5 elif j=="Q": w+=9 if w<b: print("Black") elif w==b: print("Draw") else : print("White") ```
3
414
B
Mashmokh and ACM
PROGRAMMING
1,400
[ "combinatorics", "dp", "number theory" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
1,000
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" }, { "input": "680 1091", "output": "351905328" }, { "input": "1229 1315", "output": "100240813" }, { "input": "1766 1038", "output": "435768250" }, { "input": "1000 1", "output": "1000" }, { "input": "2000 100", "output": "983281065" }, { "input": "1 1", "output": "1" }, { "input": "2000 1000", "output": "228299266" }, { "input": "1928 1504", "output": "81660104" }, { "input": "2000 2000", "output": "585712681" }, { "input": "29 99", "output": "23125873" }, { "input": "56 48", "output": "20742237" }, { "input": "209 370", "output": "804680894" }, { "input": "83 37", "output": "22793555" }, { "input": "49 110", "output": "956247348" }, { "input": "217 3", "output": "4131" }, { "input": "162 161", "output": "591739753" }, { "input": "273 871", "output": "151578252" }, { "input": "43 1640", "output": "173064407" }, { "input": "1472 854", "output": "748682383" }, { "input": "1639 1056", "output": "467464129" }, { "input": "359 896", "output": "770361185" }, { "input": "1544 648", "output": "9278889" }, { "input": "436 1302", "output": "874366220" }, { "input": "1858 743", "output": "785912917" }, { "input": "991 1094", "output": "483493131" }, { "input": "1013 1550", "output": "613533467" }, { "input": "675 741", "output": "474968598" }, { "input": "1420 1223", "output": "922677437" }, { "input": "1544 1794", "output": "933285446" }, { "input": "1903 1612", "output": "620810276" }, { "input": "500 1304", "output": "706176027" }, { "input": "525 314", "output": "245394744" }, { "input": "39 1930", "output": "992125404" }, { "input": "1895 753", "output": "180474828" }, { "input": "1722 1474", "output": "742424590" }, { "input": "1153 1823", "output": "791493066" }, { "input": "1409 734", "output": "627413973" }, { "input": "478 1301", "output": "476483030" }, { "input": "1887 1729", "output": "730033374" }, { "input": "1610 774", "output": "50897314" }, { "input": "1770 679", "output": "235295539" }, { "input": "987 1292", "output": "560110556" }, { "input": "1707 1117", "output": "237674323" }, { "input": "1424 1431", "output": "184145444" }, { "input": "86 1078", "output": "252515343" }, { "input": "1066 995", "output": "180753612" }, { "input": "1024 133", "output": "392603027" }, { "input": "659 974", "output": "397026719" }, { "input": "1349 1606", "output": "522392901" }, { "input": "473 211", "output": "809550224" }, { "input": "634 1825", "output": "438513382" }, { "input": "22 373", "output": "907321755" }, { "input": "531 147", "output": "242883376" }, { "input": "1307 1247", "output": "21512331" }, { "input": "415 735", "output": "393705804" }, { "input": "1659 1501", "output": "225266660" }, { "input": "1454 296", "output": "750032659" }, { "input": "158 772", "output": "850911301" }, { "input": "2000 1", "output": "2000" } ]
1,655,192,910
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
# import sys import pyrival.misc @pyrival.misc.bootstrap a,b=list(map(int,input().split())) g={} for i in range(1,a+1): g[i]=[] c=1 while i*c<a+1: g[i].append(i*c) c=c+1 #print(g) # sys.setrecursionlimit(10**7) h={} def recr(val,ind): if (val,ind) in h: yield h[(val,ind)] if ind==b: yield 1 ans=0 for i in g[val]: if i%val==0: ans=ans+recr(i,ind+1) h[(val,ind)]=ans yield ans print(recr(1,0)%(10**9+7))
Title: Mashmokh and ACM Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7). Input Specification: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). Output Specification: Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). Demo Input: ['3 2\n', '6 4\n', '2 1\n'] Demo Output: ['5\n', '39\n', '2\n'] Note: In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
```python # import sys import pyrival.misc @pyrival.misc.bootstrap a,b=list(map(int,input().split())) g={} for i in range(1,a+1): g[i]=[] c=1 while i*c<a+1: g[i].append(i*c) c=c+1 #print(g) # sys.setrecursionlimit(10**7) h={} def recr(val,ind): if (val,ind) in h: yield h[(val,ind)] if ind==b: yield 1 ans=0 for i in g[val]: if i%val==0: ans=ans+recr(i,ind+1) h[(val,ind)]=ans yield ans print(recr(1,0)%(10**9+7)) ```
-1
372
A
Counting Kangaroos is Fun
PROGRAMMING
1,600
[ "binary search", "greedy", "sortings", "two pointers" ]
null
null
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
Output a single integer — the optimal number of visible kangaroos.
[ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n" ]
[ "5\n", "5\n" ]
none
500
[ { "input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5" }, { "input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5" }, { "input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52", "output": "7" }, { "input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9", "output": "6" }, { "input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76", "output": "58" }, { "input": "100\n154\n60\n97\n638\n139\n150\n570\n579\n601\n647\n804\n237\n245\n549\n288\n347\n778\n282\n916\n441\n974\n145\n957\n886\n655\n702\n930\n618\n132\n520\n972\n48\n94\n54\n682\n433\n896\n134\n845\n636\n242\n842\n125\n141\n240\n130\n409\n666\n948\n938\n604\n110\n474\n484\n364\n40\n807\n271\n438\n288\n201\n814\n754\n589\n341\n576\n146\n952\n819\n923\n222\n535\n336\n83\n314\n911\n303\n911\n384\n601\n249\n330\n735\n271\n142\n204\n405\n783\n775\n449\n590\n139\n109\n276\n45\n205\n454\n836\n82\n841", "output": "50" }, { "input": "1\n1", "output": "1" }, { "input": "4\n1\n1\n1\n2", "output": "3" }, { "input": "5\n1\n2\n4\n8\n16", "output": "3" }, { "input": "7\n1\n2\n4\n8\n16\n32\n64", "output": "4" }, { "input": "3\n1\n2\n4", "output": "2" } ]
1,670,564,465
2,147,483,647
Python 3
OK
TESTS
45
623
12,288,000
import sys, math n=int(input()) a=sorted(int(x) for x in sys.stdin) i=(n//2)-1 j=n-1 k=0 while j>((n//2)-1) and i>=0: if 2*a[i]<=a[j]: j-=1 k+=1 i-=1 #print(a) print(n-k)
Title: Counting Kangaroos is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input Specification: The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). Output Specification: Output a single integer — the optimal number of visible kangaroos. Demo Input: ['8\n2\n5\n7\n6\n9\n8\n4\n2\n', '8\n9\n1\n6\n2\n6\n5\n8\n3\n'] Demo Output: ['5\n', '5\n'] Note: none
```python import sys, math n=int(input()) a=sorted(int(x) for x in sys.stdin) i=(n//2)-1 j=n-1 k=0 while j>((n//2)-1) and i>=0: if 2*a[i]<=a[j]: j-=1 k+=1 i-=1 #print(a) print(n-k) ```
3
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
1,512,550,052
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
11,059,200
n=int(input()) number=list(map(int,input().split( ))) number.sort() toastman=sum(number) for i in range(len(number)-1): toastman+=sum(number[i:len(number)]) print(toastman)
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()) number=list(map(int,input().split( ))) number.sort() toastman=sum(number) for i in range(len(number)-1): toastman+=sum(number[i:len(number)]) print(toastman) ```
0
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result. Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input": "2\n01", "output": "0" }, { "input": "2\n10", "output": "0" }, { "input": "2\n11", "output": "2" }, { "input": "3\n001", "output": "1" }, { "input": "6\n110110", "output": "2" }, { "input": "7\n0000011", "output": "3" }, { "input": "6\n110010", "output": "0" }, { "input": "6\n110100", "output": "0" }, { "input": "3\n100", "output": "1" }, { "input": "6\n010111", "output": "2" }, { "input": "8\n01011100", "output": "0" }, { "input": "6\n001011", "output": "0" }, { "input": "7\n1110000", "output": "1" }, { "input": "9\n011111101", "output": "5" } ]
1,632,950,373
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
46
0
def main(): n = int(input()) s = list(input()) i = 0 c = 0 while c == 0 and i < len(s)-1: if len(s)==1 or s.count(0)==0 or s.count(1==0): break if s[i] == "1": if s[i + 1] == "0": s = s[:i] + s[i + 1 + 1:] i = 0 else: i = i + 1 elif s[i] == "0": if s[i + 1] == "1": s = s[:i] + s[i + 1 + 1:] i = 0 else: i = i + 1 print(len(s)) if __name__ == '__main__': main()
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result. Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. Input Specification: First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones. Output Specification: Output the minimum length of the string that may remain after applying the described operations several times. Demo Input: ['4\n1100\n', '5\n01010\n', '8\n11101111\n'] Demo Output: ['0\n', '1\n', '6\n'] Note: In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python def main(): n = int(input()) s = list(input()) i = 0 c = 0 while c == 0 and i < len(s)-1: if len(s)==1 or s.count(0)==0 or s.count(1==0): break if s[i] == "1": if s[i + 1] == "0": s = s[:i] + s[i + 1 + 1:] i = 0 else: i = i + 1 elif s[i] == "0": if s[i + 1] == "1": s = s[:i] + s[i + 1 + 1:] i = 0 else: i = i + 1 print(len(s)) if __name__ == '__main__': main() ```
0
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,660,629,991
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
s = int(input()) t = int(input()) print(s^t)
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 s = int(input()) t = int(input()) print(s^t) ```
0
17
D
Notepad
PROGRAMMING
2,400
[ "number theory" ]
D. Notepad
2
64
Nick is attracted by everything unconventional. He doesn't like decimal number system any more, and he decided to study other number systems. A number system with base *b* caught his attention. Before he starts studying it, he wants to write in his notepad all the numbers of length *n* without leading zeros in this number system. Each page in Nick's notepad has enough space for *c* numbers exactly. Nick writes every suitable number only once, starting with the first clean page and leaving no clean spaces. Nick never writes number 0 as he has unpleasant memories about zero divide. Would you help Nick find out how many numbers will be written on the last page.
The only input line contains three space-separated integers *b*, *n* and *c* (2<=≤<=*b*<=&lt;<=10106, 1<=≤<=*n*<=&lt;<=10106, 1<=≤<=*c*<=≤<=109). You may consider that Nick has infinite patience, endless amount of paper and representations of digits as characters. The numbers doesn't contain leading zeros.
In the only line output the amount of numbers written on the same page as the last number.
[ "2 3 3\n", "2 3 4\n" ]
[ "1", "4" ]
In both samples there are exactly 4 numbers of length 3 in binary number system. In the first sample Nick writes 3 numbers on the first page and 1 on the second page. In the second sample all the 4 numbers can be written on the first page.
0
[ { "input": "2 3 3", "output": "1" }, { "input": "2 3 4", "output": "4" }, { "input": "9 1 79", "output": "8" }, { "input": "9 1 345", "output": "8" }, { "input": "9 9 999982045", "output": "344373768" }, { "input": "4 42 44", "output": "12" }, { "input": "6 43 659", "output": "365" }, { "input": "8 54 999992388", "output": "741886148" }, { "input": "861 11 17", "output": "14" }, { "input": "89 34 119", "output": "80" }, { "input": "84 67 999993310", "output": "829809148" }, { "input": "9219 537 98", "output": "98" }, { "input": "763 582 510", "output": "96" }, { "input": "6355 60160 999982994", "output": "904671182" }, { "input": "396882961 9936448 752", "output": "528" }, { "input": "394292559875270 34297300532732 28", "output": "28" }, { "input": "8523703220091 953421047275844 163", "output": "30" }, { "input": "713030357739784847 61197710123555584 999992531", "output": "207016405" }, { "input": "75903940600326238527 492179977057716178 954", "output": "450" }, { "input": "8085477143815539692925721 57241684823084777591460 968", "output": "304" }, { "input": "67609394386924890416446 78162115935271414671181267 999987217", "output": "926946271" }, { "input": "3351262437484130462277638791970372162118802730187825044167229944871677684706592699530322737272222086076517455404652584348 147310576952932829345029460612849431175622785231399764423717734155248977073541821053441627535488066058597900989095431439 999998948", "output": "930694076" }, { "input": "61063034544457239668509642598956869508193198481915116469015956878854905975766584002919896320353661294612971855029955483257741525207429239630069409321331850413146512850720681578339422084340720535114848966742045420860633093949996367883 965415513080902927493169838825380834798188421277961155726185690857844534367611949025561401481462737822765050755128163519122172969767981851117402342816829930821131453945898813517587656899608854645391515043085723743408226445117376493281975889755859761322184701256801 999998603", "output": "60342257" }, { "input": "9 1000000000000000000000000000000000000000000000000000000 345", "output": "192" }, { "input": "8053063680000000000000000000000000002 268435456000000000000005 805306368", "output": "268435456" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000025 805306368", "output": "268435456" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000026 805306368", "output": "536870912" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000027 805306368", "output": "268435456" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000028 805306368", "output": "536870912" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000029 805306368", "output": "268435456" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000030 805306368", "output": "536870912" }, { "input": "8053063680000000000000000000000000002 2684354560000000000000031 805306368", "output": "268435456" }, { "input": "2271048430505293080737093330373572593316324321603522463486966273671353266974713306925326907468317965879775893196923719457524955744 8990615363653447573832140957083458603886706189959668013719622351914533208654357508127820477597609318856255372184258450991108060161 53727872", "output": "26470400" }, { "input": "244741007655429712 1 297825872", "output": "297825871" } ]
1,548,888,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
0
def gcd(a, b): if (a == 0): return b return gcd(b % a, a) def phi(n): result = 1 for i in range(2, n): if (gcd(i, n) == 1): result+=1 return result [b,n,c] = [int(k) for k in input().split(' ')] result = (pow(b%c,(n-1) % phi(c),c) * ((b-1) % c)) % c if result == 0: print(c) else: print(result)
Title: Notepad Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is attracted by everything unconventional. He doesn't like decimal number system any more, and he decided to study other number systems. A number system with base *b* caught his attention. Before he starts studying it, he wants to write in his notepad all the numbers of length *n* without leading zeros in this number system. Each page in Nick's notepad has enough space for *c* numbers exactly. Nick writes every suitable number only once, starting with the first clean page and leaving no clean spaces. Nick never writes number 0 as he has unpleasant memories about zero divide. Would you help Nick find out how many numbers will be written on the last page. Input Specification: The only input line contains three space-separated integers *b*, *n* and *c* (2<=≤<=*b*<=&lt;<=10106, 1<=≤<=*n*<=&lt;<=10106, 1<=≤<=*c*<=≤<=109). You may consider that Nick has infinite patience, endless amount of paper and representations of digits as characters. The numbers doesn't contain leading zeros. Output Specification: In the only line output the amount of numbers written on the same page as the last number. Demo Input: ['2 3 3\n', '2 3 4\n'] Demo Output: ['1', '4'] Note: In both samples there are exactly 4 numbers of length 3 in binary number system. In the first sample Nick writes 3 numbers on the first page and 1 on the second page. In the second sample all the 4 numbers can be written on the first page.
```python def gcd(a, b): if (a == 0): return b return gcd(b % a, a) def phi(n): result = 1 for i in range(2, n): if (gcd(i, n) == 1): result+=1 return result [b,n,c] = [int(k) for k in input().split(' ')] result = (pow(b%c,(n-1) % phi(c),c) * ((b-1) % c)) % c if result == 0: print(c) else: print(result) ```
0
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,609,697,388
2,147,483,647
Python 3
OK
TESTS
34
216
0
n = int(input()) l = [input() for _ in range(n)] a = l[:] a = list(set(a)) save = [] for items in a: save.append(l.count(items)) for c in l: if max(save)==l.count(c): print(c) break
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) l = [input() for _ in range(n)] a = l[:] a = list(set(a)) save = [] for items in a: save.append(l.count(items)) for c in l: if max(save)==l.count(c): print(c) break ```
3.946
682
A
Alyona and Numbers
PROGRAMMING
1,100
[ "constructive algorithms", "math", "number theory" ]
null
null
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5. Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0. As usual, Alyona has some troubles and asks you to help.
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000).
Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5.
[ "6 12\n", "11 14\n", "1 5\n", "3 8\n", "5 7\n", "21 21\n" ]
[ "14\n", "31\n", "1\n", "5\n", "7\n", "88\n" ]
Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case.
500
[ { "input": "6 12", "output": "14" }, { "input": "11 14", "output": "31" }, { "input": "1 5", "output": "1" }, { "input": "3 8", "output": "5" }, { "input": "5 7", "output": "7" }, { "input": "21 21", "output": "88" }, { "input": "10 15", "output": "30" }, { "input": "1 1", "output": "0" }, { "input": "1 1000000", "output": "200000" }, { "input": "1000000 1", "output": "200000" }, { "input": "1000000 1000000", "output": "200000000000" }, { "input": "944 844", "output": "159348" }, { "input": "368 984", "output": "72423" }, { "input": "792 828", "output": "131155" }, { "input": "920 969", "output": "178296" }, { "input": "640 325", "output": "41600" }, { "input": "768 170", "output": "26112" }, { "input": "896 310", "output": "55552" }, { "input": "320 154", "output": "9856" }, { "input": "744 999", "output": "148652" }, { "input": "630 843", "output": "106218" }, { "input": "54 688", "output": "7431" }, { "input": "478 828", "output": "79157" }, { "input": "902 184", "output": "33194" }, { "input": "31 29", "output": "180" }, { "input": "751 169", "output": "25384" }, { "input": "879 14", "output": "2462" }, { "input": "7 858", "output": "1201" }, { "input": "431 702", "output": "60512" }, { "input": "855 355", "output": "60705" }, { "input": "553 29", "output": "3208" }, { "input": "721767 525996", "output": "75929310986" }, { "input": "805191 74841", "output": "12052259926" }, { "input": "888615 590981", "output": "105030916263" }, { "input": "4743 139826", "output": "132638943" }, { "input": "88167 721374", "output": "12720276292" }, { "input": "171591 13322", "output": "457187060" }, { "input": "287719 562167", "output": "32349225415" }, { "input": "371143 78307", "output": "5812618980" }, { "input": "487271 627151", "output": "61118498984" }, { "input": "261436 930642", "output": "48660664382" }, { "input": "377564 446782", "output": "33737759810" }, { "input": "460988 28330", "output": "2611958008" }, { "input": "544412 352983", "output": "38433636199" }, { "input": "660540 869123", "output": "114818101284" }, { "input": "743964 417967", "output": "62190480238" }, { "input": "827388 966812", "output": "159985729411" }, { "input": "910812 515656", "output": "93933134534" }, { "input": "26940 64501", "output": "347531388" }, { "input": "110364 356449", "output": "7867827488" }, { "input": "636358 355531", "output": "45248999219" }, { "input": "752486 871672", "output": "131184195318" }, { "input": "803206 420516", "output": "67552194859" }, { "input": "919334 969361", "output": "178233305115" }, { "input": "35462 261309", "output": "1853307952" }, { "input": "118887 842857", "output": "20040948031" }, { "input": "202311 358998", "output": "14525848875" }, { "input": "285735 907842", "output": "51880446774" }, { "input": "401863 456686", "output": "36705041203" }, { "input": "452583 972827", "output": "88056992428" }, { "input": "235473 715013", "output": "33673251230" }, { "input": "318897 263858", "output": "16828704925" }, { "input": "402321 812702", "output": "65393416268" }, { "input": "518449 361546", "output": "37488632431" }, { "input": "634577 910391", "output": "115542637921" }, { "input": "685297 235043", "output": "32214852554" }, { "input": "801425 751183", "output": "120403367155" }, { "input": "884849 300028", "output": "53095895155" }, { "input": "977 848872", "output": "165869588" }, { "input": "51697 397716", "output": "4112144810" }, { "input": "834588 107199", "output": "17893399803" }, { "input": "918012 688747", "output": "126455602192" }, { "input": "1436 237592", "output": "68236422" }, { "input": "117564 753732", "output": "17722349770" }, { "input": "200988 302576", "output": "12162829017" }, { "input": "284412 818717", "output": "46570587880" }, { "input": "400540 176073", "output": "14104855884" }, { "input": "483964 724917", "output": "70166746198" }, { "input": "567388 241058", "output": "27354683301" }, { "input": "650812 789902", "output": "102815540084" }, { "input": "400999 756281", "output": "60653584944" }, { "input": "100 101", "output": "2020" }, { "input": "100 102", "output": "2040" }, { "input": "103 100", "output": "2060" }, { "input": "100 104", "output": "2080" }, { "input": "3 4", "output": "3" }, { "input": "11 23", "output": "50" }, { "input": "8 14", "output": "23" }, { "input": "23423 34234", "output": "160372597" }, { "input": "1 4", "output": "1" }, { "input": "999999 999999", "output": "199999600001" }, { "input": "82 99", "output": "1624" }, { "input": "21 18", "output": "75" }, { "input": "234 234", "output": "10952" }, { "input": "4 4", "output": "4" }, { "input": "6 13", "output": "15" }, { "input": "3 9", "output": "6" }, { "input": "99999 99999", "output": "1999960001" }, { "input": "34 33", "output": "225" }, { "input": "2 2", "output": "0" }, { "input": "333 1", "output": "66" }, { "input": "3 3", "output": "2" }, { "input": "8 2", "output": "3" }, { "input": "2179 2218", "output": "966605" }, { "input": "1000000 999999", "output": "199999800000" }, { "input": "873828 774207", "output": "135304750879" }, { "input": "13 19", "output": "50" }, { "input": "1648 576469", "output": "190004183" }, { "input": "11 13", "output": "28" }, { "input": "5 8", "output": "8" }, { "input": "650074 943659", "output": "122689636154" }, { "input": "1 3", "output": "0" }, { "input": "54 43", "output": "465" }, { "input": "14 9", "output": "26" }, { "input": "2 3", "output": "1" }, { "input": "543 534", "output": "57993" }, { "input": "321 123", "output": "7896" }, { "input": "21 3", "output": "12" }, { "input": "2 1", "output": "0" }, { "input": "4 3", "output": "3" }, { "input": "47474 74747", "output": "709707816" }, { "input": "4 9", "output": "8" }, { "input": "7 4", "output": "6" }, { "input": "9 4", "output": "8" }, { "input": "12414 4214", "output": "10462520" }, { "input": "2 9", "output": "4" }, { "input": "253 821", "output": "41542" }, { "input": "2 4", "output": "2" } ]
1,573,251,340
2,147,483,647
Python 3
OK
TESTS
128
608
0
def inp(): return map(int, input().split()) def fill_arr(n): return [0 for x in range(n)] x, y = inp() a, b = fill_arr(5), fill_arr(5) for i in range(1, x + 1): a[i % 5] += 1 for i in range(1, y + 1): b[i % 5] += 1 sum = a[0] * b[0] for i in range(1,5): sum += a[i] * b[5 - i] print(sum)
Title: Alyona and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5. Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0. As usual, Alyona has some troubles and asks you to help. Input Specification: The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). Output Specification: Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. Demo Input: ['6 12\n', '11 14\n', '1 5\n', '3 8\n', '5 7\n', '21 21\n'] Demo Output: ['14\n', '31\n', '1\n', '5\n', '7\n', '88\n'] Note: Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case.
```python def inp(): return map(int, input().split()) def fill_arr(n): return [0 for x in range(n)] x, y = inp() a, b = fill_arr(5), fill_arr(5) for i in range(1, x + 1): a[i % 5] += 1 for i in range(1, y + 1): b[i % 5] += 1 sum = a[0] * b[0] for i in range(1,5): sum += a[i] * b[5 - i] print(sum) ```
3
437
A
The Child and Homework
PROGRAMMING
1,300
[ "implementation" ]
null
null
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: - If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose?
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
[ "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n", "A.ab\nB.abcde\nC.ab\nD.abc\n", "A.c\nB.cc\nC.c\nD.c\n" ]
[ "D\n", "C\n", "B\n" ]
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D. In the second sample, no choice is great, so the child will choose the luckiest choice C. In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
500
[ { "input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "output": "D" }, { "input": "A.ab\nB.abcde\nC.ab\nD.abc", "output": "C" }, { "input": "A.c\nB.cc\nC.c\nD.c", "output": "B" }, { "input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a", "output": "C" }, { "input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____", "output": "C" }, { "input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_", "output": "D" }, { "input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____", "output": "C" }, { "input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_", "output": "D" }, { "input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h", "output": "A" }, { "input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_", "output": "C" }, { "input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg", "output": "B" }, { "input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___", "output": "D" }, { "input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS", "output": "C" }, { "input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_", "output": "C" }, { "input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi", "output": "C" }, { "input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__", "output": "C" }, { "input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h", "output": "A" }, { "input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_", "output": "C" }, { "input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg", "output": "B" }, { "input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___", "output": "D" }, { "input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS", "output": "C" }, { "input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_", "output": "C" }, { "input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi", "output": "C" }, { "input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__", "output": "C" }, { "input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa", "output": "A" }, { "input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa", "output": "A" }, { "input": "A.a\nB.b\nC.c\nD.d", "output": "C" }, { "input": "A._\nB.__\nC.____\nD.________", "output": "C" }, { "input": "A.____\nB.________\nC.________\nD._______", "output": "C" }, { "input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg", "output": "C" }, { "input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa", "output": "C" }, { "input": "A.ccc\nB.ccccccc\nC.ccc\nD.c", "output": "C" }, { "input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc", "output": "C" }, { "input": "A.aa\nB.bb\nC.cc\nD.ddd", "output": "C" }, { "input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI", "output": "C" } ]
1,568,778,401
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; struct ppp{ string h;int len; }ln[5]; bool comp(ppp a,ppp b) { return a.len<b.len; } char ttt='9',yyy='9'; int main() { for(int i=1;i<=4;i++) { cin>>ln[i].h; ln[i].len=ln[i].h.size()-2; } sort(ln+1,ln+5,comp); if(ln[1].len<=ln[2].len/2)ttt=ln[1].h[0]; if(ln[4].len>=ln[3].len*2)yyy=ln[4].h[0]; if(ttt==yyy||ttt>='A'&&ttt<='D'&&yyy>='A'&&yyy<='D')printf("C"); else if(ttt=='9')putchar(yyy); else putchar(ttt); return 0; }
Title: The Child and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: - If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose? Input Specification: The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". Output Specification: Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). Demo Input: ['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n'] Demo Output: ['D\n', 'C\n', 'B\n'] Note: In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D. In the second sample, no choice is great, so the child will choose the luckiest choice C. In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
```python #include<bits/stdc++.h> using namespace std; struct ppp{ string h;int len; }ln[5]; bool comp(ppp a,ppp b) { return a.len<b.len; } char ttt='9',yyy='9'; int main() { for(int i=1;i<=4;i++) { cin>>ln[i].h; ln[i].len=ln[i].h.size()-2; } sort(ln+1,ln+5,comp); if(ln[1].len<=ln[2].len/2)ttt=ln[1].h[0]; if(ln[4].len>=ln[3].len*2)yyy=ln[4].h[0]; if(ttt==yyy||ttt>='A'&&ttt<='D'&&yyy>='A'&&yyy<='D')printf("C"); else if(ttt=='9')putchar(yyy); else putchar(ttt); return 0; } ```
-1
818
D
Multicolored Cars
PROGRAMMING
1,700
[ "data structures", "implementation" ]
null
null
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another. The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after *i*-th car *cnt**A*(*i*) and *cnt**B*(*i*). - If *cnt**A*(*i*)<=&gt;<=*cnt**B*(*i*) for every *i* then the winner is Alice. - If *cnt**B*(*i*)<=≥<=*cnt**A*(*i*) for every *i* then the winner is Bob. - Otherwise it's a draw. Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color *A* and Bob now wants to choose such color *B* that he will win the game (draw is not a win). Help him find this color. If there are multiple solutions, print any of them. If there is no such color then print -1.
The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice. The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their appearance.
Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1. It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106).
[ "4 1\n2 1 4 2\n", "5 2\n2 2 4 5 3\n", "3 10\n1 2 3\n" ]
[ "2\n", "-1\n", "4\n" ]
Let's consider availability of colors in the first example: - *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) &lt; *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning one for Bob. - All the other colors also have *cnt*<sub class="lower-index">*j*</sub>(2) &lt; *cnt*<sub class="lower-index">1</sub>(2), thus they are not available. In the third example every color is acceptable except for 10.
0
[ { "input": "4 1\n2 1 4 2", "output": "2" }, { "input": "5 2\n2 2 4 5 3", "output": "-1" }, { "input": "3 10\n1 2 3", "output": "4" }, { "input": "1 1\n2", "output": "3" }, { "input": "1 2\n2", "output": "-1" }, { "input": "10 6\n8 5 1 6 6 5 10 6 9 8", "output": "-1" }, { "input": "7 2\n1 2 2 1 1 1 1", "output": "-1" }, { "input": "8 2\n1 1 3 2 3 2 3 2", "output": "3" }, { "input": "10 9\n6 4 7 1 8 9 5 9 4 5", "output": "-1" }, { "input": "6 1\n2 3 3 1 1 2", "output": "3" }, { "input": "4 1\n2 1 1 2", "output": "-1" }, { "input": "5 1\n3 2 1 2 1", "output": "2" }, { "input": "5 3\n1 2 3 2 3", "output": "2" }, { "input": "1 1000000\n1", "output": "2" }, { "input": "6 3\n1 2 3 2 3 2", "output": "2" }, { "input": "3 2\n1 2 3", "output": "1" }, { "input": "6 2\n5 3 2 4 4 2", "output": "-1" }, { "input": "6 1\n5 2 1 4 2 1", "output": "2" }, { "input": "6 1\n2 2 2 1 1 1", "output": "2" }, { "input": "5 2\n3 1 1 2 2", "output": "1" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "30 1\n2 2 2 2 2 3 3 3 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 1 1 1", "output": "2" }, { "input": "2 1\n1 2", "output": "-1" }, { "input": "5 3\n1 2 2 3 3", "output": "2" }, { "input": "10 1000000\n1 2 3 4 5 6 7 8 9 10", "output": "11" }, { "input": "6 1\n3 1 2 2 3 1", "output": "3" }, { "input": "5 1\n2 3 3 1 1", "output": "3" }, { "input": "9 1\n2 3 3 1 4 1 3 2 1", "output": "3" }, { "input": "10 9\n8 9 1 1 1 1 1 1 1 9", "output": "-1" }, { "input": "13 2\n3 3 3 2 1 1 1 1 1 2 3 2 2", "output": "3" }, { "input": "5 1\n2 3 1 3 1", "output": "3" }, { "input": "8 7\n6 7 2 2 4 5 4 4", "output": "6" }, { "input": "2 7\n6 7", "output": "6" }, { "input": "3 5\n9 5 7", "output": "9" }, { "input": "6 2\n1 2 1 2 1 2", "output": "1" }, { "input": "6 3\n1000 2 3 2 2 3", "output": "2" }, { "input": "10 5\n1 1 1 1 1 5 5 5 5 5", "output": "1" }, { "input": "4 9\n4 9 9 4", "output": "-1" }, { "input": "4 1\n2 1 3 3", "output": "2" }, { "input": "19 3\n1 2 3 1 2 3 1 2 3 5 5 5 5 5 5 5 5 2 3", "output": "2" }, { "input": "15 1\n2 5 5 1 2 1 5 2 1 5 2 1 5 1 5", "output": "5" }, { "input": "14 1\n2 5 5 1 2 1 5 2 1 5 2 1 5 1", "output": "5" }, { "input": "8 5\n1 2 5 1 2 5 2 5", "output": "2" }, { "input": "5 1000000\n1 2 1000000 2 1", "output": "1" }, { "input": "8 2\n1 2 1 3 2 3 3 3", "output": "1" }, { "input": "9 10\n4 9 7 3 3 3 10 3 10", "output": "3" }, { "input": "6 2\n5 3 9 2 10 1", "output": "3" }, { "input": "10 4\n7 5 4 4 1 5 7 9 10 6", "output": "-1" }, { "input": "2 1\n9 1", "output": "9" }, { "input": "3 7\n5 7 1", "output": "5" }, { "input": "6 3\n1 3 5 4 2 3", "output": "-1" }, { "input": "7 1\n7 3 1 4 5 8 5", "output": "3" }, { "input": "2 3\n6 3", "output": "6" }, { "input": "10 8\n2 8 8 9 6 9 1 3 2 4", "output": "-1" }, { "input": "6 1\n1 7 8 4 8 6", "output": "-1" } ]
1,511,182,780
2,147,483,647
PyPy 3
OK
TESTS
95
265
10,649,600
f = lambda: map(int, input().split()) n, a = f() d = [0] * 1000001 for q in f(): if d[q] < d[a]: d[q] = -1 d[q] += 1 k = d[a] d[0] = d[a] = -1 s = max(d) print(d.index(s) if s >= k else -1)
Title: Multicolored Cars Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another. The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after *i*-th car *cnt**A*(*i*) and *cnt**B*(*i*). - If *cnt**A*(*i*)<=&gt;<=*cnt**B*(*i*) for every *i* then the winner is Alice. - If *cnt**B*(*i*)<=≥<=*cnt**A*(*i*) for every *i* then the winner is Bob. - Otherwise it's a draw. Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color *A* and Bob now wants to choose such color *B* that he will win the game (draw is not a win). Help him find this color. If there are multiple solutions, print any of them. If there is no such color then print -1. Input Specification: The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice. The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their appearance. Output Specification: Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1. It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106). Demo Input: ['4 1\n2 1 4 2\n', '5 2\n2 2 4 5 3\n', '3 10\n1 2 3\n'] Demo Output: ['2\n', '-1\n', '4\n'] Note: Let's consider availability of colors in the first example: - *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) &lt; *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning one for Bob. - All the other colors also have *cnt*<sub class="lower-index">*j*</sub>(2) &lt; *cnt*<sub class="lower-index">1</sub>(2), thus they are not available. In the third example every color is acceptable except for 10.
```python f = lambda: map(int, input().split()) n, a = f() d = [0] * 1000001 for q in f(): if d[q] < d[a]: d[q] = -1 d[q] += 1 k = d[a] d[0] = d[a] = -1 s = max(d) print(d.index(s) if s >= k else -1) ```
3