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
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,687,376,227
2,147,483,647
PyPy 3-64
OK
TESTS
28
62
0
a, b = (int(_) for _ in input().split()) print(a if a ==b else 1)
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python a, b = (int(_) for _ in input().split()) print(a if a ==b else 1) ```
3
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input": "1 1000000000000000000 2 99999999999999999 1000000000", "output": "99999999999999997" }, { "input": "1 1 1 1 1", "output": "0" }, { "input": "1 2 3 4 5", "output": "0" }, { "input": "1 1000000000 2 999999999 3141592", "output": "999999997" }, { "input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "output": "0" }, { "input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "output": "27788438422925" }, { "input": "11814 27385 22309 28354 23595", "output": "5076" }, { "input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "output": "29117730788587" }, { "input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "output": "81604391064" }, { "input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "output": "47247500916780901" }, { "input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "output": "0" }, { "input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "output": "48172141432145241" }, { "input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "output": "99277597320376979" }, { "input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "output": "256787461333454149" }, { "input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "output": "37925278862451249" }, { "input": "1 3 3 5 3", "output": "0" }, { "input": "1 5 8 10 9", "output": "0" }, { "input": "1 2 4 5 10", "output": "0" }, { "input": "1 2 2 3 5", "output": "1" }, { "input": "2 4 3 7 3", "output": "1" }, { "input": "1 2 9 10 1", "output": "0" }, { "input": "5 15 1 10 5", "output": "5" }, { "input": "1 4 9 20 25", "output": "0" }, { "input": "2 4 1 2 5", "output": "1" }, { "input": "10 1000 1 100 2", "output": "91" }, { "input": "1 3 3 8 10", "output": "1" }, { "input": "4 6 6 8 9", "output": "1" }, { "input": "2 3 1 4 3", "output": "1" }, { "input": "1 2 2 3 100", "output": "1" }, { "input": "1 2 100 120 2", "output": "0" }, { "input": "1 3 5 7 4", "output": "0" }, { "input": "1 3 5 7 5", "output": "0" }, { "input": "1 4 8 10 6", "output": "0" }, { "input": "1 2 5 6 100", "output": "0" }, { "input": "1 2 5 10 20", "output": "0" }, { "input": "1 2 5 6 7", "output": "0" }, { "input": "2 5 7 12 6", "output": "0" }, { "input": "10 20 50 100 80", "output": "0" }, { "input": "1 2 5 10 2", "output": "0" }, { "input": "1 2 5 6 4", "output": "0" }, { "input": "5 9 1 2 3", "output": "0" }, { "input": "50 100 1 20 3", "output": "0" }, { "input": "10 20 3 7 30", "output": "0" }, { "input": "1 5 10 10 100", "output": "0" }, { "input": "100 101 1 2 3", "output": "0" }, { "input": "1 5 10 20 6", "output": "0" }, { "input": "1 10 15 25 5", "output": "0" }, { "input": "1 2 5 10 3", "output": "0" }, { "input": "2 3 5 6 100", "output": "0" }, { "input": "1 2 4 5 6", "output": "0" }, { "input": "6 10 1 2 40", "output": "0" }, { "input": "20 30 1 5 1", "output": "0" }, { "input": "20 40 50 100 50", "output": "0" }, { "input": "1 1 4 9 2", "output": "0" }, { "input": "1 2 5 6 1", "output": "0" }, { "input": "1 100 400 500 450", "output": "0" }, { "input": "5 6 1 2 5", "output": "0" }, { "input": "1 10 21 30 50", "output": "0" }, { "input": "100 200 300 400 101", "output": "0" }, { "input": "2 8 12 16 9", "output": "0" }, { "input": "1 5 7 9 6", "output": "0" }, { "input": "300 400 100 200 101", "output": "0" }, { "input": "1 2 2 3 10", "output": "1" }, { "input": "1 10 100 200 5", "output": "0" }, { "input": "1 3 3 4 4", "output": "1" }, { "input": "10 20 30 40 25", "output": "0" }, { "input": "1 2 5 10 1", "output": "0" }, { "input": "2 4 8 10 1", "output": "0" }, { "input": "2 5 10 15 7", "output": "0" }, { "input": "100 200 5 10 1", "output": "0" }, { "input": "1 2 100 200 300", "output": "0" }, { "input": "30 100 10 20 25", "output": "0" }, { "input": "10 20 1 5 6", "output": "0" }, { "input": "4 5 1 2 4", "output": "0" }, { "input": "11 100 1 9 1000", "output": "0" }, { "input": "1 1 10 10 228", "output": "0" }, { "input": "5 7 10 20 15", "output": "0" }, { "input": "1 3 8 9 7", "output": "0" }, { "input": "1 10 2 8 8", "output": "6" }, { "input": "1 5 9 15 1", "output": "0" }, { "input": "1 3 5 6 12", "output": "0" }, { "input": "1 100 500 1000 3", "output": "0" }, { "input": "1 1 1 1 2", "output": "1" }, { "input": "1 1000 100 1000 200", "output": "900" }, { "input": "4 5 1 4 1", "output": "1" }, { "input": "1 5 5 7 3", "output": "1" }, { "input": "1 4 4 10 11", "output": "1" }, { "input": "1 1 3 4 100", "output": "0" }, { "input": "1 4 3 5 6", "output": "2" }, { "input": "10 100 20 30 40", "output": "11" }, { "input": "5 9 1 11 7", "output": "4" } ]
1,642,830,485
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
9
156
0
a, b, c, d, e = map(int, input().split()) start = max(a, c); end = min(b, d) + 1 ans = end - start if e >= start and e <= end: ans -= 1 print(ans)
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together. Input Specification: The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Specification: Print one integer — the number of minutes Sonya and Filya will be able to spend together. Demo Input: ['1 10 9 20 1\n', '1 100 50 200 75\n'] Demo Output: ['2\n', '50\n'] Note: In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
```python a, b, c, d, e = map(int, input().split()) start = max(a, c); end = min(b, d) + 1 ans = end - start if e >= start and e <= end: ans -= 1 print(ans) ```
0
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain\nB man\nD woman\nC child\nE rat", "output": "E\nD\nC\nB\nA" }, { "input": "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat", "output": "Rat\nRatt\nD\nC\nA\nE\nB\nF\nMan\nCap" }, { "input": "5\nJoyxnkypf captain\nDxssgr woman\nKeojmnpd rat\nGdv man\nHnw man", "output": "Keojmnpd\nDxssgr\nGdv\nHnw\nJoyxnkypf" }, { "input": "11\nJue rat\nWyglbyphk rat\nGjlgu child\nGi man\nAttx rat\nTheorpkgx man\nYm rat\nX child\nB captain\nEnualf rat\nKktsgyuyv woman", "output": "Jue\nWyglbyphk\nAttx\nYm\nEnualf\nGjlgu\nX\nKktsgyuyv\nGi\nTheorpkgx\nB" }, { "input": "22\nWswwcvvm woman\nBtmfats rat\nI rat\nOcmtsnwx man\nUrcqv rat\nYghnogt woman\nWtyfc man\nWqle child\nUjfrelpu rat\nDstixj man\nAhksnio woman\nKhkvaap woman\nSjppvwm rat\nEgdmsv rat\nDank rat\nNquicjnw rat\nLh captain\nTdyaqaqln rat\nQtj rat\nTfgwijvq rat\nNbiso child\nNqthvbf woman", "output": "Btmfats\nI\nUrcqv\nUjfrelpu\nSjppvwm\nEgdmsv\nDank\nNquicjnw\nTdyaqaqln\nQtj\nTfgwijvq\nWswwcvvm\nYghnogt\nWqle\nAhksnio\nKhkvaap\nNbiso\nNqthvbf\nOcmtsnwx\nWtyfc\nDstixj\nLh" }, { "input": "36\nKqxmtwmsf child\nIze woman\nDlpr child\nK woman\nF captain\nRjwfeuhba rat\nBbv rat\nS rat\nMnmg woman\nSmzyx woman\nSr man\nQmhroracn rat\nSoqpuqock rat\nPibdq man\nIlrkrptx rat\nZaecfyqka man\nMmersfs child\nVvvocqi man\nHjeqxvq rat\nMpmb woman\nWmgu woman\nCerelmhoxi child\nA man\nDylv man\nXrdgmmtcpq woman\nXj woman\nCeh child\nOfccguo man\nNevr man\nAknkwdkq child\nBmo man\nLqo woman\nVej child\nT child\nRlijc man\nNsdtpdg woman", "output": "Rjwfeuhba\nBbv\nS\nQmhroracn\nSoqpuqock\nIlrkrptx\nHjeqxvq\nKqxmtwmsf\nIze\nDlpr\nK\nMnmg\nSmzyx\nMmersfs\nMpmb\nWmgu\nCerelmhoxi\nXrdgmmtcpq\nXj\nCeh\nAknkwdkq\nLqo\nVej\nT\nNsdtpdg\nSr\nPibdq\nZaecfyqka\nVvvocqi\nA\nDylv\nOfccguo\nNevr\nBmo\nRlijc\nF" }, { "input": "2\nA captain\nB man", "output": "B\nA" }, { "input": "2\nB woman\nA captain", "output": "B\nA" }, { "input": "2\nX child\nY captain", "output": "X\nY" }, { "input": "2\nX captain\nY rat", "output": "Y\nX" }, { "input": "6\nAbdelrhman captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nAbdelrhman" }, { "input": "4\nAratos captain\nMind child\nAman woman\nCarrot man", "output": "Mind\nAman\nCarrot\nAratos" } ]
1,676,054,759
2,147,483,647
Python 3
OK
TESTS
26
92
0
n = int(input()) rat = [] childwoman = [] man = [] captain = [] for i in range(n): str = input() if str[-1:] == 't': rat.append(str[:-4]) elif str[-1:] == 'd': childwoman.append(str[:-6]) elif str[-5:] == 'woman': childwoman.append(str[:-6]) elif str[-3:] == 'man': man.append(str[:-4]) else: captain.append(str[:-8]) for i in rat: print(i) for i in childwoman: print(i) for i in man: print(i) for i in captain: print(i)
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. Input Specification: The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. Output Specification: Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. Demo Input: ['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n'] Demo Output: ['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n'] Note: none
```python n = int(input()) rat = [] childwoman = [] man = [] captain = [] for i in range(n): str = input() if str[-1:] == 't': rat.append(str[:-4]) elif str[-1:] == 'd': childwoman.append(str[:-6]) elif str[-5:] == 'woman': childwoman.append(str[:-6]) elif str[-3:] == 'man': man.append(str[:-4]) else: captain.append(str[:-8]) for i in rat: print(i) for i in childwoman: print(i) for i in man: print(i) for i in captain: print(i) ```
3.977
659
B
Qualifying Contest
PROGRAMMING
1,300
[ "constructive algorithms", "sortings" ]
null
null
Very soon Berland will hold a School Team Programming Olympiad. From each of the *m* Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by *n* Berland students. There were at least two schoolboys participating from each of the *m* regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=10<=000, *n*<=≥<=2*m*) — the number of participants of the qualifying contest and the number of regions in Berland. Next *n* lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to *m*) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the *m* regions. The surnames that only differ in letter cases, should be considered distinct.
Print *m* lines. On the *i*-th line print the team of the *i*-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
[ "5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503\n", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503\n" ]
[ "Sidorov Ivanov\nAndreev Semenov\n", "?\nAndreev Semenov\n" ]
In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
1,000
[ { "input": "5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "output": "Sidorov Ivanov\nAndreev Semenov" }, { "input": "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503", "output": "?\nAndreev Semenov" }, { "input": "10 2\nSHiBIEz 2 628\nXxwaAxB 1 190\nXwR 2 290\nRKjOf 2 551\nTUP 1 333\nFarsFvyH 1 208\nCGDYnq 1 482\nqaM 2 267\nVfiLunRz 1 416\nuVMHLk 2 754", "output": "CGDYnq VfiLunRz\nuVMHLk SHiBIEz" }, { "input": "10 3\nfeDtYWSlR 2 361\nZEtQAWn 3 208\nE 2 564\noSXtUXr 3 750\nP 3 520\nPhYCykFvA 2 487\nvMQ 1 797\nZtE 1 141\nlrELK 1 736\nab 2 6", "output": "vMQ lrELK\nE PhYCykFvA\noSXtUXr P" }, { "input": "10 4\nigtVqPgoW 3 24\nuc 1 381\nOxmovZAv 4 727\nxyRAaAk 2 378\nvYCV 4 67\nuf 2 478\nDawOytiYiH 2 775\nRS 1 374\npLhTehhjA 2 38\nYkWfb 3 595", "output": "uc RS\nDawOytiYiH uf\nYkWfb igtVqPgoW\nOxmovZAv vYCV" }, { "input": "2 1\nOAELh 1 733\nbFGs 1 270", "output": "OAELh bFGs" }, { "input": "3 1\nzD 1 148\nYwUMpKZREJ 1 753\nBJOy 1 30", "output": "YwUMpKZREJ zD" }, { "input": "3 1\na 1 2\nb 1 2\nc 1 1", "output": "a b" }, { "input": "3 1\nA 1 100\nB 1 200\nC 1 100", "output": "?" }, { "input": "4 1\na 1 2\nc 1 3\nd 1 3\nb 1 4", "output": "?" }, { "input": "3 1\nA 1 800\nB 1 700\nC 1 700", "output": "?" }, { "input": "3 1\nA 1 800\nB 1 800\nC 1 700", "output": "A B" }, { "input": "6 1\nA 1 1\nB 1 1\nC 1 1\nD 1 1\nE 1 2\nF 1 3", "output": "F E" }, { "input": "4 1\na 1 2\nb 1 3\nc 1 3\nd 1 4", "output": "?" }, { "input": "4 1\na 1 2\nb 1 1\nc 1 3\nd 1 3", "output": "c d" }, { "input": "3 1\nIvanov 1 800\nAndreev 1 800\nPetrov 1 799", "output": "Andreev Ivanov" }, { "input": "2 1\nA 1 5\nB 1 5", "output": "A B" }, { "input": "5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 800", "output": "Sidorov Ivanov\nAndreev Semenov" }, { "input": "4 2\nIvanov 1 1\nAndreev 1 1\nPetrov 2 1\nSidorov 2 1", "output": "Andreev Ivanov\nPetrov Sidorov" }, { "input": "2 1\na 1 0\nb 1 0", "output": "a b" }, { "input": "4 1\na 1 10\nb 1 10\nc 1 5\nd 1 5", "output": "a b" }, { "input": "3 1\na 1 2\nb 1 1\nc 1 1", "output": "?" }, { "input": "3 1\nIvanov 1 8\nAndreev 1 7\nPetrov 1 7", "output": "?" }, { "input": "3 1\nA 1 5\nB 1 4\nC 1 4", "output": "?" }, { "input": "2 1\na 1 10\nb 1 10", "output": "a b" }, { "input": "3 1\nyou 1 800\nare 1 700\nwrong 1 700", "output": "?" }, { "input": "3 1\na 1 600\nb 1 500\nc 1 500", "output": "?" }, { "input": "3 1\na 1 10\nb 1 20\nc 1 20", "output": "b c" }, { "input": "3 1\nA 1 2\nB 1 2\nC 1 1", "output": "A B" } ]
1,643,228,267
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
295
10,035,200
def Qualified(i): k = sorted(region[i],key=lambda x: x[1],reverse=True) if(k[0][1]==k[1][1]): print("?") return if(len(k)>2): if(k[1][1]==k[2][1]): print("?") else: print(k[0][0],k[1][0]) return else: print(k[0][0],k[1][0]) return n,m = map(int,input().split()) region = [[]for i in range(m)] for i in range(n): a = input().split() region[int(a[1])-1].append((a[0],int(a[2]))) for i in range(m): Qualified(i)
Title: Qualifying Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Very soon Berland will hold a School Team Programming Olympiad. From each of the *m* Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by *n* Berland students. There were at least two schoolboys participating from each of the *m* regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=10<=000, *n*<=≥<=2*m*) — the number of participants of the qualifying contest and the number of regions in Berland. Next *n* lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to *m*) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the *m* regions. The surnames that only differ in letter cases, should be considered distinct. Output Specification: Print *m* lines. On the *i*-th line print the team of the *i*-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Demo Input: ['5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503\n', '5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503\n'] Demo Output: ['Sidorov Ivanov\nAndreev Semenov\n', '?\nAndreev Semenov\n'] Note: In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
```python def Qualified(i): k = sorted(region[i],key=lambda x: x[1],reverse=True) if(k[0][1]==k[1][1]): print("?") return if(len(k)>2): if(k[1][1]==k[2][1]): print("?") else: print(k[0][0],k[1][0]) return else: print(k[0][0],k[1][0]) return n,m = map(int,input().split()) region = [[]for i in range(m)] for i in range(n): a = input().split() region[int(a[1])-1].append((a[0],int(a[2]))) for i in range(m): Qualified(i) ```
0
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", "output": "9" }, { "input": "10\n10 5 8 9 5 6 8 7 2 8", "output": "46" }, { "input": "10\n1 1 1 1 1 1 2 3 4 4", "output": "14" }, { "input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4", "output": "296" }, { "input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2", "output": "313" }, { "input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9", "output": "298" }, { "input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5", "output": "312" }, { "input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2", "output": "287" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2", "output": "265" }, { "input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9", "output": "328" }, { "input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9", "output": "324" }, { "input": "10\n7 4 5 3 9 1 10 3 4 5", "output": "34" }, { "input": "10\n8 9 6 5 6 4 10 9 1 4", "output": "39" }, { "input": "10\n1 7 1 4 9 10 8 2 9 9", "output": "40" }, { "input": "1\n100000", "output": "100000" } ]
1,696,520,237
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
42
124
20,275,200
from collections import defaultdict def solve(): n = int(input()) l = [int(i) for i in input().split()] dp, cnt = [0]*(n+1), defaultdict(int) for i in l: cnt[i] += 1 dp[1] = cnt[1] for i in range(2, max(l)+1): dp[i] = max(dp[i-1], dp[i-2]+cnt[i]*i) print(dp[max(l)]) # t = int(input()) t = 1 while t: solve() t -= 1
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a single integer — the maximum number of points that Alex can earn. Demo Input: ['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n'] Demo Output: ['2\n', '4\n', '10\n'] Note: Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
```python from collections import defaultdict def solve(): n = int(input()) l = [int(i) for i in input().split()] dp, cnt = [0]*(n+1), defaultdict(int) for i in l: cnt[i] += 1 dp[1] = cnt[1] for i in range(2, max(l)+1): dp[i] = max(dp[i-1], dp[i-2]+cnt[i]*i) print(dp[max(l)]) # t = int(input()) t = 1 while t: solve() t -= 1 ```
-1
747
B
Mammoth's Genome Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
1,000
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????", "output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT" }, { "input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "===" }, { "input": "4\n??A?", "output": "CGAT" }, { "input": "4\n?C??", "output": "ACGT" }, { "input": "4\nT???", "output": "TACG" }, { "input": "4\n???G", "output": "ACTG" }, { "input": "4\n??AC", "output": "GTAC" }, { "input": "8\n?C?AA???", "output": "CCGAAGTT" }, { "input": "12\n???A?G???A?T", "output": "ACCACGGGTATT" }, { "input": "16\n?????C??CAG??T??", "output": "AAACCCGGCAGGTTTT" }, { "input": "20\n???A?G??C?GC???????G", "output": "AAAAAGCCCCGCGGTTTTTG" }, { "input": "24\n?TG???AT?A?CTTG??T?GCT??", "output": "ATGAAAATCACCTTGCCTGGCTGG" }, { "input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?", "output": "AACTGAAGAGGTCCCGAGTTTTCCACGT" }, { "input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?", "output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT" }, { "input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?", "output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT" }, { "input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??", "output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT" }, { "input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??", "output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT" }, { "input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?", "output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT" }, { "input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG", "output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG" }, { "input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??", "output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT" }, { "input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?", "output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT" }, { "input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C", "output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC" }, { "input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??", "output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT" }, { "input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG", "output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG" }, { "input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG", "output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG" }, { "input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?", "output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG" }, { "input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C", "output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC" }, { "input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?", "output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT" }, { "input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???", "output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT" }, { "input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????", "output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT" }, { "input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT", "output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT" }, { "input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG", "output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG" }, { "input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA", "output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA" }, { "input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??", "output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT" }, { "input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C", "output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC" }, { "input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C", "output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC" }, { "input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G", "output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG" }, { "input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?", "output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT" }, { "input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT", "output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT" }, { "input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?", "output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT" }, { "input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??", "output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT" }, { "input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA", "output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA" }, { "input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?", "output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT" }, { "input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G", "output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG" }, { "input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA", "output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA" }, { "input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?", "output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT" }, { "input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?", "output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG" }, { "input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT", "output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT" }, { "input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA", "output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA" }, { "input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G", "output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG" }, { "input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?", "output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT" }, { "input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T", "output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT" }, { "input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T", "output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT" }, { "input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????", "output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT" }, { "input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??", "output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT" }, { "input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??", "output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT" }, { "input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?", "output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT" }, { "input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT", "output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT" }, { "input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?", "output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT" }, { "input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??", "output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT" }, { "input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?", "output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT" }, { "input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?", "output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT" }, { "input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C", "output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC" }, { "input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC", "output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC" }, { "input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG", "output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG" }, { "input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?", "output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT" }, { "input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC", "output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC" }, { "input": "8\n???AAA??", "output": "===" }, { "input": "12\nC??CC??????C", "output": "===" }, { "input": "4\nG??G", "output": "===" }, { "input": "4\nTT??", "output": "===" }, { "input": "4\nACAC", "output": "===" }, { "input": "8\nACGT???T", "output": "ACGTACGT" }, { "input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG" }, { "input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "4\nAA?T", "output": "===" }, { "input": "4\nAAAA", "output": "===" }, { "input": "8\nAAA?????", "output": "===" }, { "input": "10\nACGT??????", "output": "===" }, { "input": "6\nACGACG", "output": "===" }, { "input": "5\nAAAAA", "output": "===" }, { "input": "8\nGGGGAA??", "output": "===" }, { "input": "5\nATGCA", "output": "===" }, { "input": "4\nTTTT", "output": "===" }, { "input": "4\nACCG", "output": "===" }, { "input": "8\nACGTA?GT", "output": "ACGTACGT" } ]
1,690,780,253
2,147,483,647
PyPy 3-64
OK
TESTS
95
77
102,400
from collections import Counter length, gene = int(input()), input() c = Counter(gene) nucls_left = {"A": c["A"], "C": c["C"], "G": c["G"], "T": c["T"]} if length % 4 != 0 or any(value > length / 4 for value in nucls_left.values()): print("===") else: for letter in gene: if letter == "?": for nucl in nucls_left: if nucls_left[nucl] < length / 4: print(nucl, end='') nucls_left[nucl] += 1 break else: print(letter, end='')
Title: Mammoth's Genome Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input Specification: The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output Specification: If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Demo Input: ['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n'] Demo Output: ['AGACGTCT\n', 'AGCT\n', '===\n', '===\n'] Note: In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
```python from collections import Counter length, gene = int(input()), input() c = Counter(gene) nucls_left = {"A": c["A"], "C": c["C"], "G": c["G"], "T": c["T"]} if length % 4 != 0 or any(value > length / 4 for value in nucls_left.values()): print("===") else: for letter in gene: if letter == "?": for nucl in nucls_left: if nucls_left[nucl] < length / 4: print(nucl, end='') nucls_left[nucl] += 1 break else: print(letter, end='') ```
3
632
C
The Smallest String Concatenation
PROGRAMMING
1,700
[ "sortings", "strings" ]
null
null
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest concatenation.
The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104). Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.
Print the only string *a* — the lexicographically smallest string concatenation.
[ "4\nabba\nabacaba\nbcd\ner\n", "5\nx\nxx\nxxa\nxxaa\nxxaaa\n", "3\nc\ncb\ncba\n" ]
[ "abacabaabbabcder\n", "xxaaaxxaaxxaxxx\n", "cbacbc\n" ]
none
0
[ { "input": "4\nabba\nabacaba\nbcd\ner", "output": "abacabaabbabcder" }, { "input": "5\nx\nxx\nxxa\nxxaa\nxxaaa", "output": "xxaaaxxaaxxaxxx" }, { "input": "3\nc\ncb\ncba", "output": "cbacbc" }, { "input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc", "output": "abaabaabaacaabaacacacaaaabbacbaacbbbbcabcabbcccaabcc" }, { "input": "13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymt\nbvwzpuut\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymth\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdl\nrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypud\nqlvkfkshkxyrfefigtngifxsuhpjgkb\nlhxtkfjrrwcvzuamizotupjqckaq\nenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjz\nxkazwk", "output": "bvwzpuutclgknjjojyuvdtvclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymthclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdlclgknjjojyuvdtvzxzclgknjjojyuvdtvzxzxradqhmenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjzgvzpnckalbaubfviyhijosiixvxaydxagvymqlhxtkfjrrwcvzuamizotupjqckaqqlvkfkshkxyrfefigtngifxsuhpjgkbrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypudxkazwk" } ]
1,630,512,500
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
3,000
7,270,400
def rakesh(a, n): for i in range(0,n): for j in range(i+1,n): if(a[i]+a[j]>a[j]+a[i]): s=a[i] a[i]=a[j] a[j]=s an = "" for i in range( n): an += a[i] print(an) n=int(input()) a=[] for i in range(n): a.append(input()) rakesh(a,n)
Title: The Smallest String Concatenation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest concatenation. Input Specification: The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104). Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. Output Specification: Print the only string *a* — the lexicographically smallest string concatenation. Demo Input: ['4\nabba\nabacaba\nbcd\ner\n', '5\nx\nxx\nxxa\nxxaa\nxxaaa\n', '3\nc\ncb\ncba\n'] Demo Output: ['abacabaabbabcder\n', 'xxaaaxxaaxxaxxx\n', 'cbacbc\n'] Note: none
```python def rakesh(a, n): for i in range(0,n): for j in range(i+1,n): if(a[i]+a[j]>a[j]+a[i]): s=a[i] a[i]=a[j] a[j]=s an = "" for i in range( n): an += a[i] print(an) n=int(input()) a=[] for i in range(n): a.append(input()) rakesh(a,n) ```
0
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "6\n1 1 1 1 1 1", "output": "4" }, { "input": "7\n10 10 5 5 5 5 1", "output": "3" }, { "input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "output": "8" }, { "input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "output": "8" }, { "input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "output": "8" }, { "input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90", "output": "6" }, { "input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28", "output": "14" }, { "input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42", "output": "22" }, { "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": "51" }, { "input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2", "output": "37" }, { "input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2", "output": "36" }, { "input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3", "output": "33" }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "30" }, { "input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2", "output": "29" }, { "input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "output": "30" }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "29" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "30" }, { "input": "1\n1", "output": "1" }, { "input": "4\n4 1 2 3", "output": "2" }, { "input": "5\n2 2 2 4 4", "output": "2" }, { "input": "4\n100 99 99 100", "output": "2" } ]
1,692,910,437
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
60
0
import math def my_solution(coins): half = math.floor(sum(coins)/2) coins = sorted(coins) stolen = 0 i = 0 while stolen <= half: stolen += coins[i] i += 1 print(i) n = input() coins = [int(coin) for coin in input().split()] my_solution(coins)
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. Output Specification: In the single line print the single number — the minimum needed number of coins. Demo Input: ['2\n3 3\n', '3\n2 1 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
```python import math def my_solution(coins): half = math.floor(sum(coins)/2) coins = sorted(coins) stolen = 0 i = 0 while stolen <= half: stolen += coins[i] i += 1 print(i) n = input() coins = [int(coin) for coin in input().split()] my_solution(coins) ```
0
56
B
Spoilt Permutation
PROGRAMMING
1,300
[ "implementation" ]
B. Spoilt Permutation
2
256
Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from *l* to *r* inclusively and put them in the reverse order. That is, he took a certain segment [*l*,<=*r*] and reversed it. At that the segment's endpoints did not coincide. For example, if *n*<==<=8, then initially Vasya's coins were kept in the order 1 2 3 4 5 6 7 8. If Vasya's younger brother chose the segment [2,<=6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Vasya suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 ... *n* using exactly one segment reversal. If it is possible, find the segment itself.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000) which is the number of coins in Vasya's collection. The second line contains space-separated *n* integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to *n*, and every number is used exactly 1 time.
If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers *l* *r* (1<=≤<=*l*<=&lt;<=*r*<=≤<=*n*) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... *n* the given one.
[ "8\n1 6 5 4 3 2 7 8\n", "4\n2 3 4 1\n", "4\n1 2 3 4\n" ]
[ "2 6\n", "0 0\n", "0 0\n" ]
none
1,000
[ { "input": "8\n1 6 5 4 3 2 7 8", "output": "2 6" }, { "input": "4\n2 3 4 1", "output": "0 0" }, { "input": "4\n1 2 3 4", "output": "0 0" }, { "input": "8\n1 3 2 4 6 5 7 8", "output": "0 0" }, { "input": "8\n1 3 4 2 6 5 7 8", "output": "0 0" }, { "input": "1\n1", "output": "0 0" }, { "input": "2\n1 2", "output": "0 0" }, { "input": "2\n2 1", "output": "1 2" }, { "input": "149\n9 120 122 97 93 70 85 56 102 16 103 112 88 84 118 135 113 62 65 19 89 15 108 73 82 21 147 27 115 130 136 6 1 90 29 94 149 17 53 132 99 123 64 95 71 67 141 126 59 8 10 114 121 134 107 87 128 79 66 55 72 39 31 111 60 137 2 4 23 129 133 47 12 54 100 77 98 30 86 125 11 5 45 148 57 49 91 28 74 18 140 3 144 78 142 101 110 131 127 20 63 139 96 32 80 50 52 69 75 76 119 26 33 109 48 116 117 35 44 83 124 68 7 14 51 40 41 104 22 105 42 38 46 37 61 146 13 106 43 36 25 143 92 138 24 81 145 34 58", "output": "0 0" }, { "input": "35\n7 33 34 15 16 24 5 27 1 19 17 22 29 3 4 23 31 11 21 35 32 2 12 20 8 9 6 28 18 26 30 14 13 10 25", "output": "0 0" }, { "input": "114\n26 20 11 61 28 89 49 42 103 74 99 71 19 67 111 85 92 13 31 18 47 91 23 95 40 29 79 2 109 70 33 82 90 5 21 77 45 41 15 86 35 46 58 87 83 62 43 9 66 3 106 14 73 107 17 22 110 104 4 100 32 52 54 55 112 96 97 44 98 75 94 80 72 69 59 57 60 108 65 30 64 78 16 10 53 84 27 6 76 7 93 114 37 105 8 113 68 1 102 24 63 39 34 51 101 25 12 48 81 36 88 56 38 50", "output": "0 0" }, { "input": "133\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 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 128 129 130 131 132 133", "output": "85 127" }, { "input": "4\n1 2 4 3", "output": "3 4" }, { "input": "4\n1 4 3 2", "output": "2 4" } ]
1,631,543,198
2,147,483,647
Python 3
OK
TESTS
33
124
6,963,200
def solve(a,sol): f=0 s=0 for i in range(len(a)): if(a[i]!=i+1): f=i break for j in range(len(a)-1,-1,-1): if(a[j]!=j+1): s=j break x=a[f:s+1] x.reverse() if(a[:f]+x+a[s+1:]==sol): print(f+1,s+1) else: print(0,0) n=int(input()) a=list(map(int,input().split())) sol=[(i+1) for i in range(n)] if(a==sol): print(0,0) else: solve(a,sol)
Title: Spoilt Permutation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from *l* to *r* inclusively and put them in the reverse order. That is, he took a certain segment [*l*,<=*r*] and reversed it. At that the segment's endpoints did not coincide. For example, if *n*<==<=8, then initially Vasya's coins were kept in the order 1 2 3 4 5 6 7 8. If Vasya's younger brother chose the segment [2,<=6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Vasya suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 ... *n* using exactly one segment reversal. If it is possible, find the segment itself. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000) which is the number of coins in Vasya's collection. The second line contains space-separated *n* integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to *n*, and every number is used exactly 1 time. Output Specification: If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers *l* *r* (1<=≤<=*l*<=&lt;<=*r*<=≤<=*n*) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... *n* the given one. Demo Input: ['8\n1 6 5 4 3 2 7 8\n', '4\n2 3 4 1\n', '4\n1 2 3 4\n'] Demo Output: ['2 6\n', '0 0\n', '0 0\n'] Note: none
```python def solve(a,sol): f=0 s=0 for i in range(len(a)): if(a[i]!=i+1): f=i break for j in range(len(a)-1,-1,-1): if(a[j]!=j+1): s=j break x=a[f:s+1] x.reverse() if(a[:f]+x+a[s+1:]==sol): print(f+1,s+1) else: print(0,0) n=int(input()) a=list(map(int,input().split())) sol=[(i+1) for i in range(n)] if(a==sol): print(0,0) else: solve(a,sol) ```
3.95603
526
C
Om Nom and Candies
PROGRAMMING
2,000
[ "brute force", "greedy", "math" ]
null
null
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units. Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109).
Print a single integer — the maximum number of joy units that Om Nom can get.
[ "10 3 5 2 3\n" ]
[ "16\n" ]
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
1,250
[ { "input": "10 3 5 2 3", "output": "16" }, { "input": "5 3 1 6 7", "output": "0" }, { "input": "982068341 55 57 106 109", "output": "513558662" }, { "input": "930064129 32726326 25428197 83013449 64501049", "output": "363523396" }, { "input": "927155987 21197 15994 54746 41309", "output": "358983713" }, { "input": "902303498 609628987 152407246 8 2", "output": "68758795931537065" }, { "input": "942733698 9180 9072 1020 1008", "output": "8484603228" }, { "input": "951102310 39876134 24967176 70096104 43888451", "output": "539219654" }, { "input": "910943911 107 105 60 59", "output": "1624516635" }, { "input": "910943911 38162 31949 67084 56162", "output": "518210503" }, { "input": "910943911 9063 9045 1007 1005", "output": "8198495199" }, { "input": "903796108 270891702 270891702 1 1", "output": "244830865957095816" }, { "input": "936111602 154673223 309346447 1 2", "output": "144791399037089047" }, { "input": "947370735 115930744 347792233 1 3", "output": "109829394468167085" }, { "input": "958629867 96557265 386229061 1 4", "output": "92562678344491221" }, { "input": "969889000 84931386 424656931 1 5", "output": "82374017230131800" }, { "input": "925819493 47350513 28377591 83230978 49881078", "output": "520855643" }, { "input": "934395168 119 105 67 59", "output": "1662906651" }, { "input": "934395168 29208 38362 51342 67432", "output": "531576348" }, { "input": "934395168 9171 9045 1019 1005", "output": "8409556512" }, { "input": "946401698 967136832 483568416 2 1", "output": "457649970001570368" }, { "input": "962693577 967217455 967217455 2 2", "output": "465567015261784540" }, { "input": "989976325 646076560 969114840 2 3", "output": "319800249268721000" }, { "input": "901235456 485501645 971003291 2 4", "output": "218775648435471424" }, { "input": "912494588 389153108 972882772 2 5", "output": "177550052841687584" }, { "input": "995503930 29205027 18903616 51333090 33226507", "output": "565303099" }, { "input": "983935533 115 108 65 61", "output": "1742049794" }, { "input": "983935533 33986 27367 59737 48104", "output": "559787479" }, { "input": "983935533 7105 7056 1015 1008", "output": "6887548731" }, { "input": "994040035 740285170 246761723 3 1", "output": "245291032098926983" }, { "input": "905299166 740361314 493574209 3 2", "output": "223416160034288041" }, { "input": "911525551 740437472 740437472 3 3", "output": "224975891301803200" }, { "input": "922784684 566833132 755777509 3 4", "output": "174354977531116762" }, { "input": "955100178 462665160 771108601 3 5", "output": "147297192414486195" }, { "input": "949164751 36679609 23634069 64467968 41539167", "output": "537909080" }, { "input": "928443151 60 63 106 112", "output": "525533853" }, { "input": "928443151 25031 33442 43995 58778", "output": "528241752" }, { "input": "928443151 1006 1012 1006 1012", "output": "928443150" }, { "input": "936645623 540336743 135084185 4 1", "output": "126526011319256470" }, { "input": "947904756 540408420 270204210 4 2", "output": "128063927875111380" }, { "input": "959163888 540480074 405360055 4 3", "output": "129602242291091928" }, { "input": "970423020 540551739 540551739 4 4", "output": "131140962756657945" }, { "input": "976649406 455467553 569334442 4 5", "output": "111208028918928288" }, { "input": "923881933 18531902 53987967 32570076 94884602", "output": "524563246" }, { "input": "977983517 57 63 101 112", "output": "551931291" }, { "input": "977983517 29808 22786 52389 40047", "output": "556454318" }, { "input": "977983517 9009 9108 1001 1012", "output": "8801851608" }, { "input": "984283960 367291526 73458305 5 1", "output": "72303831537144592" }, { "input": "990510345 367358723 146943489 5 2", "output": "72774523091497887" }, { "input": "901769477 367425909 220455545 5 3", "output": "66266693959035917" }, { "input": "907995862 367493085 293994468 5 4", "output": "66736440098722854" }, { "input": "924287742 367560271 367560271 5 5", "output": "67946290439275508" }, { "input": "1000000000 1000 999 100 1000000000", "output": "10000000000" }, { "input": "999999999 10 499999995 2 99999999", "output": "4999999995" }, { "input": "999999999 1 1000000000 2 1000000000", "output": "499999999" }, { "input": "999999997 2 999999997 2 999999997", "output": "999999997" }, { "input": "1000000000 1 1 11 11", "output": "90909090" }, { "input": "999999999 999999998 5 999999999 5", "output": "999999998" }, { "input": "100000001 3 100000000 3 100000001", "output": "100000000" }, { "input": "999999999 2 3 1 2", "output": "1999999998" }, { "input": "1000000000 2 1 3 4", "output": "666666666" }, { "input": "999999999 10000 494999 2 99", "output": "4999999994999" }, { "input": "1000000000 1 1 1 1", "output": "1000000000" }, { "input": "998999 1000 999 1000 999", "output": "998999" }, { "input": "3 100 101 2 3", "output": "101" }, { "input": "345415838 13999 13997 13999 13997", "output": "345415838" }, { "input": "5000005 3 2 5 1", "output": "10000010" }, { "input": "1000000000 1 1 1 1000000000", "output": "1000000000" }, { "input": "999999999 3 2 10 3", "output": "666666666" }, { "input": "1000000000 1000 1000 1 1", "output": "1000000000000" }, { "input": "200000001 100000002 1 100000001 1", "output": "200000002" }, { "input": "100000000 1000000000 1 100000001 1", "output": "100000000" }, { "input": "1000000000 99 100 1 2", "output": "99000000000" }, { "input": "1000000000 5 5 1 1", "output": "5000000000" }, { "input": "1000000000 1 1000000000 1 1000000000", "output": "1000000000" } ]
1,591,339,551
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
1,536,000
C, Pr, Pb, Wr, Wb = list(map(int, input().split())) result = 0 if Wr * Wr >= C: i = 0 while Wr * i <= C: j = int((C - Wr * i) / Wb) result = max(result, Pr * i + Pb * j) i += 1 print(result) exit(0) if Wb * Wb <= C: i = 0 while Wb * i <= C: j = int((C - Wb * i) / Wr) result = max(result, Pb * i + Pr * j) i += 1 print(result) exit(0) Ab = Pb / Wb Ar = Pr / Wr if Ab < Ar: i = 0 while i * i <= C: j = int((C - Wb * i) / Wr) result = max(result, Pb * i + Pr * j) i += 1 print(result) else: i = 0 while i * i <= C: j = int((C - Wr * i) / Wb) result = max(result, Pr * i + Pb * j) i += 1 print(result)
Title: Om Nom and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units. Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat. Input Specification: The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109). Output Specification: Print a single integer — the maximum number of joy units that Om Nom can get. Demo Input: ['10 3 5 2 3\n'] Demo Output: ['16\n'] Note: In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
```python C, Pr, Pb, Wr, Wb = list(map(int, input().split())) result = 0 if Wr * Wr >= C: i = 0 while Wr * i <= C: j = int((C - Wr * i) / Wb) result = max(result, Pr * i + Pb * j) i += 1 print(result) exit(0) if Wb * Wb <= C: i = 0 while Wb * i <= C: j = int((C - Wb * i) / Wr) result = max(result, Pb * i + Pr * j) i += 1 print(result) exit(0) Ab = Pb / Wb Ar = Pr / Wr if Ab < Ar: i = 0 while i * i <= C: j = int((C - Wb * i) / Wr) result = max(result, Pb * i + Pr * j) i += 1 print(result) else: i = 0 while i * i <= C: j = int((C - Wr * i) / Wb) result = max(result, Pr * i + Pb * j) i += 1 print(result) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,682,885,414
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
n=input() n=list(map(int,input().split(' '))) ret=-1 if n[0]%2!=n[1]%2 and n[1]%2==n[2]%2: ret=1 if ret=-1: for i in range(1,len(n)-1): if n[i]%2!=n[i-1]%2 and n[i]%2!=n[i+1]%2: ret=i+1 break if ret=-1: ret=len(n) print(ret)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=input() n=list(map(int,input().split(' '))) ret=-1 if n[0]%2!=n[1]%2 and n[1]%2==n[2]%2: ret=1 if ret=-1: for i in range(1,len(n)-1): if n[i]%2!=n[i-1]%2 and n[i]%2!=n[i+1]%2: ret=i+1 break if ret=-1: ret=len(n) print(ret) ```
-1
401
C
Team
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: - there wouldn't be a pair of any side-adjacent cards with zeroes in a row; - there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought *n* cards with zeroes and *m* cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1.
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
[ "1 2\n", "4 8\n", "4 10\n", "1 5\n" ]
[ "101\n", "110110110101\n", "11011011011011\n", "-1\n" ]
none
1,500
[ { "input": "1 2", "output": "101" }, { "input": "4 8", "output": "110110110101" }, { "input": "4 10", "output": "11011011011011" }, { "input": "1 5", "output": "-1" }, { "input": "3 4", "output": "1010101" }, { "input": "3 10", "output": "-1" }, { "input": "74 99", "output": "11011011011011011011011011011011011011011011011011011011011011011011011010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" }, { "input": "19 30", "output": "1101101101101101101101101101101010101010101010101" }, { "input": "33 77", "output": "-1" }, { "input": "3830 6966", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "1000000 1000000", "output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..." }, { "input": "1027 2030", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "4610 4609", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "3342 3339", "output": "-1" }, { "input": "7757 7755", "output": "-1" }, { "input": "10 8", "output": "-1" }, { "input": "4247 8495", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "7101 14204", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "9801 19605", "output": "-1" }, { "input": "4025 6858", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "7129 13245", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "8826 12432", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "6322 9256", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "8097 14682", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "6196 6197", "output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..." }, { "input": "1709 2902", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "455 512", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..." }, { "input": "1781 1272", "output": "-1" }, { "input": "3383 5670", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "954 1788", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "9481 15554", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "9079 100096", "output": "-1" }, { "input": "481533 676709", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "423472 564888", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "227774 373297", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "42346 51898", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "739107 1000000", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "455043 798612", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "801460 801459", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "303498 503791", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "518822 597833", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "32342 64687", "output": "-1" }, { "input": "873192 873189", "output": "-1" }, { "input": "384870 450227", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "201106 208474", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "775338 980888", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "263338 393171", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "241043 330384", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "307203 614408", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "379310 417986", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "661101 785111", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "284634 319008", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "500000 1000000", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "499999 1000000", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "3 1", "output": "-1" }, { "input": "14124 242112", "output": "-1" }, { "input": "2 1", "output": "010" }, { "input": "2 3", "output": "10101" }, { "input": "1 4", "output": "11011" }, { "input": "2 6", "output": "11011011" }, { "input": "2 5", "output": "1101101" }, { "input": "2 4", "output": "110101" }, { "input": "2 3", "output": "10101" }, { "input": "2 2", "output": "1010" }, { "input": "2 1", "output": "010" }, { "input": "1 1", "output": "10" }, { "input": "1 3", "output": "1101" }, { "input": "3 2", "output": "01010" }, { "input": "5 4", "output": "010101010" }, { "input": "4 3", "output": "0101010" }, { "input": "11 10", "output": "010101010101010101010" }, { "input": "8 7", "output": "010101010101010" }, { "input": "4 2", "output": "-1" }, { "input": "6 5", "output": "01010101010" }, { "input": "3 7", "output": "1101101101" }, { "input": "5 1", "output": "-1" }, { "input": "10 1", "output": "-1" }, { "input": "4 9", "output": "1101101101101" }, { "input": "6 4", "output": "-1" }, { "input": "12 10", "output": "-1" }, { "input": "4 100", "output": "-1" } ]
1,599,623,228
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
13
327
33,382,400
# import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') n, m = list(map(int, input().split())) # if m not in range(n-1, 2*(n+1)+1): # print(-1) # exit() ans = ['0']*n for i in range(n): if m: ans[i] += '1' m -= 1 if not m: break for i in range(n): if m: ans[i] += '1' m -= 1 if not m: break ans[0] = '1'*min(m, 2) + ans[0] m -= min(m, 2) # print(ans) if not m: print(''.join(ans)) else: print(-1)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: - there wouldn't be a pair of any side-adjacent cards with zeroes in a row; - there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought *n* cards with zeroes and *m* cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input Specification: The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. Output Specification: In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Demo Input: ['1 2\n', '4 8\n', '4 10\n', '1 5\n'] Demo Output: ['101\n', '110110110101\n', '11011011011011\n', '-1\n'] Note: none
```python # import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') n, m = list(map(int, input().split())) # if m not in range(n-1, 2*(n+1)+1): # print(-1) # exit() ans = ['0']*n for i in range(n): if m: ans[i] += '1' m -= 1 if not m: break for i in range(n): if m: ans[i] += '1' m -= 1 if not m: break ans[0] = '1'*min(m, 2) + ans[0] m -= min(m, 2) # print(ans) if not m: print(''.join(ans)) else: print(-1) ```
0
12
A
Super Agent
PROGRAMMING
800
[ "implementation" ]
A. Super Agent
2
256
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base. Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9. Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
[ "XX.\n...\n.XX\n", "X.X\nX..\n...\n" ]
[ "YES\n", "NO\n" ]
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry
0
[ { "input": "XX.\n...\n.XX", "output": "YES" }, { "input": ".X.\n.X.\n.X.", "output": "YES" }, { "input": "XXX\nXXX\nXXX", "output": "YES" }, { "input": "XXX\nX.X\nXXX", "output": "YES" }, { "input": "X..\n.X.\n..X", "output": "YES" }, { "input": "...\nX.X\nX..", "output": "NO" }, { "input": ".X.\nX.X\n.X.", "output": "YES" }, { "input": "X.X\n.X.\nX.X", "output": "YES" }, { "input": "...\n...\n..X", "output": "NO" }, { "input": "XXX\n...\nXXX", "output": "YES" }, { "input": "..X\nX..\n..X", "output": "NO" }, { "input": ".X.\n...\nX.X", "output": "NO" }, { "input": "X.X\nX.X\nX.X", "output": "YES" }, { "input": ".X.\nX.X\nXX.", "output": "NO" }, { "input": "...\nXXX\nXXX", "output": "NO" }, { "input": "XXX\n..X\nXXX", "output": "NO" }, { "input": "X..\nX.X\n.X.", "output": "NO" }, { "input": "...\n..X\nXXX", "output": "NO" }, { "input": "..X\nX.X\nX..", "output": "YES" }, { "input": "..X\n..X\nXXX", "output": "NO" }, { "input": "X..\nX..\nX..", "output": "NO" }, { "input": "XXX\n.X.\nXXX", "output": "YES" }, { "input": "..X\n...\nX..", "output": "YES" }, { "input": "...\n...\nX..", "output": "NO" }, { "input": "...\n...\n.X.", "output": "NO" }, { "input": "...\n...\n..X", "output": "NO" }, { "input": "...\n.X.\nX..", "output": "NO" } ]
1,587,715,789
2,147,483,647
Python 3
OK
TESTS
40
218
0
a=[] for i in range(3): a.append(input()) if (a[0][0]!=a[2][2] or a[0][1]!=a[2][1] or a[0][2]!=a[2][0] or a[1][0]!=a[1][2]): print('NO') else: print('YES')
Title: Super Agent Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base. Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9. Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. Input Specification: Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». Output Specification: Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. Demo Input: ['XX.\n...\n.XX\n', 'X.X\nX..\n...\n'] Demo Output: ['YES\n', 'NO\n'] Note: If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry
```python a=[] for i in range(3): a.append(input()) if (a[0][0]!=a[2][2] or a[0][1]!=a[2][1] or a[0][2]!=a[2][0] or a[1][0]!=a[1][2]): print('NO') else: print('YES') ```
3.9455
340
A
The Wall
PROGRAMMING
1,200
[ "math" ]
null
null
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink. After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
[ "2 3 6 18\n" ]
[ "3" ]
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
500
[ { "input": "2 3 6 18", "output": "3" }, { "input": "4 6 20 201", "output": "15" }, { "input": "15 27 100 10000", "output": "74" }, { "input": "105 60 3456 78910", "output": "179" }, { "input": "1 1 1000 100000", "output": "99001" }, { "input": "3 2 5 5", "output": "0" }, { "input": "555 777 1 1000000", "output": "257" }, { "input": "1000 1000 1 32323", "output": "32" }, { "input": "45 125 93451125 100000000", "output": "5821" }, { "input": "101 171 1 1000000000", "output": "57900" }, { "input": "165 255 69696 1000000000", "output": "356482" }, { "input": "555 777 666013 1000000000", "output": "257229" }, { "input": "23 46 123321 900000000", "output": "19562537" }, { "input": "321 123 15 1000000", "output": "75" }, { "input": "819 1000 9532 152901000", "output": "186" }, { "input": "819 1000 10000 1000000", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 2 2 1000003", "output": "500001" }, { "input": "1 1 1 1000000000", "output": "1000000000" }, { "input": "10 15 69 195610342", "output": "6520342" }, { "input": "2 1 1 1000000000", "output": "500000000" }, { "input": "1000 1000 1 20", "output": "0" }, { "input": "1 1 1 2000000000", "output": "2000000000" }, { "input": "1 2 1 2000000000", "output": "1000000000" }, { "input": "2 1 1 2000000000", "output": "1000000000" }, { "input": "2 3 1 1000000000", "output": "166666666" }, { "input": "2 3 1 2000000000", "output": "333333333" }, { "input": "3 7 1 1000000000", "output": "47619047" }, { "input": "1 1 1000000000 2000000000", "output": "1000000001" }, { "input": "2 2 1 2000000000", "output": "1000000000" }, { "input": "1 1 2 2000000000", "output": "1999999999" }, { "input": "3 2 1 2000000000", "output": "333333333" }, { "input": "1 1 2000000000 2000000000", "output": "1" }, { "input": "2 3 7 7", "output": "0" }, { "input": "3 3 3 7", "output": "2" } ]
1,644,255,201
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
from math import gcd x,y,a,b=map(int,input().split()) l=(x)*(y)//gcd(x,y) if l>=a: gap=max(0,b-l) print(gap//l+(1 if l==a or b%l==0 else 0)) else : d=a%l start=a+l-d gap=max(0,b-start) print(gap//l+1)
Title: The Wall Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink. After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question. Input Specification: The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). Output Specification: Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. Demo Input: ['2 3 6 18\n'] Demo Output: ['3'] Note: Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
```python from math import gcd x,y,a,b=map(int,input().split()) l=(x)*(y)//gcd(x,y) if l>=a: gap=max(0,b-l) print(gap//l+(1 if l==a or b%l==0 else 0)) else : d=a%l start=a+l-d gap=max(0,b-start) print(gap//l+1) ```
0
912
B
New Year's Eve
PROGRAMMING
1,300
[ "bitmasks", "constructive algorithms", "number theory" ]
null
null
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output one number — the largest possible xor-sum.
[ "4 3\n", "6 6\n" ]
[ "7\n", "7\n" ]
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
1,000
[ { "input": "4 3", "output": "7" }, { "input": "6 6", "output": "7" }, { "input": "2 2", "output": "3" }, { "input": "1022 10", "output": "1023" }, { "input": "415853337373441 52", "output": "562949953421311" }, { "input": "75 12", "output": "127" }, { "input": "1000000000000000000 1000000000000000000", "output": "1152921504606846975" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000000000 2", "output": "1152921504606846975" }, { "input": "49194939 22", "output": "67108863" }, { "input": "228104606 17", "output": "268435455" }, { "input": "817034381 7", "output": "1073741823" }, { "input": "700976748 4", "output": "1073741823" }, { "input": "879886415 9", "output": "1073741823" }, { "input": "18007336 10353515", "output": "33554431" }, { "input": "196917003 154783328", "output": "268435455" }, { "input": "785846777 496205300", "output": "1073741823" }, { "input": "964756444 503568330", "output": "1073741823" }, { "input": "848698811 317703059", "output": "1073741823" }, { "input": "676400020444788 1", "output": "676400020444788" }, { "input": "502643198528213 1", "output": "502643198528213" }, { "input": "815936580997298686 684083143940282566", "output": "1152921504606846975" }, { "input": "816762824175382110 752185261508428780", "output": "1152921504606846975" }, { "input": "327942415253132295 222598158321260499", "output": "576460752303423487" }, { "input": "328768654136248423 284493129147496637", "output": "576460752303423487" }, { "input": "329594893019364551 25055600080496801", "output": "576460752303423487" }, { "input": "921874985256864012 297786684518764536", "output": "1152921504606846975" }, { "input": "922701224139980141 573634416190460758", "output": "1152921504606846975" }, { "input": "433880815217730325 45629641110945892", "output": "576460752303423487" }, { "input": "434707058395813749 215729375494216481", "output": "576460752303423487" }, { "input": "435533301573897173 34078453236225189", "output": "576460752303423487" }, { "input": "436359544751980597 199220719961060641", "output": "576460752303423487" }, { "input": "437185783635096725 370972992240105630", "output": "576460752303423487" }, { "input": "438012026813180149 111323110116193830", "output": "576460752303423487" }, { "input": "438838269991263573 295468957052046146", "output": "576460752303423487" }, { "input": "439664513169346997 46560240538186155", "output": "576460752303423487" }, { "input": "440490752052463125 216165966013438147", "output": "576460752303423487" }, { "input": "441316995230546549 401964286420555423", "output": "576460752303423487" }, { "input": "952496582013329437 673506882352402278", "output": "1152921504606846975" }, { "input": "1000000000000000000 1", "output": "1000000000000000000" }, { "input": "2147483647 1", "output": "2147483647" }, { "input": "2147483647 2", "output": "2147483647" }, { "input": "2147483647 31", "output": "2147483647" }, { "input": "8 2", "output": "15" }, { "input": "3 3", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "10 2", "output": "15" }, { "input": "288230376151711743 2", "output": "288230376151711743" }, { "input": "5 2", "output": "7" }, { "input": "576460752303423487 2", "output": "576460752303423487" }, { "input": "36028797018963967 123", "output": "36028797018963967" }, { "input": "1125899906842623 2", "output": "1125899906842623" }, { "input": "576460752303423489 5", "output": "1152921504606846975" }, { "input": "288230376151711743 3", "output": "288230376151711743" }, { "input": "36028797018963967 345", "output": "36028797018963967" }, { "input": "18014398509481984 30", "output": "36028797018963967" }, { "input": "8 8", "output": "15" }, { "input": "8 1", "output": "8" } ]
1,622,909,910
2,147,483,647
PyPy 3
OK
TESTS
58
140
0
n, k = map(int, input().split()) print(2**(len(bin(n))-2)-1 if k>1 else n)
Title: New Year's Eve Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. Input Specification: The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). Output Specification: Output one number — the largest possible xor-sum. Demo Input: ['4 3\n', '6 6\n'] Demo Output: ['7\n', '7\n'] Note: In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
```python n, k = map(int, input().split()) print(2**(len(bin(n))-2)-1 if k>1 else n) ```
3
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,693,852,013
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
s = input() flag = False for c in s: if ord(c) == ord('H') or ord(c) == ord('Q') or ord(c) == ord('9') or ord(c) == ord('+'): flag = True if flag: print('YES') else: print('NO')
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python s = input() flag = False for c in s: if ord(c) == ord('H') or ord(c) == ord('Q') or ord(c) == ord('9') or ord(c) == ord('+'): flag = True if flag: print('YES') else: print('NO') ```
0
376
B
I.O.U.
PROGRAMMING
1,300
[ "implementation" ]
null
null
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The debts still mean the same but the total sum of the debts now equals 20 rubles. This task is a generalisation of a described example. Imagine that your group of friends has *n* people and you know the debts between the people. Optimize the given debts without changing their meaning. In other words, finally for each friend the difference between the total money he should give and the total money he should take must be the same. Print the minimum sum of all debts in the optimal rearrangement of the debts. See the notes to the test samples to better understand the problem.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i* rubles. Assume that the people are numbered by integers from 1 to *n*. It is guaranteed that the same pair of people occurs at most once in the input. The input doesn't simultaneously contain pair of people (*x*,<=*y*) and pair of people (*y*,<=*x*).
Print a single integer — the minimum sum of debts in the optimal rearrangement.
[ "5 3\n1 2 10\n2 3 1\n2 4 1\n", "3 0\n", "4 3\n1 2 1\n2 3 1\n3 1 1\n" ]
[ "10\n", "0\n", "0\n" ]
In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.
1,000
[ { "input": "5 3\n1 2 10\n2 3 1\n2 4 1", "output": "10" }, { "input": "3 0", "output": "0" }, { "input": "4 3\n1 2 1\n2 3 1\n3 1 1", "output": "0" }, { "input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\n5 17 8\n6 9 9\n6 16 2\n6 19 9\n7 14 6\n8 9 3\n8 16 10\n9 11 7\n9 17 8\n11 13 8\n11 17 17\n11 19 1\n15 20 2\n17 20 1", "output": "124" }, { "input": "20 36\n1 2 13\n1 3 1\n1 6 4\n1 12 8\n1 13 9\n1 15 3\n1 18 4\n2 10 2\n2 15 2\n2 18 6\n3 7 8\n3 16 19\n4 7 1\n4 18 4\n5 9 2\n5 15 9\n5 17 4\n5 18 5\n6 11 7\n6 13 1\n6 14 9\n7 10 4\n7 12 10\n7 15 9\n7 17 8\n8 14 4\n10 13 8\n10 19 9\n11 12 5\n12 17 6\n13 15 8\n13 19 4\n14 15 9\n14 16 8\n17 19 8\n17 20 7", "output": "147" }, { "input": "20 40\n1 13 4\n2 3 3\n2 4 5\n2 7 7\n2 17 10\n3 5 3\n3 6 9\n3 10 4\n3 12 2\n3 13 2\n3 14 3\n4 5 4\n4 8 7\n4 13 9\n5 6 14\n5 14 5\n7 11 5\n7 12 13\n7 15 7\n8 14 5\n8 16 7\n8 18 17\n9 11 8\n9 19 19\n10 12 4\n10 16 3\n10 18 10\n10 20 9\n11 13 9\n11 20 2\n12 13 8\n12 18 2\n12 20 3\n13 17 1\n13 20 4\n14 16 8\n16 19 3\n18 19 3\n18 20 7\n19 20 10", "output": "165" }, { "input": "50 10\n1 5 1\n2 34 2\n3 8 10\n5 28 4\n7 28 6\n13 49 9\n15 42 7\n16 26 7\n18 47 5\n20 41 10", "output": "60" }, { "input": "50 46\n1 6 10\n1 18 1\n1 24 10\n1 33 2\n1 40 8\n3 16 7\n4 26 8\n4 32 2\n4 34 6\n5 29 8\n6 44 3\n8 20 5\n8 42 13\n10 13 5\n10 25 7\n10 27 9\n10 29 10\n11 23 4\n12 28 7\n12 30 10\n12 40 10\n13 18 2\n13 33 2\n14 15 7\n14 43 10\n14 47 3\n16 27 10\n17 21 6\n17 30 9\n19 40 4\n22 24 8\n22 25 7\n22 38 18\n25 38 1\n27 31 7\n27 40 8\n30 36 8\n31 34 1\n32 49 6\n33 35 4\n33 50 7\n38 47 1\n42 47 2\n42 50 5\n43 44 9\n47 50 5", "output": "228" }, { "input": "100 48\n1 56 6\n2 42 3\n3 52 1\n9 50 8\n10 96 8\n11 39 2\n12 51 6\n12 68 7\n13 40 5\n14 18 10\n14 70 6\n15 37 4\n15 38 8\n15 82 6\n15 85 5\n16 48 4\n16 50 9\n16 71 9\n17 18 3\n17 100 10\n20 73 3\n22 32 9\n22 89 9\n23 53 3\n24 53 1\n27 78 10\n30 50 5\n33 94 8\n34 87 9\n35 73 3\n36 51 8\n37 88 10\n37 97 2\n40 47 8\n40 90 6\n44 53 3\n44 65 3\n47 48 8\n48 72 10\n49 98 2\n53 68 10\n53 71 9\n57 62 2\n63 76 10\n66 90 9\n71 76 8\n72 80 5\n75 77 7", "output": "253" }, { "input": "4 3\n1 4 1\n2 3 1\n4 2 2", "output": "2" } ]
1,620,851,176
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
46
7,065,600
import math import random def main(arr,n): ans=0 owe=[0]*(n) for i in range(len(arr)): a,b,c=arr[i] owe[a]+=c owe[b]-=c return sum([x for x in owe if x>0]) n,m=list(map(int,input().split())) arr=[] for i in range(m): arr.append(list(map(int,input().split()))) print(main(arr,n))
Title: I.O.U. Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The debts still mean the same but the total sum of the debts now equals 20 rubles. This task is a generalisation of a described example. Imagine that your group of friends has *n* people and you know the debts between the people. Optimize the given debts without changing their meaning. In other words, finally for each friend the difference between the total money he should give and the total money he should take must be the same. Print the minimum sum of all debts in the optimal rearrangement of the debts. See the notes to the test samples to better understand the problem. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i* rubles. Assume that the people are numbered by integers from 1 to *n*. It is guaranteed that the same pair of people occurs at most once in the input. The input doesn't simultaneously contain pair of people (*x*,<=*y*) and pair of people (*y*,<=*x*). Output Specification: Print a single integer — the minimum sum of debts in the optimal rearrangement. Demo Input: ['5 3\n1 2 10\n2 3 1\n2 4 1\n', '3 0\n', '4 3\n1 2 1\n2 3 1\n3 1 1\n'] Demo Output: ['10\n', '0\n', '0\n'] Note: In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.
```python import math import random def main(arr,n): ans=0 owe=[0]*(n) for i in range(len(arr)): a,b,c=arr[i] owe[a]+=c owe[b]-=c return sum([x for x in owe if x>0]) n,m=list(map(int,input().split())) arr=[] for i in range(m): arr.append(list(map(int,input().split()))) print(main(arr,n)) ```
-1
626
B
Cards
PROGRAMMING
1,300
[ "constructive algorithms", "dp", "math" ]
null
null
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n" ]
[ "G\n", "BR\n", "B\n" ]
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
750
[ { "input": "2\nRB", "output": "G" }, { "input": "3\nGRG", "output": "BR" }, { "input": "5\nBBBBB", "output": "B" }, { "input": "1\nR", "output": "R" }, { "input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB", "output": "BGR" }, { "input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BG" }, { "input": "7\nBBBGBRG", "output": "BGR" }, { "input": "5\nGRRGR", "output": "BGR" }, { "input": "3\nGBR", "output": "BGR" }, { "input": "1\nB", "output": "B" }, { "input": "2\nBB", "output": "B" }, { "input": "1\nG", "output": "G" }, { "input": "2\nBG", "output": "R" }, { "input": "3\nBGB", "output": "GR" }, { "input": "2\nGG", "output": "G" }, { "input": "3\nGBG", "output": "BR" }, { "input": "4\nBGBG", "output": "BGR" }, { "input": "1\nR", "output": "R" }, { "input": "2\nBR", "output": "G" }, { "input": "3\nBRB", "output": "GR" }, { "input": "2\nRG", "output": "B" }, { "input": "3\nBGR", "output": "BGR" }, { "input": "4\nRBGB", "output": "BGR" }, { "input": "3\nGGR", "output": "BR" }, { "input": "4\nGGRB", "output": "BGR" }, { "input": "5\nBGBGR", "output": "BGR" }, { "input": "2\nRR", "output": "R" }, { "input": "3\nRBR", "output": "BG" }, { "input": "4\nRRBB", "output": "BGR" }, { "input": "3\nRRG", "output": "BG" }, { "input": "4\nBRRG", "output": "BGR" }, { "input": "5\nRBRBG", "output": "BGR" }, { "input": "4\nRGGR", "output": "BGR" }, { "input": "5\nBRGRG", "output": "BGR" }, { "input": "6\nGRRGBB", "output": "BGR" }, { "input": "150\nGRGBBBBRBGGBGBBGBBBBGRBBRRBBGRRGGGBRBBRGRRRRGBGRRBGBGBGRBBBGBBBGBGBRGBRRRRRGGGRGRBBGBRGGGRBBRGBBGRGGGBBRBRRGRGRRGRRGRRRGBGBRRGGRGGBRBGGGBBBRGRGBRGRRRR", "output": "BGR" }, { "input": "16\nRRGRRRRRRGGRGRRR", "output": "BGR" }, { "input": "190\nBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "GR" }, { "input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR", "output": "BGR" }, { "input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "G" }, { "input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BGR" }, { "input": "200\nGRGRRGRBRRRGGGRGGRRRRRBBGRRGRBBGRRGBGRRBBRBBRRBBBGRBRGGGGBGGBRRBBRGRBGGRRGGBBRBGGRGBBRRBBRGBRRBGBRBGBBRGGRRRGGGBRGGGGRRRBBRRGRGRBRRGRBBGGRBBRGRGRBGRBBRGGBBBGRGBBGGBGBGBBRRBGRGRGGBRRGRGGGGGBRGGGGBBBBRB", "output": "BGR" }, { "input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "BGR" }, { "input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG", "output": "BGR" }, { "input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB", "output": "BGR" }, { "input": "3\nGGB", "output": "BR" } ]
1,455,386,585
1,685
Python 3
WRONG_ANSWER
PRETESTS
7
61
512,000
import collections import math n = int(input()) s = input() a, b, c = s.count('B'), s.count('G'), s.count('R') if a * b * c != 0: print('BGR') elif a != 0 and b == 0 and c == 0: print('B') elif a == 0 and b != 0 and c == 0: print('G') elif a == 0 and b == 0 and c != 0: print('R') elif a == 0: if b == c: print('B') elif b > c: print('BR') else: print('BG') elif b == 0: if a == c: print('G') elif a > c: print('GR') else: print('BG') elif c == 0: if b == a: print('R') elif b > a: print('BR') else: print('GR')
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. Output Specification: Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. Demo Input: ['2\nRB\n', '3\nGRG\n', '5\nBBBBB\n'] Demo Output: ['G\n', 'BR\n', 'B\n'] Note: In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
```python import collections import math n = int(input()) s = input() a, b, c = s.count('B'), s.count('G'), s.count('R') if a * b * c != 0: print('BGR') elif a != 0 and b == 0 and c == 0: print('B') elif a == 0 and b != 0 and c == 0: print('G') elif a == 0 and b == 0 and c != 0: print('R') elif a == 0: if b == c: print('B') elif b > c: print('BR') else: print('BG') elif b == 0: if a == c: print('G') elif a > c: print('GR') else: print('BG') elif c == 0: if b == a: print('R') elif b > a: print('BR') else: print('GR') ```
0
703
A
Mishka and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
[ "3\n3 5\n2 1\n4 2\n", "2\n6 1\n1 6\n", "3\n1 5\n3 3\n2 2\n" ]
[ "Mishka", "Friendship is magic!^^", "Chris" ]
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
500
[ { "input": "3\n3 5\n2 1\n4 2", "output": "Mishka" }, { "input": "2\n6 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "3\n1 5\n3 3\n2 2", "output": "Chris" }, { "input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "output": "Mishka" }, { "input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5", "output": "Chris" }, { "input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5", "output": "Friendship is magic!^^" }, { "input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3", "output": "Mishka" }, { "input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1", "output": "Chris" }, { "input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4", "output": "Mishka" }, { "input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1", "output": "Chris" }, { "input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3", "output": "Chris" }, { "input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4", "output": "Mishka" }, { "input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3", "output": "Mishka" }, { "input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3", "output": "Mishka" }, { "input": "5\n3 6\n3 5\n3 5\n1 6\n3 5", "output": "Chris" }, { "input": "4\n4 1\n2 4\n5 3\n3 6", "output": "Friendship is magic!^^" }, { "input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2", "output": "Mishka" }, { "input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4", "output": "Chris" }, { "input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6", "output": "Friendship is magic!^^" }, { "input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1", "output": "Mishka" }, { "input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5", "output": "Chris" }, { "input": "4\n6 2\n2 4\n4 2\n3 6", "output": "Friendship is magic!^^" }, { "input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2", "output": "Mishka" }, { "input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4", "output": "Chris" }, { "input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5", "output": "Friendship is magic!^^" }, { "input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1", "output": "Mishka" }, { "input": "5\n1 4\n2 5\n3 4\n2 6\n3 4", "output": "Chris" }, { "input": "4\n6 2\n3 4\n5 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1", "output": "Mishka" }, { "input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4", "output": "Chris" }, { "input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4", "output": "Friendship is magic!^^" }, { "input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3", "output": "Mishka" }, { "input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4", "output": "Chris" }, { "input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6", "output": "Friendship is magic!^^" }, { "input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2", "output": "Mishka" }, { "input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4", "output": "Chris" }, { "input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4", "output": "Friendship is magic!^^" }, { "input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1", "output": "Mishka" }, { "input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4", "output": "Chris" }, { "input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4", "output": "Friendship is magic!^^" }, { "input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1", "output": "Mishka" }, { "input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6", "output": "Chris" }, { "input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4", "output": "Friendship is magic!^^" }, { "input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1", "output": "Mishka" }, { "input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4", "output": "Chris" }, { "input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4", "output": "Friendship is magic!^^" }, { "input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3", "output": "Mishka" }, { "input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1", "output": "Chris" }, { "input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4", "output": "Mishka" }, { "input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1", "output": "Chris" }, { "input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6", "output": "Mishka" }, { "input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4", "output": "Chris" }, { "input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4", "output": "Mishka" }, { "input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3", "output": "Mishka" }, { "input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5", "output": "Chris" }, { "input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3", "output": "Chris" }, { "input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6", "output": "Mishka" }, { "input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2", "output": "Mishka" }, { "input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1", "output": "Chris" }, { "input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2", "output": "Chris" }, { "input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5", "output": "Mishka" }, { "input": "1\n1 1", "output": "Friendship is magic!^^" } ]
1,689,658,293
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
30
0
s=0 s1=0 for i in range(int(input())): a,b=map(int,input().split()) s = s + a s1 = s1 + b if s>s1: print("Mishka") elif s<s1: print("Chris") else: print("Friendship is magic!^^")
Title: Mishka and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input Specification: The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. Output Specification: If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Demo Input: ['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n'] Demo Output: ['Mishka', 'Friendship is magic!^^', 'Chris'] Note: In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
```python s=0 s1=0 for i in range(int(input())): a,b=map(int,input().split()) s = s + a s1 = s1 + b if s>s1: print("Mishka") elif s<s1: print("Chris") else: print("Friendship is magic!^^") ```
0
900
D
Unusual Sequences
PROGRAMMING
2,000
[ "bitmasks", "combinatorics", "dp", "math", "number theory" ]
null
null
Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answer modulo 109<=+<=7. *gcd* here means the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
The only line contains two positive integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=109).
Print the number of such sequences modulo 109<=+<=7.
[ "3 9\n", "5 8\n" ]
[ "3\n", "0\n" ]
There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3). There are no suitable sequences in the second test.
2,000
[ { "input": "3 9", "output": "3" }, { "input": "5 8", "output": "0" }, { "input": "2 12", "output": "27" }, { "input": "1 8", "output": "120" }, { "input": "1 9", "output": "252" }, { "input": "1000000000 1000000000", "output": "1" }, { "input": "1000000000 1", "output": "0" }, { "input": "1 1000000000", "output": "824916815" }, { "input": "1 223092870", "output": "521342052" }, { "input": "1 1", "output": "1" }, { "input": "1 994593600", "output": "558135120" }, { "input": "1 425613469", "output": "455729363" }, { "input": "495219 444706662", "output": "115165527" }, { "input": "9357 18255507", "output": "745979764" }, { "input": "741547455 471761895", "output": "0" }, { "input": "225 315096300", "output": "413133630" }, { "input": "183612440 509579899", "output": "0" }, { "input": "231096994 462193988", "output": "1" }, { "input": "34601 35742833", "output": "60054095" }, { "input": "417485019 230941257", "output": "0" }, { "input": "524 991033864", "output": "172439543" }, { "input": "859550004 563726557", "output": "0" }, { "input": "1 282521795", "output": "436596181" }, { "input": "415879151 194713963", "output": "0" }, { "input": "109936444 989427996", "output": "252" } ]
1,513,400,100
2,147,483,647
Python 3
OK
TESTS
25
109
6,758,400
#!/usr/bin/env python3 from fractions import gcd from operator import mul from functools import reduce from itertools import combinations eval_function = lambda x: lambda f: f(x) @eval_function(int((10**9)**0.5)) def prime(n): sieve = [True] * (n+1) sieve[0] = sieve[1] = False index = 2 for i in range(int(len(sieve)**0.5)): if sieve[i]: for j in range(2*i, len(sieve), i): sieve[j] = False index += 1 return [i for i, is_prime in enumerate(sieve) if is_prime] def factorized(n): factors = [] for i in prime: if i**2 > n: break while not n % i: factors += [i] n //= i if n > 1: factors += [n] return factors def solve(x, y, mod=None): if gcd(x, y) != x: return 0 y = y//x c = pow(2, y-1, mod) unique_factors = set(factorized(y)) for i in range(1, len(unique_factors)+1): for divisor in combinations(unique_factors, i): d = reduce(mul, divisor) c += (-1)**i * pow(2, y//d-1, mod) c %= mod return c def main(): x, y = [int(n) for n in input().split()] print(solve(x, y, 10**9+7)) if __name__ == '__main__': main()
Title: Unusual Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answer modulo 109<=+<=7. *gcd* here means the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). Input Specification: The only line contains two positive integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=109). Output Specification: Print the number of such sequences modulo 109<=+<=7. Demo Input: ['3 9\n', '5 8\n'] Demo Output: ['3\n', '0\n'] Note: There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3). There are no suitable sequences in the second test.
```python #!/usr/bin/env python3 from fractions import gcd from operator import mul from functools import reduce from itertools import combinations eval_function = lambda x: lambda f: f(x) @eval_function(int((10**9)**0.5)) def prime(n): sieve = [True] * (n+1) sieve[0] = sieve[1] = False index = 2 for i in range(int(len(sieve)**0.5)): if sieve[i]: for j in range(2*i, len(sieve), i): sieve[j] = False index += 1 return [i for i, is_prime in enumerate(sieve) if is_prime] def factorized(n): factors = [] for i in prime: if i**2 > n: break while not n % i: factors += [i] n //= i if n > 1: factors += [n] return factors def solve(x, y, mod=None): if gcd(x, y) != x: return 0 y = y//x c = pow(2, y-1, mod) unique_factors = set(factorized(y)) for i in range(1, len(unique_factors)+1): for divisor in combinations(unique_factors, i): d = reduce(mul, divisor) c += (-1)**i * pow(2, y//d-1, mod) c %= mod return c def main(): x, y = [int(n) for n in input().split()] print(solve(x, y, 10**9+7)) if __name__ == '__main__': main() ```
3
18
C
Stripe
PROGRAMMING
1,200
[ "data structures", "implementation" ]
C. Stripe
2
64
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
[ "9\n1 5 -6 7 9 -16 0 -2 2\n", "3\n1 1 1\n", "2\n0 0\n" ]
[ "3\n", "0\n", "1\n" ]
none
0
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2", "output": "3" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "4\n100 1 10 111", "output": "1" }, { "input": "10\n0 4 -3 0 -2 2 -3 -3 2 5", "output": "3" }, { "input": "10\n0 -1 2 2 -1 1 0 0 0 2", "output": "0" }, { "input": "10\n-1 -1 1 -1 0 1 0 1 1 1", "output": "1" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "9" }, { "input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3", "output": "3" }, { "input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3", "output": "0" }, { "input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2", "output": "0" }, { "input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2", "output": "1" }, { "input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2", "output": "6" }, { "input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n10000", "output": "0" }, { "input": "1\n-10000", "output": "0" } ]
1,670,446,961
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
18
2,000
1,331,200
n=int(input()) l=list(map(int,input().split())) c=0 cu=0 for i in range(n-1): cu+=l[i] if cu==sum(l[i+1:]): c+=1 print(c)
Title: Stripe Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem? Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. Output Specification: Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. Demo Input: ['9\n1 5 -6 7 9 -16 0 -2 2\n', '3\n1 1 1\n', '2\n0 0\n'] Demo Output: ['3\n', '0\n', '1\n'] Note: none
```python n=int(input()) l=list(map(int,input().split())) c=0 cu=0 for i in range(n-1): cu+=l[i] if cu==sum(l[i+1:]): c+=1 print(c) ```
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,654,765,608
2,147,483,647
Python 3
OK
TESTS
42
46
0
n=int(input()) a=list(map(int,input().split())) c=a.index(max(a))+1 a.remove(max(a)) print(c,max(a))
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()) a=list(map(int,input().split())) c=a.index(max(a))+1 a.remove(max(a)) print(c,max(a)) ```
3
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson?
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "input": "4 2", "output": "2" }, { "input": "1000 700", "output": "6" }, { "input": "959986566087 524054155168", "output": "90" }, { "input": "4 3", "output": "4" }, { "input": "7 6", "output": "7" }, { "input": "1000 999", "output": "1000" }, { "input": "1000 998", "output": "500" }, { "input": "1000 997", "output": "336" }, { "input": "42 1", "output": "42" }, { "input": "1000 1", "output": "1000" }, { "input": "8 5", "output": "5" }, { "input": "13 8", "output": "6" }, { "input": "987 610", "output": "15" }, { "input": "442 42", "output": "22" }, { "input": "754 466", "output": "13" }, { "input": "1000000000000 999999999999", "output": "1000000000000" }, { "input": "1000000000000 999999999998", "output": "500000000000" }, { "input": "941 14", "output": "74" }, { "input": "998 2", "output": "499" }, { "input": "1000 42", "output": "32" }, { "input": "1000 17", "output": "66" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "4" }, { "input": "5 3", "output": "4" }, { "input": "5 4", "output": "5" }, { "input": "293 210", "output": "17" }, { "input": "787878787878 424242424242", "output": "8" }, { "input": "956722026041 591286729879", "output": "58" }, { "input": "956722026041 365435296162", "output": "58" }, { "input": "628625247282 464807889701", "output": "102" }, { "input": "695928431619 424778620208", "output": "167" }, { "input": "1000000000000 42", "output": "23809523821" }, { "input": "987654345678 23", "output": "42941493300" }, { "input": "10000000001 2", "output": "5000000002" }, { "input": "1000000000000 2", "output": "500000000000" }, { "input": "1000000000000 3", "output": "333333333336" }, { "input": "100000000000 3", "output": "33333333336" }, { "input": "100000000000 23", "output": "4347826109" }, { "input": "999999999997 7", "output": "142857142861" }, { "input": "8589934592 4294967296", "output": "2" } ]
1,514,005,863
2,147,483,647
Python 3
OK
TESTS
46
62
5,529,600
a,b=map(int,input().split()) if(a==b): print("1") exit(0) count=0 while(a!=b): if(a>b): count+=int(a/b) a=a%b elif(b>a): count+=int(b/a) b=b%a if(a==0 or b==0): break print(count)
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? Input Specification: The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Output Specification: Print a single integer — the number of ships that Vasya will make. Demo Input: ['2 1\n', '10 7\n', '1000000000000 1\n'] Demo Output: ['2\n', '6\n', '1000000000000\n'] Note: Pictures to the first and second sample test.
```python a,b=map(int,input().split()) if(a==b): print("1") exit(0) count=0 while(a!=b): if(a>b): count+=int(a/b) a=a%b elif(b>a): count+=int(b/a) b=b%a if(a==0 or b==0): break print(count) ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,677,428,888
2,147,483,647
Python 3
OK
TESTS
71
92
0
''''' ................... ♥ ♥ صلي علي محمد ♥ ♥ ........... ''''' word = str (input()).upper() list_contain_word = [] for i in word : if "WUB" in word: word = word.replace("WUB"," ") for i in word : print(i , end = "")
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python ''''' ................... ♥ ♥ صلي علي محمد ♥ ♥ ........... ''''' word = str (input()).upper() list_contain_word = [] for i in word : if "WUB" in word: word = word.replace("WUB"," ") for i in word : print(i , end = "") ```
3
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo" }, { "input": "805", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "1000", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "1", "output": "O" }, { "input": "2", "output": "OO" }, { "input": "3", "output": "OOO" }, { "input": "5", "output": "OOOoO" }, { "input": "17", "output": "OOOoOooOooooOoooo" }, { "input": "49", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo" }, { "input": "256", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo" }, { "input": "512", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "933", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "61", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo" }, { "input": "781", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "999", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." } ]
1,683,727,710
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
n=(int(input)) l=[1] s1=1 s2=1 s=0 while s<n: s=s1+s2 s1=s2 s2=s l.append(s) ch="" for i in range(1,n+1) if i in l ch='O' else ch='o' print(ch)
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. Input Specification: The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: Print Eleven's new name on the first and only line of output. Demo Input: ['8\n', '15\n'] Demo Output: ['OOOoOooO\n', 'OOOoOooOooooOoo\n'] Note: none
```python n=(int(input)) l=[1] s1=1 s2=1 s=0 while s<n: s=s1+s2 s1=s2 s2=s l.append(s) ch="" for i in range(1,n+1) if i in l ch='O' else ch='o' print(ch) ```
-1
552
B
Vanya and Books
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books.
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Print the number of digits needed to number all the books.
[ "13\n", "4\n" ]
[ "17\n", "4\n" ]
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
1,000
[ { "input": "13", "output": "17" }, { "input": "4", "output": "4" }, { "input": "100", "output": "192" }, { "input": "99", "output": "189" }, { "input": "1000000000", "output": "8888888899" }, { "input": "1000000", "output": "5888896" }, { "input": "999", "output": "2889" }, { "input": "55", "output": "101" }, { "input": "222222222", "output": "1888888896" }, { "input": "8", "output": "8" }, { "input": "13", "output": "17" }, { "input": "313", "output": "831" }, { "input": "1342", "output": "4261" }, { "input": "30140", "output": "139594" }, { "input": "290092", "output": "1629447" }, { "input": "2156660", "output": "13985516" }, { "input": "96482216", "output": "760746625" }, { "input": "943006819", "output": "8375950269" }, { "input": "1", "output": "1" }, { "input": "7", "output": "7" }, { "input": "35", "output": "61" }, { "input": "996", "output": "2880" }, { "input": "6120", "output": "23373" }, { "input": "30660", "output": "142194" }, { "input": "349463", "output": "1985673" }, { "input": "8171970", "output": "56092686" }, { "input": "36123011", "output": "277872985" }, { "input": "986747865", "output": "8769619683" }, { "input": "9", "output": "9" }, { "input": "10", "output": "11" }, { "input": "11", "output": "13" }, { "input": "101", "output": "195" }, { "input": "1000", "output": "2893" }, { "input": "1001", "output": "2897" }, { "input": "9999", "output": "38889" }, { "input": "10000", "output": "38894" }, { "input": "10001", "output": "38899" }, { "input": "99999", "output": "488889" }, { "input": "100000", "output": "488895" }, { "input": "100001", "output": "488901" }, { "input": "999999", "output": "5888889" }, { "input": "1000001", "output": "5888903" }, { "input": "9999999", "output": "68888889" }, { "input": "10000000", "output": "68888897" }, { "input": "10000001", "output": "68888905" }, { "input": "99999999", "output": "788888889" }, { "input": "100000000", "output": "788888898" }, { "input": "100000001", "output": "788888907" }, { "input": "999999999", "output": "8888888889" }, { "input": "95", "output": "181" }, { "input": "995", "output": "2877" }, { "input": "9995", "output": "38873" }, { "input": "99995", "output": "488869" }, { "input": "999999995", "output": "8888888853" }, { "input": "999999998", "output": "8888888880" } ]
1,508,703,683
2,147,483,647
Python 3
OK
TESTS
55
62
5,529,600
n=int(input()) l=len(str(n)) #l=l-1 #yo=l-1 #ro=(10**(l-1)-1) ro=int(((9*l-10)*(10**(l-1))+1)/9) #print(int(ro)) if l!=1: yo=n-int('9'*(l-1)) else: yo=n #print(yo) yoyo=yo*l ans=ro+yoyo print(ans)
Title: Vanya and Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. Output Specification: Print the number of digits needed to number all the books. Demo Input: ['13\n', '4\n'] Demo Output: ['17\n', '4\n'] Note: Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
```python n=int(input()) l=len(str(n)) #l=l-1 #yo=l-1 #ro=(10**(l-1)-1) ro=int(((9*l-10)*(10**(l-1))+1)/9) #print(int(ro)) if l!=1: yo=n-int('9'*(l-1)) else: yo=n #print(yo) yoyo=yo*l ans=ro+yoyo print(ans) ```
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,443,554,119
2,147,483,647
Python 3
OK
TESTS
36
421
20,787,200
count=0 x=input() num=[int(x) for x in input().split()] num.sort() if len(num)==1: print(num[0]) exit() else: for i in range(len(num)-2): count+=num[i]*(i+2) count+=(num[-1]+num[-2])*(len(num)) print(count)
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 count=0 x=input() num=[int(x) for x in input().split()] num.sort() if len(num)==1: print(num[0]) exit() else: for i in range(len(num)-2): count+=num[i]*(i+2) count+=(num[-1]+num[-2])*(len(num)) print(count) ```
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "output": "840" }, { "input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "output": "922" }, { "input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "output": "674" }, { "input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "output": "848" }, { "input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "output": "902" }, { "input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "output": "798" }, { "input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "output": "632" }, { "input": "1\n4", "output": "4" }, { "input": "2\n1 4", "output": "4" }, { "input": "3\n1 2 4", "output": "6" }, { "input": "2\n9 3", "output": "12" }, { "input": "2\n1000000000 1001", "output": "1000000000" }, { "input": "3\n1 8 4", "output": "12" }, { "input": "3\n7 4 4", "output": "8" }, { "input": "5\n2 3 4 5 3", "output": "14" }, { "input": "2\n4 5", "output": "4" }, { "input": "3\n2 4 5", "output": "6" }, { "input": "3\n2 2 3", "output": "4" }, { "input": "2\n2 3", "output": "2" }, { "input": "4\n2 3 7 7", "output": "16" }, { "input": "2\n999999999 2", "output": "2" }, { "input": "2\n2 5", "output": "2" }, { "input": "3\n5 3 1", "output": "8" }, { "input": "4\n3 2 5 7", "output": "14" } ]
1,658,571,375
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
108
7,065,600
n = int(input()) arr = map(int, input().split(" ")) res = sum = 0 for a in arr: sum += a if sum % 2 == 0: res = max(res, sum) print(res)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. Input Specification: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Specification: Print the maximum possible even sum that can be obtained if we use some of the given integers. Demo Input: ['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n'] Demo Output: ['6', '3999999996'] Note: In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
```python n = int(input()) arr = map(int, input().split(" ")) res = sum = 0 for a in arr: sum += a if sum % 2 == 0: res = max(res, sum) print(res) ```
0
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, { "input": "10 3 4 5", "output": "3" }, { "input": "100 23 15 50", "output": "2" }, { "input": "3119 3515 1021 7", "output": "11" }, { "input": "918 102 1327 1733", "output": "9" }, { "input": "3164 42 430 1309", "output": "15" }, { "input": "3043 317 1141 2438", "output": "7" }, { "input": "26 1 772 2683", "output": "26" }, { "input": "370 2 1 15", "output": "370" }, { "input": "734 12 6 2", "output": "367" }, { "input": "418 18 14 17", "output": "29" }, { "input": "18 16 28 9", "output": "2" }, { "input": "14 6 2 17", "output": "7" }, { "input": "29 27 18 2", "output": "2" }, { "input": "29 12 7 10", "output": "3" }, { "input": "27 23 4 3", "output": "9" }, { "input": "5 14 5 2", "output": "1" }, { "input": "5 17 26 5", "output": "1" }, { "input": "9 1 10 3", "output": "9" }, { "input": "2 19 15 1", "output": "2" }, { "input": "4 6 4 9", "output": "1" }, { "input": "10 6 2 9", "output": "5" }, { "input": "2 2 9 6", "output": "1" }, { "input": "6 2 4 1", "output": "6" }, { "input": "27 24 5 27", "output": "1" }, { "input": "2683 83 26 2709", "output": "101" }, { "input": "728 412 789 158", "output": "3" }, { "input": "3964 4 2916 176", "output": "991" }, { "input": "3399 2035 2 3334", "output": "683" }, { "input": "3455 244 3301 3", "output": "991" }, { "input": "595 2263 3625 1", "output": "595" }, { "input": "4000 1 1 1", "output": "4000" }, { "input": "3999 2 2 3999", "output": "1" }, { "input": "25 6 8 11", "output": "3" }, { "input": "4000 500 1000 2000", "output": "8" }, { "input": "53 10 11 23", "output": "5" }, { "input": "100 100 1 1", "output": "100" }, { "input": "17 3 4 10", "output": "5" }, { "input": "413 101 102 105", "output": "4" }, { "input": "490 4 49 50", "output": "111" }, { "input": "3999 2 3 3", "output": "1999" }, { "input": "8 3 8 4", "output": "2" }, { "input": "5 1 3 3", "output": "5" }, { "input": "100 3 17 22", "output": "27" }, { "input": "4000 2 3 4", "output": "2000" }, { "input": "4000 3 3 5", "output": "1332" }, { "input": "13 4 6 7", "output": "2" }, { "input": "4000 5 2 2", "output": "2000" }, { "input": "3999 2 2 3", "output": "1999" }, { "input": "4000 33 7 3333", "output": "564" }, { "input": "60 33 20 9", "output": "4" }, { "input": "100 9 11 99", "output": "10" }, { "input": "2009 6 8 9", "output": "334" } ]
1,675,003,924
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
x = input().split() target = int(x[0]) memo = {} for i in range(1,len(x)): remainder = target - int(x[i]) memo[remainder] = x[i] ans = 0 for i in range(1,len(x)): if int(x[i]) in memo: ans += 1 memo.pop(int(x[i])) print(ans)
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting. Input Specification: The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. Output Specification: Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. Demo Input: ['5 5 3 2\n', '7 5 5 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
```python x = input().split() target = int(x[0]) memo = {} for i in range(1,len(x)): remainder = target - int(x[i]) memo[remainder] = x[i] ans = 0 for i in range(1,len(x)): if int(x[i]) in memo: ans += 1 memo.pop(int(x[i])) print(ans) ```
0
859
C
Pie Rules
PROGRAMMING
1,500
[ "dp", "games" ]
null
null
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person. The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left. All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input will begin with an integer *N* (1<=≤<=*N*<=≤<=50), the number of slices of pie. Following this is a line with *N* integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
[ "3\n141 592 653\n", "5\n10 21 10 21 10\n" ]
[ "653 733\n", "31 41\n" ]
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
1,000
[ { "input": "3\n141 592 653", "output": "653 733" }, { "input": "5\n10 21 10 21 10", "output": "31 41" }, { "input": "1\n100000", "output": "0 100000" }, { "input": "50\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000", "output": "2500000 2500000" }, { "input": "2\n1 100000", "output": "1 100000" }, { "input": "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "output": "65535 65536" }, { "input": "15\n3026 3027 4599 4854 7086 29504 38709 40467 40663 58674 61008 70794 77517 85547 87320", "output": "306375 306420" }, { "input": "30\n2351 14876 66138 87327 29940 73204 19925 50198 13441 54751 1383 92120 90236 13525 3920 16669 80637 94428 54890 71321 77670 57080 82145 39778 69967 38722 46902 82127 1142 21792", "output": "724302 724303" }, { "input": "1\n59139", "output": "0 59139" }, { "input": "2\n9859 48096", "output": "9859 48096" }, { "input": "3\n25987 64237 88891", "output": "88891 90224" }, { "input": "4\n9411 13081 2149 19907", "output": "19907 24641" }, { "input": "5\n25539 29221 6895 82089 18673", "output": "80328 82089" }, { "input": "6\n76259 10770 87448 3054 67926 81667", "output": "158428 168696" }, { "input": "7\n92387 35422 24898 32532 92988 84636 99872", "output": "192724 270011" }, { "input": "8\n8515 51563 5451 94713 9537 30709 63343 41819", "output": "138409 167241" }, { "input": "9\n91939 407 10197 24191 58791 9486 68030 25807 11", "output": "102429 186430" }, { "input": "10\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754", "output": "252317 291210" }, { "input": "11\n46646 21171 78816 89449 99375 50934 15950 90299 18702 62232 12657", "output": "288850 297381" }, { "input": "12\n30070 37311 92074 18927 91732 29711 12126 41583 52857 99118 73097 33928", "output": "296580 315954" }, { "input": "13\n13494 86155 96820 72596 40986 99976 16813 25571 87013 3301 832 26376 83769", "output": "325890 327812" }, { "input": "14\n96918 67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518", "output": "414474 453667" }, { "input": "15\n13046 83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336", "output": "362168 392358" }, { "input": "16\n29174 32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082", "output": "370791 371188" }, { "input": "17\n79894 24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688", "output": "492038 551105" }, { "input": "18\n96022 73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967", "output": "436157 470692" }, { "input": "19\n79446 55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759", "output": "538648 614005" }, { "input": "20\n5440 88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499", "output": "506639 558873" }, { "input": "21\n21569 37548 74739 25809 65063 37631 71913 89138 47543 65542 10956 14045 78880 70111 73357 27810 70326 40523 899 6547 87440", "output": "506467 510922" }, { "input": "22\n72289 86393 79484 55287 14317 83704 11192 73126 81699 2429 4100 41085 87482 72352 10976 75727 42240 79569 31621 3492 51189 25936", "output": "513496 572193" }, { "input": "23\n88417 11045 92742 84765 6675 86673 40072 57114 15854 6611 40347 76636 87572 66082 38195 56348 89962 59831 29640 43541 14937 73713 52755", "output": "602650 616877" }, { "input": "24\n71841 27185 73295 46946 55928 65450 12055 73806 82714 78089 787 36380 87663 68323 75814 4265 94581 31581 51850 40486 11390 21491 27560 22678", "output": "560664 601494" }, { "input": "25\n87969 76030 78041 616 13694 11522 84038 25090 16869 14975 61226 96124 20457 62052 70329 76374 42303 11844 15276 37430 99330 77781 35069 64358 45168", "output": "586407 637558" }, { "input": "26\n71393 24874 91299 30093 62947 14491 80214 41782 51025 19158 21666 23163 20547 64293 40653 24291 46922 92106 13294 77479 63079 25559 42579 62933 24433 39507", "output": "569885 599895" }, { "input": "27\n54817 73719 96044 92275 12201 60564 84901 25770 17884 90636 14810 82907 20637 58023 10976 72208 94644 63856 11312 74424 26828 40632 58600 37316 38290 82420 48297", "output": "716531 728460" }, { "input": "28\n70945 22563 76598 21753 4558 39341 48372 77054 52039 27522 75249 18459 96536 60264 5491 20125 42367 44118 42034 38665 47472 88410 66109 78995 52147 68436 9814 71112", "output": "669482 697066" }, { "input": "29\n54369 14511 14048 83934 53812 75014 20356 17938 86195 31704 68393 78202 96626 86697 75814 746 46985 15868 40052 11417 11221 44700 40915 53378 98708 78644 4035 20164 37165", "output": "678299 683312" }, { "input": "30\n4555 13594 57403 75796 14203 12847 66292 60885 9525 40478 57327 69970 15297 37483 39540 31102 14855 412 84174 57684 65591 19837 80431 18385 3107 87740 15433 24854 73472 88205", "output": "620095 620382" }, { "input": "31\n20683 29734 37957 37978 63456 58920 70980 44873 76385 44661 17767 97009 15387 63916 77159 79019 86770 4866 14897 63141 86236 67614 87940 60064 16964 97948 9654 49714 30888 88075 63792", "output": "825663 838784" }, { "input": "32\n71403 78578 75406 67455 12710 37697 67155 28861 10540 48843 10911 56753 15477 33453 4378 26936 34492 19720 12915 27382 49984 91200 95449 34448 63525 83964 3875 98767 77905 63753 83018 58084", "output": "770578 774459" }, { "input": "33\n87531 27423 55960 53829 37771 40665 39138 12849 77399 53025 71350 83793 48271 59887 41997 74854 14919 24175 43637 24327 13733 38978 2959 319 10086 26876 65393 56332 68025 63623 93732 68354 83938", "output": "741185 823963" }, { "input": "34\n70955 19371 60706 50603 54321 86738 11122 29541 11555 57207 31790 19344 24170 29424 36512 22771 86833 4437 41655 64376 34378 19459 86276 74702 23943 69789 59614 48489 49634 63494 12958 11328 69333 1736", "output": "693927 744637" }, { "input": "35\n54379 920 41259 12784 3574 98219 40001 80825 45710 61390 24933 79088 24260 23153 6835 94880 67260 76187 39673 28616 98126 10341 26489 49085 37800 55805 86539 97542 39754 30660 32184 64703 11625 77872 63584", "output": "823487 862568" }, { "input": "36\n37803 17060 78709 42262 28636 68484 79280 97517 12570 98276 52669 6128 57054 58098 68646 75501 39174 56449 3099 1369 94579 58119 1295 90764 51657 66013 48056 55107 54066 30530 75602 74973 21212 21304 22589 4895", "output": "872694 876851" }, { "input": "37\n53932 65904 91967 4443 77890 47261 8160 81505 46725 69754 21621 65871 24440 51828 71673 23418 86896 4008 1117 65610 82519 5897 8804 65148 98218 76221 42277 79968 68379 30401 62125 61052 96207 64737 24698 99495 70720", "output": "989044 1011845" }, { "input": "38\n70060 14749 72520 58113 2951 26037 80143 32789 80881 73936 82060 92911 24531 78261 9292 71335 91515 8462 31839 62555 46268 29482 92121 31019 12075 94942 36498 96317 58499 30271 81351 71322 81602 8169 26807 69903 38154 20539", "output": "977736 1012543" }, { "input": "39\n20780 30889 9970 87591 19501 96302 76318 49481 47740 10823 42500 61167 57325 47798 36511 19252 39237 23316 29857 2603 10016 9964 99630 5402 82828 5150 98015 53882 72811 97437 57473 57400 91189 84305 85811 64503 40179 50614 52044", "output": "954593 973021" }, { "input": "40\n3670 5779 20621 87964 12595 34136 98063 92429 38366 43789 88330 52934 19100 22776 43342 82312 74404 64756 73980 14278 21283 85101 63339 70409 63034 14245 33606 58571 84927 14931 25355 15452 46072 4671 5838 69121 18243 87783 29748 84047", "output": "909877 959523" }, { "input": "41\n87094 21920 58071 41634 29145 45616 94239 76417 5226 47971 48770 79974 19190 25017 37857 30229 11726 12314 71998 54327 85032 8687 46656 12088 9595 24454 27827 7624 66535 14801 44581 25723 55659 48103 75242 39529 52973 17858 16985 41454 44182", "output": "799467 864856" }, { "input": "42\n70518 70764 38625 3816 78399 48585 66222 60405 72085 52153 85018 39717 51984 51451 8180 78146 59448 16768 2720 51272 48780 56464 21461 86471 23452 10470 22048 65189 56655 90480 31103 11801 73758 91536 10055 34129 20407 47933 4223 98861 84475 52291", "output": "1012190 1036128" }, { "input": "43\n86646 19609 43370 33293 3460 94658 95101 44393 6241 56335 78161 66757 52074 53692 2695 58767 31363 64326 738 15513 69425 4242 28971 60855 37309 53382 16269 57346 70968 90350 74522 22072 83345 67672 69060 4537 55137 78008 91461 32075 33280 70405 71607", "output": "1039942 1109548" }, { "input": "44\n70070 68453 23924 95475 52714 73435 34380 61085 40396 60518 38601 26501 52165 47421 73018 6684 79085 68781 31460 88265 33173 52020 44992 2534 8062 96295 77786 39103 85280 24812 93748 75446 92932 11105 71169 66433 89866 75379 11402 22186 73572 31624 70092 10734", "output": "1141992 1210184" }, { "input": "45\n53494 93105 37182 24953 1967 43700 39068 12369 7256 64700 31744 62052 84959 49662 34829 78793 51000 16339 29478 52506 96922 75606 52501 1109 21919 6503 72007 63964 75400 24682 45678 18420 67928 87241 73278 69545 24596 29646 65936 55401 89673 49738 35873 45189 3622", "output": "1052557 1068976" }, { "input": "46\n36918 9246 74631 78622 94325 22476 35243 96357 41411 68882 92184 21796 28153 43392 37856 26710 64130 20793 60200 16747 84862 23383 60010 42788 68480 92519 66229 56121 57009 24553 89096 4499 53323 30673 75386 31442 92030 59721 53173 45511 29966 67853 77462 12347 61811 81517", "output": "1199490 1212346" }, { "input": "47\n53046 58090 55185 8100 43578 1253 7226 13049 75567 73065 19920 48836 28243 45633 75475 74628 11853 68351 90922 89500 81315 71161 34816 49875 82337 2727 27746 37878 79833 24423 75618 82065 95614 82618 34391 1850 94056 57092 73115 70214 46067 29071 75947 46802 95807 42600 11211", "output": "1214201 1233568" }, { "input": "48\n69174 6934 59931 70281 68640 47326 3402 64333 42426 77247 13063 8579 61038 39362 2694 22545 83767 15909 88940 86445 45063 27451 18133 91555 28898 45640 21967 62738 61441 24293 19036 68144 5201 26050 69204 29154 85681 19871 60352 36133 86359 47186 74432 5448 53996 27876 58022 80559", "output": "1096672 1115247" }, { "input": "49\n19894 55779 73188 99759 17893 50295 8089 81025 76582 81429 73503 35619 61128 41603 40313 3166 31490 87660 19662 59197 8812 75229 25642 65938 42755 31656 16188 87599 51562 91460 38262 11118 90596 69482 71313 66858 87707 17242 14886 93539 35164 32596 83317 72606 12185 21664 80642 72099 7525", "output": "1233007 1259909" }, { "input": "50\n70081 97965 40736 24325 2476 20832 54026 23972 91400 47099 95141 27386 79799 49285 4039 818 23552 72203 55273 38168 52783 50365 89351 30945 47154 8047 27586 49184 20573 8953 38849 36466 45479 89848 82827 71475 74283 87115 92590 28903 97800 74550 74140 82514 10849 6786 67881 63456 53022 25051", "output": "1251581 1255820" }, { "input": "4\n10 3 2 1", "output": "4 12" }, { "input": "6\n5245 1414 21632 12159 31783 7412", "output": "38442 41203" }, { "input": "46\n1666 17339 9205 20040 30266 12751 11329 7951 9000 14465 11771 7600 19480 15993 19453 7470 1361 7922 27747 17347 4727 11280 403 16338 6064 11124 25723 18717 26118 271 9242 16952 26381 31795 28226 3646 27589 31472 30108 28354 25281 22429 30956 32264 14729 21685", "output": "379808 392222" }, { "input": "3\n100 90 80", "output": "90 180" }, { "input": "5\n10 9 8 7 6", "output": "16 24" }, { "input": "4\n100 40 50 10", "output": "50 150" }, { "input": "6\n5 4 3 2 1 1", "output": "7 9" }, { "input": "33\n30274 12228 26670 31244 5457 2643 27275 4380 30954 23407 8387 6669 25229 31591 27518 30261 25670 20962 31316 8992 8324 26216 10812 28467 15401 23077 10311 24975 14046 12010 11406 22841 7593", "output": "299163 327443" }, { "input": "3\n4 2 1", "output": "2 5" }, { "input": "3\n10 5 5", "output": "5 15" }, { "input": "6\n6 5 4 3 2 1", "output": "9 12" }, { "input": "4\n5 2 7 3", "output": "7 10" } ]
1,507,226,202
2,147,483,647
PyPy 3
OK
TESTS
70
108
307,200
n = int(input()) d = [[0 for i in range(2)] for i in range(n)] w = [int(z) for z in input().split()] w.reverse() d[0][1] = w[0] d[0][0] = 0 summ = w[0] for i in range(1,n): summ += w[i] d[i][1] = max(d[i - 1][1], d[i - 1][0] + w[i]) d[i][0] = summ - d[i][1] print(min(d[n - 1][1],d[n - 1][0]), summ - min(d[n - 1][1],d[n - 1][0]))
Title: Pie Rules Time Limit: None seconds Memory Limit: None megabytes Problem Description: You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person. The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left. All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive? Input Specification: Input will begin with an integer *N* (1<=≤<=*N*<=≤<=50), the number of slices of pie. Following this is a line with *N* integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out. Output Specification: Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally. Demo Input: ['3\n141 592 653\n', '5\n10 21 10 21 10\n'] Demo Output: ['653 733\n', '31 41\n'] Note: In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
```python n = int(input()) d = [[0 for i in range(2)] for i in range(n)] w = [int(z) for z in input().split()] w.reverse() d[0][1] = w[0] d[0][0] = 0 summ = w[0] for i in range(1,n): summ += w[i] d[i][1] = max(d[i - 1][1], d[i - 1][0] + w[i]) d[i][0] = summ - d[i][1] print(min(d[n - 1][1],d[n - 1][0]), summ - min(d[n - 1][1],d[n - 1][0])) ```
3
626
C
Block Towers
PROGRAMMING
1,600
[ "brute force", "greedy", "math", "number theory" ]
null
null
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Print a single integer, denoting the minimum possible height of the tallest tower.
[ "1 3\n", "3 2\n", "5 0\n" ]
[ "9\n", "8\n", "10\n" ]
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
1,000
[ { "input": "1 3", "output": "9" }, { "input": "3 2", "output": "8" }, { "input": "5 0", "output": "10" }, { "input": "4 2", "output": "9" }, { "input": "0 1000000", "output": "3000000" }, { "input": "1000000 1", "output": "2000000" }, { "input": "1083 724", "output": "2710" }, { "input": "1184 868", "output": "3078" }, { "input": "1285 877", "output": "3243" }, { "input": "820189 548173", "output": "2052543" }, { "input": "968867 651952", "output": "2431228" }, { "input": "817544 553980", "output": "2057286" }, { "input": "813242 543613", "output": "2035282" }, { "input": "961920 647392", "output": "2413968" }, { "input": "825496 807050", "output": "2448819" }, { "input": "974174 827926", "output": "2703150" }, { "input": "969872 899794", "output": "2804499" }, { "input": "818549 720669", "output": "2308827" }, { "input": "967227 894524", "output": "2792626" }, { "input": "185253 152723", "output": "506964" }, { "input": "195173 150801", "output": "518961" }, { "input": "129439 98443", "output": "341823" }, { "input": "163706 157895", "output": "482402" }, { "input": "197973 140806", "output": "508168" }, { "input": "1000000 1000000", "output": "3000000" }, { "input": "1000000 999999", "output": "2999998" }, { "input": "999999 1000000", "output": "3000000" }, { "input": "500000 500100", "output": "1500300" }, { "input": "500000 166000", "output": "1000000" }, { "input": "500000 499000", "output": "1498500" }, { "input": "500000 167000", "output": "1000500" }, { "input": "1 1000000", "output": "3000000" }, { "input": "2 999123", "output": "2997369" }, { "input": "10 988723", "output": "2966169" }, { "input": "234 298374", "output": "895122" }, { "input": "2365 981235", "output": "2943705" }, { "input": "12345 981732", "output": "2945196" }, { "input": "108752 129872", "output": "389616" }, { "input": "984327 24352", "output": "1968654" }, { "input": "928375 1253", "output": "1856750" }, { "input": "918273 219", "output": "1836546" }, { "input": "987521 53", "output": "1975042" }, { "input": "123456 1", "output": "246912" }, { "input": "789123 0", "output": "1578246" }, { "input": "143568 628524", "output": "1885572" }, { "input": "175983 870607", "output": "2611821" }, { "input": "6 4", "output": "15" }, { "input": "6 3", "output": "14" }, { "input": "7 3", "output": "15" }, { "input": "5 4", "output": "14" }, { "input": "5 3", "output": "12" }, { "input": "8 5", "output": "20" }, { "input": "1 0", "output": "2" }, { "input": "19170 15725", "output": "52342" }, { "input": "3000 2000", "output": "7500" }, { "input": "7 4", "output": "16" }, { "input": "50 30", "output": "120" }, { "input": "300 200", "output": "750" }, { "input": "9 4", "output": "20" }, { "input": "4 3", "output": "10" }, { "input": "1 1", "output": "3" }, { "input": "8 6", "output": "21" }, { "input": "10 6", "output": "24" }, { "input": "65 56", "output": "182" }, { "input": "13 10", "output": "34" }, { "input": "14 42", "output": "126" }, { "input": "651 420", "output": "1606" }, { "input": "8 9", "output": "27" }, { "input": "15 10", "output": "38" }, { "input": "999999 888888", "output": "2833330" }, { "input": "192056 131545", "output": "485402" }, { "input": "32 16", "output": "72" }, { "input": "18 12", "output": "45" }, { "input": "1000000 666667", "output": "2500000" }, { "input": "0 1", "output": "3" }, { "input": "9 5", "output": "21" }, { "input": "1515 1415", "output": "4395" }, { "input": "300000 200000", "output": "750000" } ]
1,507,581,876
2,147,483,647
Python 3
OK
TESTS
78
62
0
n, m = map(int, input().split()) k = n + m a = [6, 3][m % 2] + 6 * ((m - 1) // 2) b = [6, 2, 4][n % 3] + 6 * ((n - 1) // 3) c = [6, 2, 3, 4][k % 4] + 6 * ((k - 1) // 4) print(a if n < m else b if n > 3 * m else c)
Title: Block Towers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers. Input Specification: The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. Output Specification: Print a single integer, denoting the minimum possible height of the tallest tower. Demo Input: ['1 3\n', '3 2\n', '5 0\n'] Demo Output: ['9\n', '8\n', '10\n'] Note: In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
```python n, m = map(int, input().split()) k = n + m a = [6, 3][m % 2] + 6 * ((m - 1) // 2) b = [6, 2, 4][n % 3] + 6 * ((n - 1) // 3) c = [6, 2, 3, 4][k % 4] + 6 * ((k - 1) // 4) print(a if n < m else b if n > 3 * m else c) ```
3
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,644,544,276
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
nnumbers = list(map(int,input().split())) ccount=0 a=[] k = nnumbers[-1] for i in range(0, nnumbers[0]): n=int(input()) a.append(n) for i in a: i = str(i) if int(max(i)) <= k and str(0) in i: ccount+=1 print(ccount)
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 nnumbers = list(map(int,input().split())) ccount=0 a=[] k = nnumbers[-1] for i in range(0, nnumbers[0]): n=int(input()) a.append(n) for i in a: i = str(i) if int(max(i)) <= k and str(0) in i: ccount+=1 print(ccount) ```
0
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above.
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { "input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543", "output": "NO" }, { "input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869", "output": "YES" }, { "input": "3\n408 410 409", "output": "YES" }, { "input": "3\n903 902 904", "output": "YES" }, { "input": "3\n399 400 398", "output": "YES" }, { "input": "3\n450 448 449", "output": "YES" }, { "input": "3\n390 389 388", "output": "YES" }, { "input": "3\n438 439 440", "output": "YES" }, { "input": "11\n488 688 490 94 564 615 641 170 489 517 669", "output": "YES" }, { "input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954", "output": "YES" }, { "input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318", "output": "YES" }, { "input": "6\n10 79 306 334 304 305", "output": "YES" }, { "input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365", "output": "YES" }, { "input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73", "output": "YES" }, { "input": "11\n325 325 324 324 324 325 325 324 324 324 324", "output": "NO" }, { "input": "7\n517 517 518 517 518 518 518", "output": "NO" }, { "input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710", "output": "NO" }, { "input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29", "output": "NO" }, { "input": "7\n880 880 514 536 881 881 879", "output": "YES" }, { "input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375", "output": "YES" }, { "input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404", "output": "YES" }, { "input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987", "output": "YES" }, { "input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116", "output": "NO" }, { "input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995", "output": "NO" }, { "input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22", "output": "YES" }, { "input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952", "output": "YES" }, { "input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "3\n500 999 1000", "output": "NO" }, { "input": "10\n101 102 104 105 107 109 110 112 113 115", "output": "NO" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "3\n1000 999 998", "output": "YES" }, { "input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456", "output": "NO" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3", "output": "YES" }, { "input": "3\n999 999 1000", "output": "NO" }, { "input": "9\n2 4 5 13 25 100 200 300 400", "output": "NO" }, { "input": "9\n1 1 1 2 2 2 3 3 3", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n998 999 1000", "output": "YES" }, { "input": "12\n1 1 1 1 1 1 1 1 1 2 2 4", "output": "NO" }, { "input": "4\n4 3 4 5", "output": "YES" }, { "input": "6\n1 1 1 2 2 2", "output": "NO" }, { "input": "3\n2 3 2", "output": "NO" }, { "input": "5\n10 5 6 3 2", "output": "NO" }, { "input": "3\n1 2 1", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "4\n998 999 1000 1000", "output": "YES" }, { "input": "5\n2 3 9 9 4", "output": "YES" }, { "input": "4\n1 2 4 4", "output": "NO" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "7\n1 2 2 2 4 5 6", "output": "YES" }, { "input": "5\n1 3 10 3 10", "output": "NO" }, { "input": "3\n1 2 2", "output": "NO" }, { "input": "4\n1000 1000 999 998", "output": "YES" }, { "input": "3\n5 3 7", "output": "NO" }, { "input": "6\n1 1 2 2 3 3", "output": "YES" }, { "input": "9\n6 6 6 5 5 5 4 4 4", "output": "YES" }, { "input": "7\n5 6 6 6 7 7 7", "output": "YES" }, { "input": "5\n2 3 3 3 4", "output": "YES" }, { "input": "5\n2 1 2 1 3", "output": "YES" }, { "input": "3\n1 2 7", "output": "NO" }, { "input": "3\n1000 1000 1000", "output": "NO" }, { "input": "5\n1 100 2 100 3", "output": "YES" }, { "input": "5\n5 4 6 5 5", "output": "YES" }, { "input": "12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "YES" }, { "input": "5\n9 9 1 2 3", "output": "YES" }, { "input": "6\n1 2 3 1 2 3", "output": "YES" }, { "input": "7\n1 1 1 1 2 3 3", "output": "YES" }, { "input": "3\n13 13 13", "output": "NO" }, { "input": "3\n42 42 42", "output": "NO" }, { "input": "8\n1 1 1 1 2 2 2 2", "output": "NO" }, { "input": "6\n1 1 1 1 2 3", "output": "YES" }, { "input": "6\n1 1 2 2 6 6", "output": "NO" }, { "input": "6\n1 2 5 5 5 5", "output": "NO" }, { "input": "9\n1 2 3 1 2 3 1 2 3", "output": "YES" }, { "input": "4\n1 2 1 100", "output": "NO" }, { "input": "5\n1 1 2 2 3", "output": "YES" } ]
1,683,003,879
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) a = list(map(int, input().split())) a.sort() kol = 0 for i in range(n-3): if a[i] != a[i+1] and a[i+1] != a[i+2]: if abs(a[i] - a[i+1]) <=2 and abs(a[i+1] - a[i+2]) <= 2: kol += 1 if kol == 1: print('YES') exit() print('NO') exit()
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above. Input Specification: The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. Output Specification: Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). Demo Input: ['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
```python n = int(input()) a = list(map(int, input().split())) a.sort() kol = 0 for i in range(n-3): if a[i] != a[i+1] and a[i+1] != a[i+2]: if abs(a[i] - a[i+1]) <=2 and abs(a[i+1] - a[i+2]) <= 2: kol += 1 if kol == 1: print('YES') exit() print('NO') exit() ```
0
801
A
Vicious Keyboard
PROGRAMMING
1,100
[ "brute force" ]
null
null
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
[ "VK\n", "VV\n", "V\n", "VKKKKKKKKKVVVVVVVVVK\n", "KVKV\n" ]
[ "1\n", "1\n", "0\n", "3\n", "1\n" ]
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear. For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring. For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
500
[ { "input": "VK", "output": "1" }, { "input": "VV", "output": "1" }, { "input": "V", "output": "0" }, { "input": "VKKKKKKKKKVVVVVVVVVK", "output": "3" }, { "input": "KVKV", "output": "1" }, { "input": "VKKVVVKVKVK", "output": "5" }, { "input": "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV", "output": "14" }, { "input": "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK", "output": "32" }, { "input": "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK", "output": "32" }, { "input": "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK", "output": "21" }, { "input": "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV", "output": "25" }, { "input": "KKVVKVVKVVKKVVKKVKVVKKV", "output": "7" }, { "input": "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV", "output": "24" }, { "input": "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV", "output": "35" }, { "input": "VKVVVKKKVKVVKVKVKVKVKVV", "output": "9" }, { "input": "KKKKVKKVKVKVKKKVVVVKK", "output": "6" }, { "input": "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK", "output": "9" }, { "input": "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK", "output": "22" }, { "input": "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK", "output": "25" }, { "input": "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK", "output": "29" }, { "input": "KKVKVVVKKVV", "output": "3" }, { "input": "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK", "output": "16" }, { "input": "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV", "output": "13" }, { "input": "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV", "output": "26" }, { "input": "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV", "output": "26" }, { "input": "K", "output": "0" }, { "input": "VKVK", "output": "2" }, { "input": "VKVV", "output": "2" }, { "input": "KV", "output": "0" }, { "input": "KK", "output": "1" }, { "input": "KKVK", "output": "2" }, { "input": "KKKK", "output": "1" }, { "input": "KKV", "output": "1" }, { "input": "KKVKVK", "output": "3" }, { "input": "VKKVK", "output": "2" }, { "input": "VKKK", "output": "2" }, { "input": "KKK", "output": "1" }, { "input": "KVV", "output": "1" }, { "input": "KKVKV", "output": "2" }, { "input": "VVK", "output": "1" }, { "input": "VVVKVKVKVKVKVKVK", "output": "8" }, { "input": "KVVVK", "output": "2" }, { "input": "VVVKK", "output": "2" }, { "input": "KKVV", "output": "1" }, { "input": "KKKKKKK", "output": "1" }, { "input": "VKKKVK", "output": "3" }, { "input": "KKVVV", "output": "1" }, { "input": "VVVVVV", "output": "1" }, { "input": "KKKV", "output": "1" }, { "input": "VVKVV", "output": "2" }, { "input": "VKVKKK", "output": "3" }, { "input": "VKKV", "output": "1" }, { "input": "VKKVV", "output": "2" }, { "input": "VVKKVV", "output": "2" }, { "input": "KKVVKKV", "output": "2" }, { "input": "KKKKK", "output": "1" }, { "input": "VKVVKKVKKVVKVKKVKKKVKKVKVKK", "output": "10" }, { "input": "VKVKVV", "output": "3" }, { "input": "VKVVKVV", "output": "3" }, { "input": "VVV", "output": "1" }, { "input": "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV", "output": "1" }, { "input": "VVKKKKKKVKK", "output": "3" }, { "input": "KVKVKVV", "output": "3" } ]
1,493,657,254
274
Python 3
WRONG_ANSWER
TESTS
1
46
5,529,600
s = input() V = "V" K = "K" res = 0 flag = False for i, c in enumerate(list(s)): if i == 0: continue if s[i] == K and s[i-1] == V: res += 1 if i == len(s)-1: continue if s[i] == s[i-1] == s[i+1]: flag = True print(res + (1 if flag else 0))
Title: Vicious Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string. Input Specification: The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. Output Specification: Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. Demo Input: ['VK\n', 'VV\n', 'V\n', 'VKKKKKKKKKVVVVVVVVVK\n', 'KVKV\n'] Demo Output: ['1\n', '1\n', '0\n', '3\n', '1\n'] Note: For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear. For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring. For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
```python s = input() V = "V" K = "K" res = 0 flag = False for i, c in enumerate(list(s)): if i == 0: continue if s[i] == K and s[i-1] == V: res += 1 if i == len(s)-1: continue if s[i] == s[i-1] == s[i+1]: flag = True print(res + (1 if flag else 0)) ```
0
757
C
Felicity is Coming!
PROGRAMMING
1,900
[ "data structures", "hashing", "sortings", "strings" ]
null
null
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has *n* gyms. The *i*-th gym has *g**i* Pokemon in it. There are *m* distinct Pokemon types in the Himalayan region numbered from 1 to *m*. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving. Formally, an evolution plan is a permutation *f* of {1,<=2,<=...,<=*m*}, such that *f*(*x*)<==<=*y* means that a Pokemon of type *x* evolves into a Pokemon of type *y*. The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol. Two evolution plans *f*1 and *f*2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an *i* such that *f*1(*i*)<=≠<=*f*2(*i*). Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109<=+<=7.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=106) — the number of gyms and the number of Pokemon types. The next *n* lines contain the description of Pokemons in the gyms. The *i*-th of these lines begins with the integer *g**i* (1<=≤<=*g**i*<=≤<=105) — the number of Pokemon in the *i*-th gym. After that *g**i* integers follow, denoting types of the Pokemons in the *i*-th gym. Each of these integers is between 1 and *m*. The total number of Pokemons (the sum of all *g**i*) does not exceed 5·105.
Output the number of valid evolution plans modulo 109<=+<=7.
[ "2 3\n2 1 2\n2 2 3\n", "1 3\n3 1 2 3\n", "2 4\n2 1 2\n3 2 3 4\n", "2 2\n3 2 2 1\n2 1 2\n", "3 7\n2 1 2\n2 3 4\n3 5 6 7\n" ]
[ "1\n", "6\n", "2\n", "1\n", "24\n" ]
In the first case, the only possible evolution plan is: In the second case, any permutation of (1,  2,  3) is valid. In the third case, there are two possible plans: In the fourth case, the only possible evolution plan is:
1,500
[ { "input": "2 3\n2 1 2\n2 2 3", "output": "1" }, { "input": "1 3\n3 1 2 3", "output": "6" }, { "input": "2 4\n2 1 2\n3 2 3 4", "output": "2" }, { "input": "2 2\n3 2 2 1\n2 1 2", "output": "1" }, { "input": "3 7\n2 1 2\n2 3 4\n3 5 6 7", "output": "24" }, { "input": "10 100\n16 25 7 48 43 16 23 66 3 17 31 64 27 7 17 11 60\n62 76 82 99 77 19 26 66 46 9 54 77 8 34 76 70 48 53 35 69 29 84 22 16 53 36 27 24 81 2 86 67 45 22 54 96 37 8 3 22 9 30 63 61 86 19 16 47 3 72 39 36 1 50 1 18 7 44 52 66 90 3 63\n3 22 61 39\n9 28 69 91 62 98 23 45 9 10\n2 42 20\n3 90 46 55\n2 71 9\n1 7\n1 44\n1 94", "output": "732842622" }, { "input": "10 100\n26 69 60 30 8 89 7 54 66 100 75 4 17 48 40 20 78 56 94 23 48 55 40 9 23 55 30\n3 94 78 64\n50 57 81 62 43 95 4 22 29 9 67 17 82 13 69 13 30 85 3 44 5 85 70 4 50 9 30 85 67 64 7 59 98 78 68 61 63 35 35 94 87 37 18 12 83 26 77 48 67 72 82\n7 59 52 92 41 37 11 17\n1 65\n2 75 82\n4 28 66 33 70\n1 81\n2 4 31\n1 12", "output": "510562296" }, { "input": "10 100\n53 9 10 7 62 66 82 38 22 82 14 48 7 77 51 37 5 10 12 68 88 36 49 80 80 71 48 72 6 49 87 21 48 17 75 43 25 75 55 36 10 82 2 28 14 53 25 66 7 70 58 53 74 86\n32 84 95 55 32 79 75 12 94 80 13 29 49 87 26 69 51 73 52 30 87 17 75 60 1 82 15 34 26 83 95 60 13\n8 61 39 91 78 19 32 91 26\n1 22\n1 87\n1 55\n1 87\n1 39\n1 70\n1 40", "output": "51603121" }, { "input": "10 100\n46 62 64 81 19 35 65 30 81 64 54 95 98 18 78 54 19 68 34 16 37 22 55 63 41 87 65 33 22 15 5 99 35 49 79 47 54 50 97 54 3 100 86 91 3 24 36\n36 25 29 71 1 64 18 92 22 86 76 91 87 79 29 33 61 36 87 22 10 25 7 96 56 67 38 66 43 35 55 54 90 65 83 56 11\n4 36 73 34 11\n2 28 94\n2 97 100\n5 52 69 13 11 78\n1 78\n2 71 8\n1 33\n1 11", "output": "166939681" }, { "input": "10 100\n73 10 13 55 73 7 41 18 37 47 97 43 96 52 97 75 42 23 52 61 89 100 64 43 98 95 86 86 39 85 31 74 30 82 84 51 84 21 35 61 3 15 71 45 99 12 48 54 39 96 85 57 45 35 92 57 65 97 42 91 86 47 64 35 67 52 11 34 24 41 45 42 87 50\n9 77 91 42 99 98 20 43 82 35\n10 96 48 77 64 81 66 3 38 58 9\n1 61\n2 47 35\n1 7\n1 61\n1 70\n1 88\n1 83", "output": "8656282" }, { "input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1" }, { "input": "100 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2", "output": "1" }, { "input": "2 1000000\n1 1\n1 2", "output": "44455173" }, { "input": "5 262143\n1 1\n1 2\n1 3\n1 4\n1 5", "output": "943283753" }, { "input": "65 3\n1 1\n1 1\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n2 1 2\n1 1\n1 1\n1 1\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n1 1\n2 1 2", "output": "1" }, { "input": "1 1000000\n1 1", "output": "128233642" }, { "input": "20 3\n4 1 3 3 3\n6 1 3 3 3 3 3\n1 1\n2 1 3\n2 1 2\n1 1\n8 1 2 2 2 2 2 2 2\n3 1 3 3\n3 1 3 3\n5 1 2 2 2 2\n10 1 3 3 3 3 3 3 3 3 3\n15 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n10 1 2 2 2 2 2 2 2 2 2\n3 1 2 2\n1 1\n1 1\n7 1 3 3 3 3 3 3\n1 1\n1 1\n1 1", "output": "1" }, { "input": "20 3\n1 1\n5 1 2 2 2 2\n6 1 3 3 3 3 3\n2 1 2\n3 1 3 3\n3 1 3 3\n4 1 3 3 3\n2 1 3\n3 1 3 3\n5 1 2 2 2 2\n3 1 3 3\n7 1 2 2 2 2 2 2\n3 1 2 2\n6 1 3 3 3 3 3\n3 1 3 3\n2 1 2\n3 1 3 3\n2 1 2\n1 1\n1 1", "output": "1" }, { "input": "65 3\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n2 1 2", "output": "1" }, { "input": "20 3\n2 1 2\n8 1 3 3 3 3 3 3 3\n4 1 3 3 3\n2 1 2\n3 1 2 2\n9 1 3 3 3 3 3 3 3 3\n2 1 2\n3 1 2 2\n2 1 2\n3 1 3 3\n9 1 3 3 3 3 3 3 3 3\n2 1 2\n15 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n2 1 3\n4 1 3 3 3\n2 1 2\n1 1\n1 1\n1 1\n1 1", "output": "1" }, { "input": "20 3\n2 1 3\n3 1 2 2\n5 1 3 3 3 3\n3 1 2 2\n1 1\n5 1 3 3 3 3\n4 1 3 3 3\n5 1 3 3 3 3\n4 1 3 3 3\n3 1 2 2\n2 1 3\n5 1 3 3 3 3\n5 1 2 2 2 2\n6 1 2 2 2 2 2\n3 1 2 2\n5 1 3 3 3 3\n5 1 2 2 2 2\n3 1 3 3\n4 1 2 2 2\n2 1 2", "output": "1" }, { "input": "3 3\n6 1 1 1 1 1 1\n6 2 2 2 2 2 2\n2 1 1", "output": "1" } ]
1,484,983,192
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
from array import array from collections import Counter n, m = [int(x) for x in input().split()] inv = array('Q', (0 for t in range(m))) for i in range(n): tcs = Counter([int(x) for x in input().split()][1:]) for t, c in tcs.iteritems(): inv[t-1] = 0xffffffffffffffff & (inv[t-1] + 14524308274859922871 * i + 15722343008486712703 * c) r = 1 mod = 10**9+7 for c in Counter(inv).itervalues(): for i in xrange(2, c+1): r = r * i % mod print r
Title: Felicity is Coming! Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has *n* gyms. The *i*-th gym has *g**i* Pokemon in it. There are *m* distinct Pokemon types in the Himalayan region numbered from 1 to *m*. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving. Formally, an evolution plan is a permutation *f* of {1,<=2,<=...,<=*m*}, such that *f*(*x*)<==<=*y* means that a Pokemon of type *x* evolves into a Pokemon of type *y*. The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol. Two evolution plans *f*1 and *f*2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an *i* such that *f*1(*i*)<=≠<=*f*2(*i*). Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109<=+<=7. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=106) — the number of gyms and the number of Pokemon types. The next *n* lines contain the description of Pokemons in the gyms. The *i*-th of these lines begins with the integer *g**i* (1<=≤<=*g**i*<=≤<=105) — the number of Pokemon in the *i*-th gym. After that *g**i* integers follow, denoting types of the Pokemons in the *i*-th gym. Each of these integers is between 1 and *m*. The total number of Pokemons (the sum of all *g**i*) does not exceed 5·105. Output Specification: Output the number of valid evolution plans modulo 109<=+<=7. Demo Input: ['2 3\n2 1 2\n2 2 3\n', '1 3\n3 1 2 3\n', '2 4\n2 1 2\n3 2 3 4\n', '2 2\n3 2 2 1\n2 1 2\n', '3 7\n2 1 2\n2 3 4\n3 5 6 7\n'] Demo Output: ['1\n', '6\n', '2\n', '1\n', '24\n'] Note: In the first case, the only possible evolution plan is: In the second case, any permutation of (1,  2,  3) is valid. In the third case, there are two possible plans: In the fourth case, the only possible evolution plan is:
```python from array import array from collections import Counter n, m = [int(x) for x in input().split()] inv = array('Q', (0 for t in range(m))) for i in range(n): tcs = Counter([int(x) for x in input().split()][1:]) for t, c in tcs.iteritems(): inv[t-1] = 0xffffffffffffffff & (inv[t-1] + 14524308274859922871 * i + 15722343008486712703 * c) r = 1 mod = 10**9+7 for c in Counter(inv).itervalues(): for i in xrange(2, c+1): r = r * i % mod print r ```
-1
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,695,374,355
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n=int(input()) s=input() Ap=0 Dp=0 for i in s: if i=='A': Ap+=1 else: Dp+=1 if Ap==Dp: print("FRENDSHIP") elif Ap>Dp: print("Anton") else: print("Danik")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python n=int(input()) s=input() Ap=0 Dp=0 for i in s: if i=='A': Ap+=1 else: Dp+=1 if Ap==Dp: print("FRENDSHIP") elif Ap>Dp: print("Anton") else: print("Danik") ```
0
284
A
Cows and Primitive Roots
PROGRAMMING
1,400
[ "implementation", "math", "number theory" ]
null
null
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=&lt;<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots .
The input contains a single line containing an integer *p* (2<=≤<=*p*<=&lt;<=2000). It is guaranteed that *p* is a prime.
Output on a single line the number of primitive roots .
[ "3\n", "5\n" ]
[ "1\n", "2\n" ]
The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3.
500
[ { "input": "3", "output": "1" }, { "input": "5", "output": "2" }, { "input": "7", "output": "2" }, { "input": "11", "output": "4" }, { "input": "17", "output": "8" }, { "input": "19", "output": "6" }, { "input": "1583", "output": "672" }, { "input": "997", "output": "328" }, { "input": "2", "output": "1" }, { "input": "1987", "output": "660" }, { "input": "1993", "output": "656" }, { "input": "1997", "output": "996" }, { "input": "1999", "output": "648" }, { "input": "1297", "output": "432" }, { "input": "163", "output": "54" }, { "input": "1259", "output": "576" }, { "input": "821", "output": "320" }, { "input": "29", "output": "12" }, { "input": "43", "output": "12" }, { "input": "1949", "output": "972" }, { "input": "1879", "output": "624" }, { "input": "1759", "output": "584" }, { "input": "1597", "output": "432" }, { "input": "1619", "output": "808" }, { "input": "1277", "output": "560" }, { "input": "1097", "output": "544" }, { "input": "953", "output": "384" }, { "input": "751", "output": "200" }, { "input": "607", "output": "200" }, { "input": "509", "output": "252" }, { "input": "431", "output": "168" }, { "input": "317", "output": "156" }, { "input": "211", "output": "48" }, { "input": "127", "output": "36" }, { "input": "101", "output": "40" }, { "input": "31", "output": "8" } ]
1,555,838,430
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
1,058
0
n=int(input()) ro=0 for i in range(2,n): c=1 for h in range(1,n): c=(c*i)%n if(c%n==1): if(h==n-1): ro+=1 else: break print(ro)
Title: Cows and Primitive Roots Time Limit: None seconds Memory Limit: None megabytes Problem Description: The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=&lt;<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots . Input Specification: The input contains a single line containing an integer *p* (2<=≤<=*p*<=&lt;<=2000). It is guaranteed that *p* is a prime. Output Specification: Output on a single line the number of primitive roots . Demo Input: ['3\n', '5\n'] Demo Output: ['1\n', '2\n'] Note: The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3.
```python n=int(input()) ro=0 for i in range(2,n): c=1 for h in range(1,n): c=(c*i)%n if(c%n==1): if(h==n-1): ro+=1 else: break print(ro) ```
0
724
B
Batch Sort
PROGRAMMING
1,500
[ "brute force", "greedy", "implementation", "math" ]
null
null
You are given a table consisting of *n* rows and *m* columns. Numbers in each row form a permutation of integers from 1 to *m*. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to *n*<=+<=1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1,<=2,<=...,<=*m* in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=20) — the number of rows and the number of columns in the given table. Each of next *n* lines contains *m* integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*.
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
[ "2 4\n1 3 2 4\n1 3 4 2\n", "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n", "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 4 3 2</center> 1. In the second row, swap the second and the fourth elements. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 2 3 4</center>
1,000
[ { "input": "2 4\n1 3 2 4\n1 3 4 2", "output": "YES" }, { "input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "output": "NO" }, { "input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5", "output": "YES" }, { "input": "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "5 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 8 5 6 7 10 9 4 11 12\n1 5 3 4 2 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12", "output": "YES" }, { "input": "4 10\n3 2 8 10 5 6 7 1 9 4\n1 2 9 4 5 3 7 8 10 6\n7 5 3 4 8 6 1 2 9 10\n4 2 3 9 8 6 7 5 1 10", "output": "NO" }, { "input": "5 10\n9 2 3 4 5 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 10 7 8 1 6", "output": "NO" }, { "input": "1 10\n9 10 4 2 3 5 7 1 8 6", "output": "NO" }, { "input": "5 10\n6 4 7 3 5 8 1 9 10 2\n1 5 10 6 3 4 9 7 2 8\n3 2 1 7 8 6 5 4 10 9\n7 9 1 6 8 2 4 5 3 10\n3 4 6 9 8 7 1 2 10 5", "output": "NO" }, { "input": "20 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n2 1", "output": "YES" }, { "input": "20 3\n3 2 1\n2 3 1\n2 3 1\n2 1 3\n1 3 2\n2 1 3\n1 2 3\n3 2 1\n3 1 2\n1 3 2\n3 1 2\n2 1 3\n2 3 1\n2 3 1\n3 1 2\n1 3 2\n3 1 2\n1 3 2\n3 1 2\n3 1 2", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n1 2 3 4 5 6 7 10 9 8", "output": "YES" }, { "input": "1 10\n6 9 3 4 5 1 8 7 2 10", "output": "NO" }, { "input": "5 20\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "output": "YES" }, { "input": "5 20\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20", "output": "YES" }, { "input": "5 20\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20", "output": "NO" }, { "input": "1 10\n4 2 3 8 5 6 7 1 9 10", "output": "YES" }, { "input": "1 10\n3 2 1 4 5 6 7 8 10 9", "output": "YES" }, { "input": "5 20\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20", "output": "YES" }, { "input": "5 20\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20", "output": "YES" }, { "input": "5 20\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20", "output": "NO" }, { "input": "1 10\n10 2 3 4 5 9 7 8 6 1", "output": "YES" }, { "input": "1 10\n1 9 2 4 6 5 8 3 7 10", "output": "NO" }, { "input": "5 20\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20", "output": "NO" }, { "input": "5 20\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20", "output": "NO" }, { "input": "5 20\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1", "output": "NO" }, { "input": "1 4\n2 3 4 1", "output": "NO" }, { "input": "3 3\n1 2 3\n2 1 3\n3 2 1", "output": "YES" }, { "input": "15 6\n2 1 4 3 6 5\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "2 4\n4 3 2 1\n4 3 1 2", "output": "NO" }, { "input": "2 4\n1 2 3 4\n2 1 4 3", "output": "YES" }, { "input": "10 6\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1", "output": "NO" }, { "input": "4 4\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "4 8\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7", "output": "YES" }, { "input": "4 6\n1 2 3 5 6 4\n3 2 1 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "3 3\n1 2 3\n3 1 2\n1 3 2", "output": "YES" }, { "input": "2 5\n5 2 1 4 3\n2 1 5 4 3", "output": "YES" }, { "input": "20 8\n4 3 2 1 5 6 7 8\n1 2 3 4 8 7 6 5\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8", "output": "NO" }, { "input": "6 8\n8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8", "output": "NO" }, { "input": "6 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11", "output": "YES" }, { "input": "6 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 10 11 12 9", "output": "NO" }, { "input": "2 4\n2 3 1 4\n3 2 1 4", "output": "YES" }, { "input": "2 4\n4 3 2 1\n1 2 3 4", "output": "YES" }, { "input": "2 4\n1 2 3 4\n4 3 2 1", "output": "YES" }, { "input": "2 6\n2 3 1 4 5 6\n1 2 3 5 6 4", "output": "NO" }, { "input": "3 3\n2 3 1\n2 3 1\n1 2 3", "output": "YES" }, { "input": "2 6\n6 5 4 3 2 1\n6 5 4 3 2 1", "output": "NO" }, { "input": "5 4\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "5 4\n3 1 4 2\n3 1 4 2\n3 1 4 2\n3 1 4 2\n3 1 4 2", "output": "NO" }, { "input": "6 8\n3 8 1 4 5 6 7 2\n1 8 3 6 5 4 7 2\n1 8 3 5 4 6 7 2\n1 8 3 7 5 6 4 2\n1 8 3 7 5 6 4 2\n1 8 3 7 5 6 4 2", "output": "YES" }, { "input": "2 5\n5 2 4 3 1\n2 1 5 4 3", "output": "NO" }, { "input": "4 4\n2 3 1 4\n1 2 3 4\n2 3 1 4\n2 1 3 4", "output": "YES" }, { "input": "2 4\n1 2 4 3\n2 1 4 3", "output": "YES" }, { "input": "3 5\n1 2 4 3 5\n2 1 4 3 5\n1 2 3 4 5", "output": "YES" }, { "input": "3 10\n2 1 3 4 5 6 8 7 10 9\n1 2 3 4 5 6 8 7 10 9\n1 2 3 4 6 5 8 7 10 9", "output": "NO" }, { "input": "3 4\n3 1 2 4\n3 2 4 1\n3 1 2 4", "output": "YES" }, { "input": "2 5\n1 4 2 3 5\n1 2 4 5 3", "output": "YES" }, { "input": "2 5\n2 1 5 3 4\n2 1 5 3 4", "output": "NO" }, { "input": "3 6\n2 3 1 4 5 6\n2 1 4 3 5 6\n1 2 3 4 5 6", "output": "YES" }, { "input": "6 6\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "2 4\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "6 6\n6 5 4 3 2 1\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "4 6\n6 5 4 3 2 1\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6", "output": "NO" }, { "input": "2 4\n2 3 1 4\n1 2 3 4", "output": "YES" }, { "input": "3 5\n1 2 3 4 5\n1 3 4 2 5\n1 4 2 3 5", "output": "YES" }, { "input": "4 3\n1 2 3\n1 2 3\n1 2 3\n3 1 2", "output": "YES" }, { "input": "2 3\n3 1 2\n1 2 3", "output": "YES" }, { "input": "2 5\n2 1 5 4 3\n2 1 5 4 3", "output": "YES" }, { "input": "7 4\n1 2 3 4\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1", "output": "YES" }, { "input": "3 3\n1 2 3\n1 3 2\n3 1 2", "output": "YES" }, { "input": "10 6\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5", "output": "NO" } ]
1,476,020,128
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
4,608,000
n, m = map(int, input().split()) t = [[]for i in range(m)] for _ in range(n): for i, v in zip(range(m), map(int, input().split())): t[i] += [v] pattern = list(range(1, m + 1)) for i in range(m): for j in range(i, m): t[i], t[j] = t[j], t[i] if all(3 > sum(t[i][j] != pattern[i] for i in range(m)) for j in range(n)):r='YES' t[i], t[j]=t[j], t[i] print("NO")
Title: Batch Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a table consisting of *n* rows and *m* columns. Numbers in each row form a permutation of integers from 1 to *m*. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to *n*<=+<=1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1,<=2,<=...,<=*m* in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=20) — the number of rows and the number of columns in the given table. Each of next *n* lines contains *m* integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*. Output Specification: If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Demo Input: ['2 4\n1 3 2 4\n1 3 4 2\n', '4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n', '3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 4 3 2</center> 1. In the second row, swap the second and the fourth elements. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 2 3 4</center>
```python n, m = map(int, input().split()) t = [[]for i in range(m)] for _ in range(n): for i, v in zip(range(m), map(int, input().split())): t[i] += [v] pattern = list(range(1, m + 1)) for i in range(m): for j in range(i, m): t[i], t[j] = t[j], t[i] if all(3 > sum(t[i][j] != pattern[i] for i in range(m)) for j in range(n)):r='YES' t[i], t[j]=t[j], t[i] print("NO") ```
0
4
C
Registration System
PROGRAMMING
1,300
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
0
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" }, { "input": "3\nb\nb\nb", "output": "OK\nb1\nb2" }, { "input": "2\nc\ncn", "output": "OK\nOK" }, { "input": "3\nvhn\nvhn\nh", "output": "OK\nvhn1\nOK" }, { "input": "4\nd\nhd\nd\nh", "output": "OK\nOK\nd1\nOK" }, { "input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp", "output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9" }, { "input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh", "output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7" }, { "input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj", "output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4" }, { "input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4" }, { "input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3" } ]
1,693,221,799
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
5,000
8,089,600
n = int(input()) l = [] s = [0]*n c = 0 for _ in range(n): a = input() if a in l: s[c] = f"{a}{l.count(a)}" else: s[c] = "OK" l.append(a) c += 1 print('\n'.join(map(str, s)))
Title: Registration System Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. Output Specification: Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. Demo Input: ['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n'] Demo Output: ['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n'] Note: none
```python n = int(input()) l = [] s = [0]*n c = 0 for _ in range(n): a = input() if a in l: s[c] = f"{a}{l.count(a)}" else: s[c] = "OK" l.append(a) c += 1 print('\n'.join(map(str, s))) ```
0
56
A
Bar
PROGRAMMING
1,000
[ "implementation" ]
A. Bar
2
256
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol.
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
[ "5\n18\nVODKA\nCOKE\n19\n17\n" ]
[ "2\n" ]
In the sample test the second and fifth clients should be checked.
500
[ { "input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2" }, { "input": "2\n2\nGIN", "output": "2" }, { "input": "3\nWHISKEY\n3\nGIN", "output": "3" }, { "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW", "output": "1" }, { "input": "4\nSAKE\nSAKE\n13\n2", "output": "4" }, { "input": "2\n0\n17", "output": "2" }, { "input": "1\n0", "output": "1" } ]
1,509,259,981
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
n=int(input()) c=0 for i in range(0,n): p=input() if ord(p[0])>=65 and ord(p[0])<=96 : pass else: p=int(p) if p>=18 : c+=1 print(c)
Title: Bar Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol. Output Specification: Print a single number which is the number of people Vasya should check to guarantee the law enforcement. Demo Input: ['5\n18\nVODKA\nCOKE\n19\n17\n'] Demo Output: ['2\n'] Note: In the sample test the second and fifth clients should be checked.
```python n=int(input()) c=0 for i in range(0,n): p=input() if ord(p[0])>=65 and ord(p[0])<=96 : pass else: p=int(p) if p>=18 : c+=1 print(c) ```
0
831
A
Unimodal Array
PROGRAMMING
1,000
[ "implementation" ]
null
null
Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array.
Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower).
[ "6\n1 5 5 5 4 2\n", "5\n10 20 30 20 10\n", "4\n1 2 1 2\n", "7\n3 3 3 3 3 3 3\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n" ]
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
500
[ { "input": "6\n1 5 5 5 4 2", "output": "YES" }, { "input": "5\n10 20 30 20 10", "output": "YES" }, { "input": "4\n1 2 1 2", "output": "NO" }, { "input": "7\n3 3 3 3 3 3 3", "output": "YES" }, { "input": "6\n5 7 11 11 2 1", "output": "YES" }, { "input": "1\n7", "output": "YES" }, { "input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "YES" }, { "input": "5\n5 5 6 6 1", "output": "NO" }, { "input": "3\n4 4 2", "output": "YES" }, { "input": "4\n4 5 5 6", "output": "NO" }, { "input": "3\n516 516 515", "output": "YES" }, { "input": "5\n502 503 508 508 507", "output": "YES" }, { "input": "10\n538 538 538 538 538 538 538 538 538 538", "output": "YES" }, { "input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426", "output": "YES" }, { "input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513", "output": "YES" }, { "input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337", "output": "YES" }, { "input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479", "output": "YES" }, { "input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393", "output": "YES" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "YES" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "YES" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "YES" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "YES" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "YES" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "YES" }, { "input": "1\n1000", "output": "YES" }, { "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": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1", "output": "YES" }, { "input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999", "output": "NO" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "NO" }, { "input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "NO" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "NO" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "NO" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "NO" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "NO" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n2 1 1", "output": "NO" }, { "input": "3\n2 1 2", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "YES" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "YES" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "NO" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "NO" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "2\n1 3", "output": "YES" }, { "input": "2\n1 2", "output": "YES" }, { "input": "5\n2 2 1 1 1", "output": "NO" }, { "input": "4\n1 3 2 2", "output": "NO" }, { "input": "6\n1 2 1 2 2 1", "output": "NO" }, { "input": "2\n4 2", "output": "YES" }, { "input": "3\n3 2 2", "output": "NO" }, { "input": "9\n1 2 2 3 3 4 3 2 1", "output": "NO" }, { "input": "4\n5 5 4 4", "output": "NO" }, { "input": "2\n2 1", "output": "YES" }, { "input": "5\n5 4 3 2 1", "output": "YES" }, { "input": "7\n4 3 3 3 3 3 3", "output": "NO" }, { "input": "5\n1 2 3 4 5", "output": "YES" }, { "input": "3\n2 2 1", "output": "YES" }, { "input": "3\n4 3 3", "output": "NO" }, { "input": "7\n1 5 5 4 3 3 1", "output": "NO" }, { "input": "6\n3 3 1 2 2 1", "output": "NO" }, { "input": "5\n1 2 1 2 1", "output": "NO" }, { "input": "2\n5 1", "output": "YES" }, { "input": "9\n1 2 3 4 4 3 2 2 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "2\n5 4", "output": "YES" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 7 8 9 99", "output": "YES" }, { "input": "4\n1 2 3 4", "output": "YES" }, { "input": "3\n5 5 2", "output": "YES" }, { "input": "4\n1 4 2 3", "output": "NO" }, { "input": "2\n3 2", "output": "YES" }, { "input": "5\n1 2 2 1 1", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "5\n1 2 3 2 2", "output": "NO" }, { "input": "5\n5 6 6 5 5", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n5 4 3 3 2", "output": "NO" }, { "input": "7\n1 3 3 3 2 1 1", "output": "NO" }, { "input": "9\n5 6 6 5 5 4 4 3 3", "output": "NO" }, { "input": "6\n1 5 5 3 2 2", "output": "NO" }, { "input": "5\n2 1 3 3 1", "output": "NO" }, { "input": "2\n4 3", "output": "YES" }, { "input": "5\n3 2 2 1 1", "output": "NO" }, { "input": "4\n5 4 3 2", "output": "YES" }, { "input": "4\n4 4 1 1", "output": "NO" }, { "input": "4\n3 3 1 1", "output": "NO" }, { "input": "4\n4 4 2 2", "output": "NO" }, { "input": "5\n4 4 3 2 2", "output": "NO" }, { "input": "8\n4 4 4 4 5 6 7 8", "output": "NO" }, { "input": "5\n3 5 4 4 3", "output": "NO" }, { "input": "6\n2 5 3 3 2 2", "output": "NO" }, { "input": "4\n5 5 2 2", "output": "NO" }, { "input": "5\n1 2 2 3 5", "output": "NO" } ]
1,640,892,605
2,147,483,647
Python 3
OK
TESTS
101
46
0
n=int(input()) a=list(map(int,input().split())) c=0 while c<n-1 and a[c]<a[c+1]: c=c+1 while c<n-1 and a[c]==a[c+1]: c=c+1 while c<n-1 and a[c]>a[c+1]: c=c+1 d=n-1 if c==d: print('YES') else: print('NO')
Title: Unimodal Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. Output Specification: Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Demo Input: ['6\n1 5 5 5 4 2\n', '5\n10 20 30 20 10\n', '4\n1 2 1 2\n', '7\n3 3 3 3 3 3 3\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
```python n=int(input()) a=list(map(int,input().split())) c=0 while c<n-1 and a[c]<a[c+1]: c=c+1 while c<n-1 and a[c]==a[c+1]: c=c+1 while c<n-1 and a[c]>a[c+1]: c=c+1 d=n-1 if c==d: print('YES') else: print('NO') ```
3
463
D
Gargari and Permutations
PROGRAMMING
1,900
[ "dfs and similar", "dp", "graphs", "implementation" ]
null
null
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutations. Can you help Gargari? You can read about longest common subsequence there: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*k*<=≤<=5). Each of the next *k* lines contains integers 1,<=2,<=...,<=*n* in some order — description of the current permutation.
Print the length of the longest common subsequence.
[ "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n" ]
[ "3\n" ]
The answer for the first test sample is subsequence [1, 2, 3].
2,000
[ { "input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3" }, { "input": "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1", "output": "3" }, { "input": "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 20 6 28\n31 27 39 16 22 12 13 32 6 10 19 29 37 7 18 33 24 21 1 9 36 4 34 41 25 28 17 40 30 35 23 14 11 8 2 15 38 20 26 5 3\n8 18 39 38 7 34 16 31 15 1 40 20 37 4 25 11 17 19 33 26 6 14 13 41 12 32 2 21 10 35 27 9 28 5 30 24 22 23 29 3 36", "output": "4" }, { "input": "1 2\n1\n1", "output": "1" }, { "input": "28 5\n3 14 12 16 13 27 20 8 1 10 24 11 5 9 7 18 17 23 22 25 28 19 4 21 26 6 15 2\n7 12 23 27 22 26 16 18 19 5 6 9 11 28 25 4 10 3 1 14 8 17 15 2 20 13 24 21\n21 20 2 5 19 15 12 4 18 9 23 16 11 14 8 6 25 27 13 17 10 26 7 24 28 1 3 22\n12 2 23 11 20 18 25 21 13 27 14 8 4 6 9 16 7 3 10 1 22 15 26 19 5 17 28 24\n13 2 6 19 22 23 4 1 28 10 18 17 21 8 9 3 26 11 12 27 14 20 24 25 15 5 16 7", "output": "3" }, { "input": "6 3\n2 5 1 4 6 3\n5 1 4 6 2 3\n5 4 2 6 3 1", "output": "4" }, { "input": "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 20 6 28\n31 27 39 16 22 12 13 32 6 10 19 29 37 7 18 33 24 21 1 9 36 4 34 41 25 28 17 40 30 35 23 14 11 8 2 15 38 20 26 5 3\n8 18 39 38 7 34 16 31 15 1 40 20 37 4 25 11 17 19 33 26 6 14 13 41 12 32 2 21 10 35 27 9 28 5 30 24 22 23 29 3 36", "output": "4" }, { "input": "37 3\n6 3 19 20 15 4 1 35 8 24 12 21 34 26 18 14 23 33 28 9 36 11 37 31 25 32 29 22 13 27 16 17 10 7 5 30 2\n10 3 35 17 34 21 14 8 26 28 11 19 27 7 4 23 24 22 12 13 16 1 25 29 5 31 30 20 32 18 15 9 2 36 37 33 6\n19 9 22 32 26 35 29 23 5 6 14 34 33 10 2 28 15 11 24 4 13 7 8 31 37 36 1 27 3 16 30 25 20 21 18 17 12", "output": "7" } ]
1,623,054,215
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
140
1,536,000
import sys input=sys.stdin.readline n,k=map(int,input().split()) a=[list(map(int,input().split())) for i in range(k)] g=[[] for i in range(n+1)] for i in range(n): x=a[0][i] s1=set(a[0][i+1:]) idx2=a[1].index(x) s2=set(a[1][idx2+1:]) idx3=a[2].index(x) s3=set(a[2][idx3+1:]) s=s1&s2&s3 for y in s: g[x].append(y) MAX=0 for s in range(1,n+1): q=[[0,s]] dist=[-1]*(n+1) dist[s]=0 while q: cost,ver=q.pop() for to in g[ver]: if dist[to]<cost+1: dist[to]=cost+1 q.append([dist[to],to]) MAX=max(MAX,max(dist)) print(MAX+1)
Title: Gargari and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutations. Can you help Gargari? You can read about longest common subsequence there: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*k*<=≤<=5). Each of the next *k* lines contains integers 1,<=2,<=...,<=*n* in some order — description of the current permutation. Output Specification: Print the length of the longest common subsequence. Demo Input: ['4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n'] Demo Output: ['3\n'] Note: The answer for the first test sample is subsequence [1, 2, 3].
```python import sys input=sys.stdin.readline n,k=map(int,input().split()) a=[list(map(int,input().split())) for i in range(k)] g=[[] for i in range(n+1)] for i in range(n): x=a[0][i] s1=set(a[0][i+1:]) idx2=a[1].index(x) s2=set(a[1][idx2+1:]) idx3=a[2].index(x) s3=set(a[2][idx3+1:]) s=s1&s2&s3 for y in s: g[x].append(y) MAX=0 for s in range(1,n+1): q=[[0,s]] dist=[-1]*(n+1) dist[s]=0 while q: cost,ver=q.pop() for to in g[ver]: if dist[to]<cost+1: dist[to]=cost+1 q.append([dist[to],to]) MAX=max(MAX,max(dist)) print(MAX+1) ```
0
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,636,785,002
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
218
42,803,200
import math import itertools import random s=input() o=0 q=0 ans='abcdefghijklmnopqrstuvwxyz' if len(s)==1: w=ans.index(s[0]) print(w) else: for l in s: ans=ans[o:]+ans[:o] a=ans.index(l)+1 o=a p=min(len(ans)-a,a) q+=p if 'a' in s: print(q-1) else: print(q+1)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python import math import itertools import random s=input() o=0 q=0 ans='abcdefghijklmnopqrstuvwxyz' if len(s)==1: w=ans.index(s[0]) print(w) else: for l in s: ans=ans[o:]+ans[:o] a=ans.index(l)+1 o=a p=min(len(ans)-a,a) q+=p if 'a' in s: print(q-1) else: print(q+1) ```
0
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input": "1 1000000000000000000 2 99999999999999999 1000000000", "output": "99999999999999997" }, { "input": "1 1 1 1 1", "output": "0" }, { "input": "1 2 3 4 5", "output": "0" }, { "input": "1 1000000000 2 999999999 3141592", "output": "999999997" }, { "input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "output": "0" }, { "input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "output": "27788438422925" }, { "input": "11814 27385 22309 28354 23595", "output": "5076" }, { "input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "output": "29117730788587" }, { "input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "output": "81604391064" }, { "input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "output": "47247500916780901" }, { "input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "output": "0" }, { "input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "output": "48172141432145241" }, { "input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "output": "99277597320376979" }, { "input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "output": "256787461333454149" }, { "input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "output": "37925278862451249" }, { "input": "1 3 3 5 3", "output": "0" }, { "input": "1 5 8 10 9", "output": "0" }, { "input": "1 2 4 5 10", "output": "0" }, { "input": "1 2 2 3 5", "output": "1" }, { "input": "2 4 3 7 3", "output": "1" }, { "input": "1 2 9 10 1", "output": "0" }, { "input": "5 15 1 10 5", "output": "5" }, { "input": "1 4 9 20 25", "output": "0" }, { "input": "2 4 1 2 5", "output": "1" }, { "input": "10 1000 1 100 2", "output": "91" }, { "input": "1 3 3 8 10", "output": "1" }, { "input": "4 6 6 8 9", "output": "1" }, { "input": "2 3 1 4 3", "output": "1" }, { "input": "1 2 2 3 100", "output": "1" }, { "input": "1 2 100 120 2", "output": "0" }, { "input": "1 3 5 7 4", "output": "0" }, { "input": "1 3 5 7 5", "output": "0" }, { "input": "1 4 8 10 6", "output": "0" }, { "input": "1 2 5 6 100", "output": "0" }, { "input": "1 2 5 10 20", "output": "0" }, { "input": "1 2 5 6 7", "output": "0" }, { "input": "2 5 7 12 6", "output": "0" }, { "input": "10 20 50 100 80", "output": "0" }, { "input": "1 2 5 10 2", "output": "0" }, { "input": "1 2 5 6 4", "output": "0" }, { "input": "5 9 1 2 3", "output": "0" }, { "input": "50 100 1 20 3", "output": "0" }, { "input": "10 20 3 7 30", "output": "0" }, { "input": "1 5 10 10 100", "output": "0" }, { "input": "100 101 1 2 3", "output": "0" }, { "input": "1 5 10 20 6", "output": "0" }, { "input": "1 10 15 25 5", "output": "0" }, { "input": "1 2 5 10 3", "output": "0" }, { "input": "2 3 5 6 100", "output": "0" }, { "input": "1 2 4 5 6", "output": "0" }, { "input": "6 10 1 2 40", "output": "0" }, { "input": "20 30 1 5 1", "output": "0" }, { "input": "20 40 50 100 50", "output": "0" }, { "input": "1 1 4 9 2", "output": "0" }, { "input": "1 2 5 6 1", "output": "0" }, { "input": "1 100 400 500 450", "output": "0" }, { "input": "5 6 1 2 5", "output": "0" }, { "input": "1 10 21 30 50", "output": "0" }, { "input": "100 200 300 400 101", "output": "0" }, { "input": "2 8 12 16 9", "output": "0" }, { "input": "1 5 7 9 6", "output": "0" }, { "input": "300 400 100 200 101", "output": "0" }, { "input": "1 2 2 3 10", "output": "1" }, { "input": "1 10 100 200 5", "output": "0" }, { "input": "1 3 3 4 4", "output": "1" }, { "input": "10 20 30 40 25", "output": "0" }, { "input": "1 2 5 10 1", "output": "0" }, { "input": "2 4 8 10 1", "output": "0" }, { "input": "2 5 10 15 7", "output": "0" }, { "input": "100 200 5 10 1", "output": "0" }, { "input": "1 2 100 200 300", "output": "0" }, { "input": "30 100 10 20 25", "output": "0" }, { "input": "10 20 1 5 6", "output": "0" }, { "input": "4 5 1 2 4", "output": "0" }, { "input": "11 100 1 9 1000", "output": "0" }, { "input": "1 1 10 10 228", "output": "0" }, { "input": "5 7 10 20 15", "output": "0" }, { "input": "1 3 8 9 7", "output": "0" }, { "input": "1 10 2 8 8", "output": "6" }, { "input": "1 5 9 15 1", "output": "0" }, { "input": "1 3 5 6 12", "output": "0" }, { "input": "1 100 500 1000 3", "output": "0" }, { "input": "1 1 1 1 2", "output": "1" }, { "input": "1 1000 100 1000 200", "output": "900" }, { "input": "4 5 1 4 1", "output": "1" }, { "input": "1 5 5 7 3", "output": "1" }, { "input": "1 4 4 10 11", "output": "1" }, { "input": "1 1 3 4 100", "output": "0" }, { "input": "1 4 3 5 6", "output": "2" }, { "input": "10 100 20 30 40", "output": "11" }, { "input": "5 9 1 11 7", "output": "4" } ]
1,564,804,883
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
108
0
l11, l12, l21, l22, prink = [int(x) for x in input().split()] begin = max(l11, l21) ends = min(l12, l22) meeting = max(0, ends - begin + 1) meeting += begin <= prink <= ends print(meeting)
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together. Input Specification: The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Specification: Print one integer — the number of minutes Sonya and Filya will be able to spend together. Demo Input: ['1 10 9 20 1\n', '1 100 50 200 75\n'] Demo Output: ['2\n', '50\n'] Note: In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
```python l11, l12, l21, l22, prink = [int(x) for x in input().split()] begin = max(l11, l21) ends = min(l12, l22) meeting = max(0, ends - begin + 1) meeting += begin <= prink <= ends print(meeting) ```
0
622
B
The Time
PROGRAMMING
900
[ "implementation" ]
null
null
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes. Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedia.org/wiki/24-hour_clock).
The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=&lt;<=24,<=0<=≤<=*mm*<=&lt;<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes passed.
The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format.
[ "23:59\n10\n", "20:20\n121\n", "10:10\n0\n" ]
[ "00:09\n", "22:21\n", "10:10\n" ]
none
0
[ { "input": "23:59\n10", "output": "00:09" }, { "input": "20:20\n121", "output": "22:21" }, { "input": "10:10\n0", "output": "10:10" }, { "input": "12:34\n10000", "output": "11:14" }, { "input": "00:00\n10000", "output": "22:40" }, { "input": "00:00\n1440", "output": "00:00" }, { "input": "23:59\n8640", "output": "23:59" }, { "input": "10:01\n0", "output": "10:01" }, { "input": "04:05\n0", "output": "04:05" }, { "input": "02:59\n1", "output": "03:00" }, { "input": "05:15\n10", "output": "05:25" }, { "input": "03:10\n20", "output": "03:30" }, { "input": "09:11\n0", "output": "09:11" }, { "input": "19:00\n0", "output": "19:00" }, { "input": "23:59\n1", "output": "00:00" }, { "input": "11:59\n1", "output": "12:00" }, { "input": "19:34\n566", "output": "05:00" }, { "input": "00:01\n59", "output": "01:00" }, { "input": "03:30\n0", "output": "03:30" }, { "input": "22:30\n30", "output": "23:00" }, { "input": "22:50\n70", "output": "00:00" }, { "input": "05:12\n0", "output": "05:12" }, { "input": "09:20\n40", "output": "10:00" }, { "input": "15:04\n36", "output": "15:40" }, { "input": "05:37\n23", "output": "06:00" }, { "input": "23:59\n59", "output": "00:58" }, { "input": "21:09\n9997", "output": "19:46" }, { "input": "11:00\n1", "output": "11:01" }, { "input": "20:01\n2699", "output": "17:00" }, { "input": "01:00\n59", "output": "01:59" }, { "input": "07:09\n6538", "output": "20:07" }, { "input": "00:00\n10", "output": "00:10" }, { "input": "02:09\n2074", "output": "12:43" }, { "input": "01:10\n1", "output": "01:11" }, { "input": "23:01\n59", "output": "00:00" }, { "input": "08:50\n20", "output": "09:10" }, { "input": "13:18\n5121", "output": "02:39" }, { "input": "18:31\n2677", "output": "15:08" }, { "input": "14:17\n108", "output": "16:05" }, { "input": "02:45\n5617", "output": "00:22" }, { "input": "00:00\n3600", "output": "12:00" }, { "input": "19:01\n59", "output": "20:00" }, { "input": "19:02\n59", "output": "20:01" }, { "input": "14:00\n2880", "output": "14:00" }, { "input": "01:10\n44", "output": "01:54" }, { "input": "02:01\n59", "output": "03:00" }, { "input": "07:02\n121", "output": "09:03" }, { "input": "10:00\n61", "output": "11:01" }, { "input": "23:59\n61", "output": "01:00" }, { "input": "00:00\n0", "output": "00:00" }, { "input": "23:59\n121", "output": "02:00" }, { "input": "00:00\n60", "output": "01:00" }, { "input": "15:52\n60", "output": "16:52" }, { "input": "00:39\n6525", "output": "13:24" }, { "input": "00:30\n30", "output": "01:00" }, { "input": "00:59\n1", "output": "01:00" }, { "input": "00:55\n4321", "output": "00:56" }, { "input": "10:05\n1", "output": "10:06" }, { "input": "23:00\n60", "output": "00:00" } ]
1,455,217,172
2,147,483,647
Python 3
OK
TESTS
59
62
0
hh, mm = [int(t) for t in input().split(':')] dm = int(input()) mm += dm hh += mm//60 mm %= 60 hh %= 24 print("{0}:{1}".format(str(hh).zfill(2), str(mm).zfill(2)))
Title: The Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes. Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedia.org/wiki/24-hour_clock). Input Specification: The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=&lt;<=24,<=0<=≤<=*mm*<=&lt;<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes passed. Output Specification: The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format. Demo Input: ['23:59\n10\n', '20:20\n121\n', '10:10\n0\n'] Demo Output: ['00:09\n', '22:21\n', '10:10\n'] Note: none
```python hh, mm = [int(t) for t in input().split(':')] dm = int(input()) mm += dm hh += mm//60 mm %= 60 hh %= 24 print("{0}:{1}".format(str(hh).zfill(2), str(mm).zfill(2))) ```
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,593,047,435
2,147,483,647
PyPy 3
OK
TESTS
20
340
21,913,600
n = int(input()) d = {} l = [] for i in range(n): x , y = input().split() d[x] = d.get(x , 0) + int(y) l.append([x , d[x]]) m = max(d.values()) for i , j in l : if d[i] == m and int(j) >= m : print(i) break
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python n = int(input()) d = {} l = [] for i in range(n): x , y = input().split() d[x] = d.get(x , 0) + int(y) l.append([x , d[x]]) m = max(d.values()) for i , j in l : if d[i] == m and int(j) >= m : print(i) break ```
3.666731
224
B
Array
PROGRAMMING
1,500
[ "bitmasks", "implementation", "two pointers" ]
null
null
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
[ "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n", "7 4\n4 7 7 4 7 4 7\n" ]
[ "1 2\n", "2 5\n", "-1 -1\n" ]
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
1,000
[ { "input": "4 2\n1 2 2 3", "output": "1 2" }, { "input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5" }, { "input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1" }, { "input": "5 1\n1 7 2 3 2", "output": "1 1" }, { "input": "1 2\n666", "output": "-1 -1" }, { "input": "1 1\n5", "output": "1 1" }, { "input": "10 4\n1 1 2 2 3 3 4 4 4 4", "output": "2 7" }, { "input": "4 2\n3 3 4 3", "output": "2 3" }, { "input": "4 3\n4 4 4 2", "output": "-1 -1" }, { "input": "10 5\n15 17 2 13 3 16 4 5 9 12", "output": "1 5" }, { "input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148", "output": "1 13" }, { "input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796", "output": "-1 -1" }, { "input": "8 5\n1 2 1 1 2 3 4 5", "output": "4 8" }, { "input": "7 3\n2 1 2 2 1 2 3", "output": "5 7" }, { "input": "6 3\n1 3 1 1 4 5", "output": "2 5" }, { "input": "5 3\n1 2 1 1 3", "output": "2 5" }, { "input": "9 3\n1 2 1 2 1 2 2 3 1", "output": "5 8" }, { "input": "4 3\n1 2 1 3", "output": "2 4" }, { "input": "5 3\n1 3 1 3 4", "output": "3 5" }, { "input": "6 3\n1 3 3 1 4 4", "output": "3 5" }, { "input": "5 3\n1 2 1 2 3", "output": "3 5" }, { "input": "8 4\n1 2 3 2 1 2 3 4", "output": "5 8" }, { "input": "10 4\n1 2 3 1 2 3 4 3 2 1", "output": "4 7" }, { "input": "10 3\n1 1 1 2 1 2 3 3 3 4", "output": "5 7" }, { "input": "10 3\n1 1 2 1 2 2 3 4 5 6", "output": "4 7" } ]
1,631,894,558
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
124
6,758,400
n = list(map(int, input().split())) a = list(map(int, input().split())) check_point = n[1] set_A = set(a) # print (set_A) len_set = len(set_A) # print(len_set) list = list(set_A) if len_set >= check_point: print (list[0],list[check_point-1])
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. Input Specification: The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. Demo Input: ['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n'] Demo Output: ['1 2\n', '2 5\n', '-1 -1\n'] Note: In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
```python n = list(map(int, input().split())) a = list(map(int, input().split())) check_point = n[1] set_A = set(a) # print (set_A) len_set = len(set_A) # print(len_set) list = list(set_A) if len_set >= check_point: print (list[0],list[check_point-1]) ```
0
777
B
Game of Credit Cards
PROGRAMMING
1,300
[ "data structures", "dp", "greedy", "sortings" ]
null
null
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick. Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks. Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use. The second line contains *n* digits — Sherlock's credit card number. The third line contains *n* digits — Moriarty's credit card number.
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
[ "3\n123\n321\n", "2\n88\n00\n" ]
[ "0\n2\n", "2\n0\n" ]
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
1,000
[ { "input": "3\n123\n321", "output": "0\n2" }, { "input": "2\n88\n00", "output": "2\n0" }, { "input": "1\n4\n5", "output": "0\n1" }, { "input": "1\n8\n7", "output": "1\n0" }, { "input": "2\n55\n55", "output": "0\n0" }, { "input": "3\n534\n432", "output": "1\n1" }, { "input": "3\n486\n024", "output": "2\n0" }, { "input": "5\n22222\n22222", "output": "0\n0" }, { "input": "5\n72471\n05604", "output": "2\n3" }, { "input": "5\n72471\n72471", "output": "0\n3" }, { "input": "5\n72471\n41772", "output": "0\n3" }, { "input": "8\n99999999\n99999999", "output": "0\n0" }, { "input": "8\n01234567\n01234567", "output": "0\n7" }, { "input": "8\n07070707\n76543210", "output": "3\n4" }, { "input": "8\n88888888\n98769876", "output": "4\n2" }, { "input": "8\n23456789\n01234567", "output": "2\n5" }, { "input": "5\n11222\n22111", "output": "1\n2" }, { "input": "9\n777777777\n777777777", "output": "0\n0" }, { "input": "9\n353589343\n280419388", "output": "3\n5" }, { "input": "10\n8104381743\n8104381743", "output": "0\n8" }, { "input": "10\n8104381743\n8418134730", "output": "0\n8" }, { "input": "10\n1111122222\n2222211111", "output": "0\n5" }, { "input": "100\n6317494220822818719411404030346382869796138932712461187067886456209071515048745855973784223939110171\n6017563370120161528504797580620647099370814387367549926215651181421345104088127581963662589996747937", "output": "2\n86" }, { "input": "200\n89017372169770060638462517044634884577600285180365791227828841983192945639410766634962149214165390392679430585962408483864914959904870801002680423351144765728677610509881245693518626747873607530273392\n34804385048475325130258121398275821439066233953856051421626677848150660724595847484466293487857039579239864150199164135152374201294909986469345076423004279983866383035554588630496127880705497919788390", "output": "6\n175" }, { "input": "3\n112\n111", "output": "1\n0" }, { "input": "5\n66666\n11119", "output": "4\n1" }, { "input": "3\n232\n123", "output": "1\n1" } ]
1,587,234,587
4,487
Python 3
RUNTIME_ERROR
TESTS
17
139
409,600
import collections t=int(input()) n=str(input()) m=str(input()) d=collections.Counter(n) #print(d,n) v=collections.Counter(m) k=d-v l=[] l1=[] #print(k) for i in n: if i in k: l.append(i) k[i]-=1 if k[i]==0: del k[i] for j in m: if j not in d: l1.append(j) l.sort() l1.sort(reverse=True) count=0 #print(l,l1) for i in range(len(l)): if l[i]>l1[i]: count+=1 ans=0 #print(d,v) for i in n: for j in range(1,10): g=str(int(i)+j) if g in v: v[g]-=1 ans+=1 if v[g]==0: del v[g] break print(count) print(ans)
Title: Game of Credit Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick. Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks. Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use. The second line contains *n* digits — Sherlock's credit card number. The third line contains *n* digits — Moriarty's credit card number. Output Specification: First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. Demo Input: ['3\n123\n321\n', '2\n88\n00\n'] Demo Output: ['0\n2\n', '2\n0\n'] Note: First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
```python import collections t=int(input()) n=str(input()) m=str(input()) d=collections.Counter(n) #print(d,n) v=collections.Counter(m) k=d-v l=[] l1=[] #print(k) for i in n: if i in k: l.append(i) k[i]-=1 if k[i]==0: del k[i] for j in m: if j not in d: l1.append(j) l.sort() l1.sort(reverse=True) count=0 #print(l,l1) for i in range(len(l)): if l[i]>l1[i]: count+=1 ans=0 #print(d,v) for i in n: for j in range(1,10): g=str(int(i)+j) if g in v: v[g]-=1 ans+=1 if v[g]==0: del v[g] break print(count) print(ans) ```
-1
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,671,917,969
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,764,800
for n in [0]*int(input()): s = input() b = len(input())-2 print(s[0]+b+s[-1] if b>8 else s)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python for n in [0]*int(input()): s = input() b = len(input())-2 print(s[0]+b+s[-1] if b>8 else s) ```
-1
926
G
Large Bouquets
PROGRAMMING
1,500
[]
null
null
A flower shop has got *n* bouquets, and the *i*-th bouquet consists of *a**i* flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet. Determine the maximum possible number of large bouquets Vasya can make.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of initial bouquets. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the number of flowers in each of the initial bouquets.
Print the maximum number of large bouquets Vasya can make.
[ "5\n2 3 4 2 7\n", "6\n2 2 6 8 6 12\n", "3\n11 4 10\n" ]
[ "2\n", "0\n", "1\n" ]
In the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme. In the second example it is not possible to form a single bouquet with odd number of flowers. In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25.
0
[ { "input": "5\n2 3 4 2 7", "output": "2" }, { "input": "6\n2 2 6 8 6 12", "output": "0" }, { "input": "3\n11 4 10", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n999999", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "4\n943543 151729 379602 589828", "output": "2" }, { "input": "2\n468463 62253", "output": "0" }, { "input": "3\n352987 849349 967007", "output": "1" }, { "input": "20\n274039 899325 798709 157662 963297 276599 529230 80095 252956 980560 358150 82383 29856 901568 123794 275349 512273 508369 120076 170206", "output": "10" }, { "input": "25\n742168 377547 485672 437223 96307 902863 759104 747933 512899 410317 588598 666688 823202 257684 520631 910066 168864 71499 899972 565350 764848 754913 929040 864132 289976", "output": "10" } ]
1,521,357,727
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) l = 0 k = 0 arr = list(map(int,input().split())) for i in range(0,n) if arr[i] % 2 == 0 : l = l + 1 if arr[i] % 2 == 1 : k = k + 1 if l>k : print(k) if l<k : print(l+(k-l)/3)
Title: Large Bouquets Time Limit: None seconds Memory Limit: None megabytes Problem Description: A flower shop has got *n* bouquets, and the *i*-th bouquet consists of *a**i* flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet. Determine the maximum possible number of large bouquets Vasya can make. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of initial bouquets. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the number of flowers in each of the initial bouquets. Output Specification: Print the maximum number of large bouquets Vasya can make. Demo Input: ['5\n2 3 4 2 7\n', '6\n2 2 6 8 6 12\n', '3\n11 4 10\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme. In the second example it is not possible to form a single bouquet with odd number of flowers. In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25.
```python n = int(input()) l = 0 k = 0 arr = list(map(int,input().split())) for i in range(0,n) if arr[i] % 2 == 0 : l = l + 1 if arr[i] % 2 == 1 : k = k + 1 if l>k : print(k) if l<k : print(l+(k-l)/3) ```
-1
389
B
Fox and Cross
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way.
The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'.
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
[ "5\n.#...\n####.\n.####\n...#.\n.....\n", "4\n####\n####\n####\n####\n", "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n", "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n", "3\n...\n...\n...\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ]
In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
1,000
[ { "input": "4\n####\n####\n####\n####", "output": "NO" }, { "input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.", "output": "YES" }, { "input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.", "output": "NO" }, { "input": "5\n.....\n.#...\n####.\n.####\n...#.", "output": "YES" }, { "input": "5\n#....\n###..\n.###.\n..##.\n..##.", "output": "NO" }, { "input": "10\n....#...#.\n.#.###.###\n#####.#.#.\n.#######..\n.#.##.#.#.\n######.###\n.#..#.#.#.\n.#..#####.\n##########\n.#..#...#.", "output": "YES" }, { "input": "8\n.#...##.\n##.##.#.\n#....##.\n#.###.##\n...##..#\n#..#.##.\n#..#.#..\n#....###", "output": "NO" }, { "input": "15\n.#...##.##.....\n.###.#.#.##..#.\n##.#####......#\n#....###.#..#..\n#.##.#.###.###.\n.###....#.###.#\n##.....##..#...\n.#.########...#\n##..#..##..#.##\n#...#....##....\n.......#.......\n.#..#.#.####...\n.#..#...#..###.\n#..#.#..#......\n###.....##....#", "output": "NO" }, { "input": "7\n.......\n.......\n.......\n.......\n.....#.\n....###\n.....#.", "output": "YES" }, { "input": "9\n.#.#....#\n#.#.....#\n.#..#..#.\n#.#....##\n...#...#.\n#..###.#.\n....#..##\n.#.###...\n....##..#", "output": "NO" }, { "input": "5\n#...#\n.....\n..#..\n.....\n#...#", "output": "NO" }, { "input": "3\n.#.\n#.#\n.#.", "output": "NO" }, { "input": "3\n...\n...\n..#", "output": "NO" } ]
1,646,007,144
2,147,483,647
PyPy 3
OK
TESTS
42
77
1,843,200
grid = [] yes = True size = int(input()) for x in range(size): grid.append(list(input())) for y in range(size): if not yes: break for x in range(size): if grid[y][x] == "#": if x == 0 or x == size-1 or y >= size-2: print("NO") yes = False break if grid[y+1][x-1] == "." or grid[y+1][x] == "." or grid[y+1][x+1] == "." or grid[y+2][x] == ".": print("NO") yes = False break else: grid[y+1][x-1] = "." grid[y+1][x] = "." grid[y+1][x+1] = "." grid[y+2][x] = "." if yes: print("YES")
Title: Fox and Cross Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way. Input Specification: The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. Output Specification: Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". Demo Input: ['5\n.#...\n####.\n.####\n...#.\n.....\n', '4\n####\n####\n####\n####\n', '6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n', '6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n', '3\n...\n...\n...\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
```python grid = [] yes = True size = int(input()) for x in range(size): grid.append(list(input())) for y in range(size): if not yes: break for x in range(size): if grid[y][x] == "#": if x == 0 or x == size-1 or y >= size-2: print("NO") yes = False break if grid[y+1][x-1] == "." or grid[y+1][x] == "." or grid[y+1][x+1] == "." or grid[y+2][x] == ".": print("NO") yes = False break else: grid[y+1][x-1] = "." grid[y+1][x] = "." grid[y+1][x+1] = "." grid[y+2][x] = "." if yes: print("YES") ```
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,424,374,258
2,147,483,647
Python 3
OK
TESTS
36
514
19,865,600
input() l = list(map(int, input().split())) l.sort() i = 0 s = 0 while i < len(l) - 1: s += (i+2)*l[i] i += 1 s += (i+1)*l[i] print(s)
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 input() l = list(map(int, input().split())) l.sort() i = 0 s = 0 while i < len(l) - 1: s += (i+2)*l[i] i += 1 s += (i+1)*l[i] print(s) ```
3
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }, { "input": "2\n8 2", "output": "1 1" }, { "input": "3\n6 8 4", "output": "1 2" }, { "input": "4\n4 3 2 8", "output": "3 1" }, { "input": "5\n1 9 8 2 7", "output": "2 3" }, { "input": "6\n1 4 7 3 2 1", "output": "3 3" }, { "input": "11\n7 9 1 8 7 1 7 1 4 8 1", "output": "4 7" }, { "input": "12\n4 2 7 1 9 5 6 2 7 8 5 7", "output": "7 5" }, { "input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9", "output": "7 6" } ]
1,614,786,943
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
307,200
# import sys n = int(sys.stdin.readline()) choc_ls = [int(i.strip()) for i in sys.stdin.readline().rstrip().split()] sum_choc = sum(choc_ls) a_choc_t = a = b_choc_t = b = 0 for i in choc_ls: a_choc_t += i a += 1 if a_choc_t > 1 / 2 * sum_choc: a_choc_t -= i a -= 1 break elif a_choc_t == 1 / 2 * sum_choc: b_choc_t = a_choc_t break if a_choc_t == b_choc_t: print(a, n - a) else: for i in range(n): b_choc_t += choc_ls[n - 1 - i] b += 1 if b_choc_t > 1 / 2 * sum_choc: b_choc_t -= choc_ls[n - 1 - i] b -= 1 break if a_choc_t <= b_choc_t: print(a + 1, b) else: print(a, b + 1)
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). Output Specification: Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. Demo Input: ['5\n2 9 8 2 7\n'] Demo Output: ['2 3\n'] Note: none
```python # import sys n = int(sys.stdin.readline()) choc_ls = [int(i.strip()) for i in sys.stdin.readline().rstrip().split()] sum_choc = sum(choc_ls) a_choc_t = a = b_choc_t = b = 0 for i in choc_ls: a_choc_t += i a += 1 if a_choc_t > 1 / 2 * sum_choc: a_choc_t -= i a -= 1 break elif a_choc_t == 1 / 2 * sum_choc: b_choc_t = a_choc_t break if a_choc_t == b_choc_t: print(a, n - a) else: for i in range(n): b_choc_t += choc_ls[n - 1 - i] b += 1 if b_choc_t > 1 / 2 * sum_choc: b_choc_t -= choc_ls[n - 1 - i] b -= 1 break if a_choc_t <= b_choc_t: print(a + 1, b) else: print(a, b + 1) ```
0
197
A
Plate Game
PROGRAMMING
1,600
[ "constructive algorithms", "games", "math" ]
null
null
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well.
A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly.
If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes).
[ "5 5 2\n", "6 7 4\n" ]
[ "First\n", "Second\n" ]
In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses. In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move.
1,000
[ { "input": "5 5 2", "output": "First" }, { "input": "6 7 4", "output": "Second" }, { "input": "100 100 1", "output": "First" }, { "input": "1 1 100", "output": "Second" }, { "input": "13 7 3", "output": "First" }, { "input": "23 7 3", "output": "First" }, { "input": "9 9 2", "output": "First" }, { "input": "13 13 2", "output": "First" }, { "input": "21 21 10", "output": "First" }, { "input": "20 21 10", "output": "First" }, { "input": "20 20 10", "output": "First" }, { "input": "9 13 2", "output": "First" }, { "input": "19 7 3", "output": "First" }, { "input": "19 19 10", "output": "Second" }, { "input": "19 20 10", "output": "Second" }, { "input": "19 21 10", "output": "Second" }, { "input": "1 100 1", "output": "Second" }, { "input": "2 100 1", "output": "First" }, { "input": "3 100 1", "output": "First" }, { "input": "100 100 49", "output": "First" }, { "input": "100 100 50", "output": "First" }, { "input": "100 100 51", "output": "Second" }, { "input": "100 99 50", "output": "Second" }, { "input": "4 10 5", "output": "Second" }, { "input": "8 11 2", "output": "First" }, { "input": "3 12 5", "output": "Second" }, { "input": "14 15 5", "output": "First" }, { "input": "61 2 3", "output": "Second" }, { "input": "82 20 5", "output": "First" }, { "input": "16 80 10", "output": "Second" }, { "input": "2 1 20", "output": "Second" }, { "input": "78 82 5", "output": "First" }, { "input": "8 55 7", "output": "Second" }, { "input": "75 55 43", "output": "Second" }, { "input": "34 43 70", "output": "Second" }, { "input": "86 74 36", "output": "First" }, { "input": "86 74 37", "output": "First" }, { "input": "86 74 38", "output": "Second" }, { "input": "24 70 11", "output": "First" }, { "input": "24 70 12", "output": "First" }, { "input": "24 70 13", "output": "Second" }, { "input": "78 95 38", "output": "First" }, { "input": "78 95 39", "output": "First" }, { "input": "78 95 40", "output": "Second" }, { "input": "88 43 21", "output": "First" }, { "input": "88 43 22", "output": "Second" }, { "input": "88 43 23", "output": "Second" }, { "input": "30 40 14", "output": "First" }, { "input": "30 40 15", "output": "First" }, { "input": "30 40 16", "output": "Second" }, { "input": "2 5 2", "output": "Second" }, { "input": "5 100 3", "output": "Second" }, { "input": "44 58 5", "output": "First" }, { "input": "4 4 6", "output": "Second" }, { "input": "10 20 6", "output": "Second" }, { "input": "100 1 1", "output": "Second" }, { "input": "60 60 1", "output": "First" }, { "input": "100 1 2", "output": "Second" }, { "input": "2 4 2", "output": "Second" }, { "input": "10 90 11", "output": "Second" }, { "input": "20 5 6", "output": "Second" }, { "input": "1 44 2", "output": "Second" }, { "input": "10 5 5", "output": "Second" }, { "input": "5 100 4", "output": "Second" }, { "input": "99 99 50", "output": "Second" }, { "input": "1 100 2", "output": "Second" }, { "input": "100 20 12", "output": "Second" }, { "input": "10 2 4", "output": "Second" }, { "input": "1 50 2", "output": "Second" }, { "input": "10 4 3", "output": "Second" }, { "input": "74 1 1", "output": "Second" }, { "input": "6 6 1", "output": "First" }, { "input": "10 10 1", "output": "First" }, { "input": "21 41 5", "output": "First" }, { "input": "13 1 2", "output": "Second" }, { "input": "1 100 3", "output": "Second" }, { "input": "1 64 2", "output": "Second" }, { "input": "3 4 1", "output": "First" }, { "input": "15 15 1", "output": "First" }, { "input": "15 16 1", "output": "First" }, { "input": "16 15 1", "output": "First" }, { "input": "16 16 1", "output": "First" }, { "input": "15 15 2", "output": "First" }, { "input": "15 16 2", "output": "First" }, { "input": "16 15 2", "output": "First" }, { "input": "16 16 2", "output": "First" }, { "input": "15 15 3", "output": "First" }, { "input": "15 16 3", "output": "First" }, { "input": "16 15 3", "output": "First" }, { "input": "16 16 3", "output": "First" }, { "input": "15 17 3", "output": "First" }, { "input": "16 17 3", "output": "First" }, { "input": "17 17 3", "output": "First" }, { "input": "17 15 3", "output": "First" }, { "input": "17 16 3", "output": "First" } ]
1,689,420,265
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1689420265.1456444")# 1689420265.1456645
Title: Plate Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well. Input Specification: A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly. Output Specification: If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). Demo Input: ['5 5 2\n', '6 7 4\n'] Demo Output: ['First\n', 'Second\n'] Note: In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses. In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move.
```python print("_RANDOM_GUESS_1689420265.1456444")# 1689420265.1456645 ```
0
722
C
Destroying Array
PROGRAMMING
1,600
[ "data structures", "dsu" ]
null
null
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements.
Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed.
[ "4\n1 3 2 5\n3 4 1 2\n", "5\n1 2 3 4 5\n4 2 3 5 1\n", "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n" ]
[ "5\n4\n3\n0\n", "6\n5\n5\n1\n0\n", "18\n16\n11\n8\n8\n6\n6\n0\n" ]
Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.
1,000
[ { "input": "4\n1 3 2 5\n3 4 1 2", "output": "5\n4\n3\n0" }, { "input": "5\n1 2 3 4 5\n4 2 3 5 1", "output": "6\n5\n5\n1\n0" }, { "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6", "output": "18\n16\n11\n8\n8\n6\n6\n0" }, { "input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8", "output": "34\n29\n14\n11\n11\n11\n8\n3\n1\n0" }, { "input": "17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4", "output": "94\n78\n78\n77\n39\n39\n21\n21\n21\n21\n21\n21\n21\n9\n9\n5\n0" }, { "input": "17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 0 2\n9 13 15 14 16 17 11 10 12 4 6 5 7 8 2 3 1", "output": "65\n64\n64\n64\n64\n64\n64\n64\n64\n46\n31\n31\n16\n16\n9\n1\n0" }, { "input": "17\n10 10 3 9 8 0 10 13 11 8 11 1 6 9 2 10 5\n9 4 13 2 6 15 11 5 16 10 7 3 14 1 12 8 17", "output": "63\n52\n31\n31\n26\n23\n23\n23\n23\n23\n13\n13\n13\n13\n13\n5\n0" }, { "input": "10\n10 4 9 0 7 5 10 3 10 9\n5 2 8 1 3 9 6 10 4 7", "output": "37\n37\n19\n19\n19\n15\n10\n10\n10\n0" }, { "input": "10\n3 10 9 2 6 8 4 4 1 9\n5 8 6 7 9 10 2 1 3 4", "output": "26\n24\n24\n24\n24\n24\n11\n11\n2\n0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 2 3 4 5 6 7", "output": "6000000000\n5000000000\n4000000000\n3000000000\n2000000000\n1000000000\n0" } ]
1,607,546,095
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
// ================================ c++ ==================================================== # include <bits/stdc++.h> using namespace std; # define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // ================================= TYPEDEF MACROS ========================================== typedef long long ll; # define vii vector<int> # define vll vector<long long int> # define vcc vector<char> # define vvi vector<vector<int>> # define vvl vector<vector<long long int>> # define vvc vector<vector<char>> # define pii pair<int,int> # define pll pair<long long int, long long int> # define sii set<int> # define sll set<long long int> # define scc set<char> # define usii unordered_set<int> # define usll unordered_set<long long int> # define uscc unordered_set<char> # define mii map<int,int> # define mll map<long long int,long long int> # define mci map<char,int> # define mcl map<char,long long> # define umii unordered_map<int,int> # define umll unordered_map<long long int,long long int> # define umci unordered_map<char,int> # define umcl unordered_map<char,long long> // ================================ MACROS ======================================= // Range based for loops # define forr(i,a,b) for(long long i=a;i<b;i++) # define fors(p,s) for(auto p=s.begin();p!=s.end();p++) # define form(p,m) for(auto p=m.begin();p!=m.end();p++) # define print(x) cout<<(x)<<"\n" # define P0(x) cout<<(x)<<' ' # define P1(x) cout<<(x)<<"\n" # define P2(x,y) cout<<(x)<<' '<<(y)<<' '<<"\n" # define P3(x,y,z) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<"\n" # define P4(x,y,z,w) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<(w)<<' '<<"\n" # define endl "\n" # define el cout<<"\n" # define F first // valid for pairs and 'auto x:maps' # define S second // valid for pairs and 'auto x:maps' # define B begin() // valid for vectors, sets and strings # define E end() // valid for vectors, sets and strings # define all(v) v.begin(),v.end() // valid for vectors, sets and strings # define len(x) (long long)(x.size()) # define lst(x) (long long)(x.back()) // valid for vectors # define pb push_back # define pop pop_back # define append push_back # define mp make_pair # define add insert # define remove erase # define lb lower_bound # define ub upper_bound # define er equal_range // redefine min, max for (int,long long int) calculations // # define min(a, b) (a > b) ? (b) : (a) // # define max(a, b) (a > b) ? (a) : (b) // array operations (=> valid for strings, vectors, sets) // pointer based # define maxe(args) *max_element(args) # define mine(args) *min_element(args) # define acc(args) accumulate(args,0LL) // python based # define maxp(a) *max_element(a.begin(),a.end()) // maxp => maxpython # define minp(a) *min_element(a.begin(),a.end()) // minp => minpython # define sump(a) accumulate(a.begin(),a.end(),0LL) // sump => sumpython // always use count method as replacement for 'x in a' in maps and sets // a.count(x) //=============================== DEBUG TOOLS ====================================== # define printa(a,n) for(int idnphq=0;idnphq<(n);idnphq++) cout << a[idnphq] << " ";cout << "\n"; // only for debugging (of arrays) thus int // auto notation avoided here to cuz I keep forgetting how iterators for maps work // # define printv(v) for(auto idnphq=v.begin();idnphq!=v.end();idnphq++) cout<< *idnphq << ' ';cout << "\n"; // only for debugging (of vectors) // # define prints(s) for(auto idnphq=s.begin();idnphq!=s.end();idnphq++) cout<< *idnphq << ' ';cout << "\n"; // only for debugging (of sets) // # define printm(m) for(auto idnphq=m.begin();idnphq!=m.end();idnphq++) cout<< idnphq->first << ':' << idnphq->second << ' ';cout << "\n"; // only for debugging (of maps) // using auto in for # define printv(v) {auto kjhg = v;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";} # define printvv(v) {auto kjhg = v;for(auto idnphq : kjhg) {for(auto plinrw : idnphq) cout<< plinrw << ' ';cout << "\n";}} # define prints(s) {auto kjhg = s;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";} # define printm(m) {auto kjhg = m;for(auto idnphq : kjhg) cout<< idnphq.first << ':' << idnphq.second << ' ';cout << "\n";} // =============================== UTILITY FUNCTIONS =============================================== // sii done; // vector<vii> adj; // vii parent; // void dfs(int node){ // // perform operation on node // done.add(node); // for(int neighbour:adj[node]){ // if(done.count(neighbour)) continue; // else{ // parent[neighbour]=node; // dfs(neighbour); // this 'neighbour' is a child of 'node' // } // } // return; // } // =============================== FUNCTIONS ======================================================== // [LOAD SNIPPETS] int hcf(int a,int b){if(!a) return(b);else return(hcf(b%a,a));} int lcm(int a,int b){return((a*b)/hcf(a,b));} # define lif(a,b) (((a)%(b))?(((a)/(b))+1):((a)/(b))) // ================================ ENTRY POINT ============================================================ // Constants # define INF LLONG_MAX # define mod 100000000 # define MN 200005 # define int ll int32_t main() { fastio; int n; cin>>n; vii a(n); forr(i,0,n) cin>>a[i]; vii pint={0}; forr(i,0,n) pint.pb(pint[len(pint)-1]+a[i]); sii intervals; intervals.add(0); intervals.add(n); multiset<int> sums; sums.add(pint[n]-pint[0]); forr(i,0,n){ int p; cin>>p; p--; auto it=intervals.lower_bound(p); auto nxt=it; nxt++; if(!(*it<=p && p<*nxt)){ it--; nxt--; } assert(*it<=p && p<*nxt); pii old={*it,*nxt}; pii new1={*it,p}; pii new2={p+1,*nxt}; intervals.remove(old.F); intervals.remove(old.S); if(new1.F<new1.S){ intervals.add(new1.F); intervals.add(new1.S); } if(new2.F<new2.S){ intervals.add(new2.F); intervals.add(new2.S); } sums.remove(pint[old.S]-pint[old.F]); sums.add(pint[new1.S]-pint[new1.F]); sums.add(pint[new2.S]-pint[new2.F]); print(*(--sums.E)); } return 0; }
Title: Destroying Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. Output Specification: Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. Demo Input: ['4\n1 3 2 5\n3 4 1 2\n', '5\n1 2 3 4 5\n4 2 3 5 1\n', '8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n'] Demo Output: ['5\n4\n3\n0\n', '6\n5\n5\n1\n0\n', '18\n16\n11\n8\n8\n6\n6\n0\n'] Note: Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.
```python // ================================ c++ ==================================================== # include <bits/stdc++.h> using namespace std; # define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // ================================= TYPEDEF MACROS ========================================== typedef long long ll; # define vii vector<int> # define vll vector<long long int> # define vcc vector<char> # define vvi vector<vector<int>> # define vvl vector<vector<long long int>> # define vvc vector<vector<char>> # define pii pair<int,int> # define pll pair<long long int, long long int> # define sii set<int> # define sll set<long long int> # define scc set<char> # define usii unordered_set<int> # define usll unordered_set<long long int> # define uscc unordered_set<char> # define mii map<int,int> # define mll map<long long int,long long int> # define mci map<char,int> # define mcl map<char,long long> # define umii unordered_map<int,int> # define umll unordered_map<long long int,long long int> # define umci unordered_map<char,int> # define umcl unordered_map<char,long long> // ================================ MACROS ======================================= // Range based for loops # define forr(i,a,b) for(long long i=a;i<b;i++) # define fors(p,s) for(auto p=s.begin();p!=s.end();p++) # define form(p,m) for(auto p=m.begin();p!=m.end();p++) # define print(x) cout<<(x)<<"\n" # define P0(x) cout<<(x)<<' ' # define P1(x) cout<<(x)<<"\n" # define P2(x,y) cout<<(x)<<' '<<(y)<<' '<<"\n" # define P3(x,y,z) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<"\n" # define P4(x,y,z,w) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<(w)<<' '<<"\n" # define endl "\n" # define el cout<<"\n" # define F first // valid for pairs and 'auto x:maps' # define S second // valid for pairs and 'auto x:maps' # define B begin() // valid for vectors, sets and strings # define E end() // valid for vectors, sets and strings # define all(v) v.begin(),v.end() // valid for vectors, sets and strings # define len(x) (long long)(x.size()) # define lst(x) (long long)(x.back()) // valid for vectors # define pb push_back # define pop pop_back # define append push_back # define mp make_pair # define add insert # define remove erase # define lb lower_bound # define ub upper_bound # define er equal_range // redefine min, max for (int,long long int) calculations // # define min(a, b) (a > b) ? (b) : (a) // # define max(a, b) (a > b) ? (a) : (b) // array operations (=> valid for strings, vectors, sets) // pointer based # define maxe(args) *max_element(args) # define mine(args) *min_element(args) # define acc(args) accumulate(args,0LL) // python based # define maxp(a) *max_element(a.begin(),a.end()) // maxp => maxpython # define minp(a) *min_element(a.begin(),a.end()) // minp => minpython # define sump(a) accumulate(a.begin(),a.end(),0LL) // sump => sumpython // always use count method as replacement for 'x in a' in maps and sets // a.count(x) //=============================== DEBUG TOOLS ====================================== # define printa(a,n) for(int idnphq=0;idnphq<(n);idnphq++) cout << a[idnphq] << " ";cout << "\n"; // only for debugging (of arrays) thus int // auto notation avoided here to cuz I keep forgetting how iterators for maps work // # define printv(v) for(auto idnphq=v.begin();idnphq!=v.end();idnphq++) cout<< *idnphq << ' ';cout << "\n"; // only for debugging (of vectors) // # define prints(s) for(auto idnphq=s.begin();idnphq!=s.end();idnphq++) cout<< *idnphq << ' ';cout << "\n"; // only for debugging (of sets) // # define printm(m) for(auto idnphq=m.begin();idnphq!=m.end();idnphq++) cout<< idnphq->first << ':' << idnphq->second << ' ';cout << "\n"; // only for debugging (of maps) // using auto in for # define printv(v) {auto kjhg = v;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";} # define printvv(v) {auto kjhg = v;for(auto idnphq : kjhg) {for(auto plinrw : idnphq) cout<< plinrw << ' ';cout << "\n";}} # define prints(s) {auto kjhg = s;for(auto idnphq : kjhg) cout<< idnphq << ' ';cout << "\n";} # define printm(m) {auto kjhg = m;for(auto idnphq : kjhg) cout<< idnphq.first << ':' << idnphq.second << ' ';cout << "\n";} // =============================== UTILITY FUNCTIONS =============================================== // sii done; // vector<vii> adj; // vii parent; // void dfs(int node){ // // perform operation on node // done.add(node); // for(int neighbour:adj[node]){ // if(done.count(neighbour)) continue; // else{ // parent[neighbour]=node; // dfs(neighbour); // this 'neighbour' is a child of 'node' // } // } // return; // } // =============================== FUNCTIONS ======================================================== // [LOAD SNIPPETS] int hcf(int a,int b){if(!a) return(b);else return(hcf(b%a,a));} int lcm(int a,int b){return((a*b)/hcf(a,b));} # define lif(a,b) (((a)%(b))?(((a)/(b))+1):((a)/(b))) // ================================ ENTRY POINT ============================================================ // Constants # define INF LLONG_MAX # define mod 100000000 # define MN 200005 # define int ll int32_t main() { fastio; int n; cin>>n; vii a(n); forr(i,0,n) cin>>a[i]; vii pint={0}; forr(i,0,n) pint.pb(pint[len(pint)-1]+a[i]); sii intervals; intervals.add(0); intervals.add(n); multiset<int> sums; sums.add(pint[n]-pint[0]); forr(i,0,n){ int p; cin>>p; p--; auto it=intervals.lower_bound(p); auto nxt=it; nxt++; if(!(*it<=p && p<*nxt)){ it--; nxt--; } assert(*it<=p && p<*nxt); pii old={*it,*nxt}; pii new1={*it,p}; pii new2={p+1,*nxt}; intervals.remove(old.F); intervals.remove(old.S); if(new1.F<new1.S){ intervals.add(new1.F); intervals.add(new1.S); } if(new2.F<new2.S){ intervals.add(new2.F); intervals.add(new2.S); } sums.remove(pint[old.S]-pint[old.F]); sums.add(pint[new1.S]-pint[new1.F]); sums.add(pint[new2.S]-pint[new2.F]); print(*(--sums.E)); } return 0; } ```
-1
939
A
Love Triangle
PROGRAMMING
800
[ "graphs" ]
null
null
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case.
[ "5\n2 4 5 1 3\n", "5\n5 5 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
500
[ { "input": "5\n2 4 5 1 3", "output": "YES" }, { "input": "5\n5 5 5 5 1", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "10\n4 10 9 5 3 1 5 10 6 4", "output": "NO" }, { "input": "10\n5 5 4 9 10 9 9 5 3 1", "output": "YES" }, { "input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43", "output": "NO" }, { "input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50", "output": "YES" }, { "input": "2\n2 1", "output": "NO" }, { "input": "3\n2 3 1", "output": "YES" }, { "input": "5\n2 1 4 5 3", "output": "YES" }, { "input": "5\n5 4 5 5 2", "output": "YES" } ]
1,696,351,854
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
print("893")
Title: Love Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. Output Specification: Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case. Demo Input: ['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
```python print("893") ```
0
893
B
Beautiful Divisors
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it!
The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got.
Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.
[ "3\n", "992\n" ]
[ "1\n", "496\n" ]
none
0
[ { "input": "3", "output": "1" }, { "input": "992", "output": "496" }, { "input": "81142", "output": "1" }, { "input": "76920", "output": "120" }, { "input": "2016", "output": "2016" }, { "input": "1", "output": "1" }, { "input": "6", "output": "6" }, { "input": "32640", "output": "32640" }, { "input": "12096", "output": "2016" }, { "input": "55948", "output": "1" }, { "input": "47262", "output": "6" }, { "input": "22876", "output": "28" }, { "input": "96120", "output": "120" }, { "input": "42160", "output": "496" }, { "input": "38304", "output": "2016" }, { "input": "89408", "output": "8128" }, { "input": "97920", "output": "32640" }, { "input": "55493", "output": "1" }, { "input": "38021", "output": "1" }, { "input": "21445", "output": "1" }, { "input": "100000", "output": "1" }, { "input": "497", "output": "1" }, { "input": "240", "output": "120" }, { "input": "21204", "output": "6" }, { "input": "65536", "output": "1" }, { "input": "364", "output": "28" }, { "input": "1024", "output": "1" }, { "input": "36", "output": "6" }, { "input": "28", "output": "28" }, { "input": "14400", "output": "120" }, { "input": "10080", "output": "2016" }, { "input": "9", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "6" }, { "input": "83160", "output": "120" }, { "input": "65534", "output": "1" }, { "input": "1026", "output": "6" }, { "input": "1025", "output": "1" }, { "input": "1027", "output": "1" }, { "input": "2018", "output": "1" }, { "input": "2020", "output": "1" }, { "input": "123", "output": "1" }, { "input": "150", "output": "6" }, { "input": "5", "output": "1" }, { "input": "66", "output": "6" }, { "input": "12768", "output": "28" }, { "input": "156", "output": "6" }, { "input": "99990", "output": "6" }, { "input": "248", "output": "1" } ]
1,667,567,376
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
values=[((pow(2,k)-1)*pow(2,k-1)) for k in range(8)] values=values[1:] n=int(input()) s=[] for i in values: if n%int(i)==0: s.append(int(i)) print(max(s))
Title: Beautiful Divisors Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it! Input Specification: The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. Output Specification: Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. Demo Input: ['3\n', '992\n'] Demo Output: ['1\n', '496\n'] Note: none
```python values=[((pow(2,k)-1)*pow(2,k-1)) for k in range(8)] values=values[1:] n=int(input()) s=[] for i in values: if n%int(i)==0: s.append(int(i)) print(max(s)) ```
0
862
B
Mahmoud and Ehab and the bipartiteness
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "trees" ]
null
null
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
[ "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n" ]
[ "0\n", "2\n" ]
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
1,000
[ { "input": "3\n1 2\n1 3", "output": "0" }, { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "2" }, { "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "output": "16" }, { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "output": "16" }, { "input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8", "output": "16" }, { "input": "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9", "output": "0" }, { "input": "2\n1 2", "output": "0" } ]
1,680,928,043
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
from collections import defaultdict def dfs(node, color, graph, visited): visited[node] = True for neighbor in graph[node]: if not visited[neighbor]: graph[neighbor].remove(node) dfs(neighbor, 3-color, graph, visited) n = int(input()) graph = defaultdict(list) for _ in range(n-1): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) visited = [False] * (n+1) dfs(1, 1, graph, visited) num_color1 = visited.count(True) num_color2 = n - num_color1 ans = num_color1 * num_color2 - (n-1) print(ans)
Title: Mahmoud and Ehab and the bipartiteness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . Input Specification: The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. Output Specification: Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. Demo Input: ['3\n1 2\n1 3\n', '5\n1 2\n2 3\n3 4\n4 5\n'] Demo Output: ['0\n', '2\n'] Note: Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
```python from collections import defaultdict def dfs(node, color, graph, visited): visited[node] = True for neighbor in graph[node]: if not visited[neighbor]: graph[neighbor].remove(node) dfs(neighbor, 3-color, graph, visited) n = int(input()) graph = defaultdict(list) for _ in range(n-1): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) visited = [False] * (n+1) dfs(1, 1, graph, visited) num_color1 = visited.count(True) num_color2 = n - num_color1 ans = num_color1 * num_color2 - (n-1) print(ans) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,672,478,536
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
s = input() if len(s) > 10: n = s[1:-1] print(s[0] + str(len(n)) + s[-1]) else: print(s)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python s = input() if len(s) > 10: n = s[1:-1] print(s[0] + str(len(n)) + s[-1]) else: print(s) ```
0
631
B
Print Check
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing. Printer works with a rectangular sheet of paper of size *n*<=×<=*m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0. Your program has to support two operations: 1. Paint all cells in row *r**i* in color *a**i*; 1. Paint all cells in column *c**i* in color *a**i*. If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*. Your program has to print the resulting table after *k* operation.
The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively. Each of the next *k* lines contains the description of exactly one query: - 1 *r**i* *a**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=109), means that row *r**i* is painted in color *a**i*; - 2 *c**i* *a**i* (1<=≤<=*c**i*<=≤<=*m*, 1<=≤<=*a**i*<=≤<=109), means that column *c**i* is painted in color *a**i*.
Print *n* lines containing *m* integers each — the resulting table after all operations are applied.
[ "3 3 3\n1 1 3\n2 2 1\n1 2 2\n", "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n" ]
[ "3 1 3 \n2 2 2 \n0 1 0 \n", "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n" ]
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
1,000
[ { "input": "3 3 3\n1 1 3\n2 2 1\n1 2 2", "output": "3 1 3 \n2 2 2 \n0 1 0 " }, { "input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1", "output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 " }, { "input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1", "output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 " }, { "input": "4 6 8\n1 2 1\n2 2 2\n2 5 2\n1 1 1\n1 4 1\n1 3 2\n2 1 1\n2 6 1", "output": "1 1 1 1 1 1 \n1 2 1 1 2 1 \n1 2 2 2 2 1 \n1 1 1 1 1 1 " }, { "input": "2 2 3\n1 1 1\n1 2 1\n2 1 2", "output": "2 1 \n2 1 " }, { "input": "1 2 4\n1 1 1\n2 1 2\n2 2 3\n1 1 4", "output": "4 4 " }, { "input": "2 1 5\n1 1 7\n1 2 77\n2 1 777\n1 1 77\n1 2 7", "output": "77 \n7 " }, { "input": "2 1 1\n1 2 1000000000", "output": "0 \n1000000000 " }, { "input": "1 2 1\n2 2 1000000000", "output": "0 1000000000 " }, { "input": "160 600 1\n1 132 589472344", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "600 160 1\n1 124 542622711", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "10 1 1\n2 1 1000000000", "output": "1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 " }, { "input": "1 10 1\n1 1 1000000000", "output": "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 " }, { "input": "5000 20 15\n2 13 447246914\n2 10 89345638\n2 6 393683717\n2 1 62225152\n2 12 990340161\n2 4 227462932\n1 4011 327145900\n1 1915 981331082\n1 802 437883065\n2 11 205232924\n2 15 303578182\n1 2667 835309719\n2 3 550440583\n1 3852 766318960\n2 5 204700467", "output": "62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 ..." }, { "input": "20 5000 15\n1 14 94104058\n1 3 170575572\n1 12 613859505\n2 4797 363375206\n1 10 554079405\n2 4481 223609505\n2 4974 385117513\n1 7 363246561\n2 2503 128936152\n1 2 152944073\n1 14 25797327\n1 20 258831369\n1 10 453164078\n2 2159 753235825\n2 1823 827844660", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "1 1 1\n1 1 1", "output": "1 " }, { "input": "1 1 1\n1 1 1000000000", "output": "1000000000 " }, { "input": "1 1 2\n1 1 123\n1 1 321", "output": "321 " }, { "input": "1 1 2\n1 1 321\n1 1 123", "output": "123 " } ]
1,697,608,889
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
21
1,000
35,737,600
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) n, m, k = inlt() arr = [[0 for i in range(m)] for j in range(n)] inpts = [] for i in range(k): a, b, c = inlt() inpts.append([a, b, c]) for i in range(k): a, b, c = inpts[i] if a == 1: arr[b - 1] = [c for l in range(m)] else: for j in range(n): arr[j][b - 1] = c for i in arr: print(*i)
Title: Print Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing. Printer works with a rectangular sheet of paper of size *n*<=×<=*m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0. Your program has to support two operations: 1. Paint all cells in row *r**i* in color *a**i*; 1. Paint all cells in column *c**i* in color *a**i*. If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*. Your program has to print the resulting table after *k* operation. Input Specification: The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively. Each of the next *k* lines contains the description of exactly one query: - 1 *r**i* *a**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=109), means that row *r**i* is painted in color *a**i*; - 2 *c**i* *a**i* (1<=≤<=*c**i*<=≤<=*m*, 1<=≤<=*a**i*<=≤<=109), means that column *c**i* is painted in color *a**i*. Output Specification: Print *n* lines containing *m* integers each — the resulting table after all operations are applied. Demo Input: ['3 3 3\n1 1 3\n2 2 1\n1 2 2\n', '5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n'] Demo Output: ['3 1 3 \n2 2 2 \n0 1 0 \n', '1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n'] Note: The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
```python import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) n, m, k = inlt() arr = [[0 for i in range(m)] for j in range(n)] inpts = [] for i in range(k): a, b, c = inlt() inpts.append([a, b, c]) for i in range(k): a, b, c = inpts[i] if a == 1: arr[b - 1] = [c for l in range(m)] else: for j in range(n): arr[j][b - 1] = c for i in arr: print(*i) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,689,687,301
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int (input()) l = [] for i in range(n): s = str(input()) if len(s)>10: x = str(len(s)-2) y = s[0]+x+s[-1] l.append(y) else: l.append(s) for t in l: print(t)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n = int (input()) l = [] for i in range(n): s = str(input()) if len(s)>10: x = str(len(s)-2) y = s[0]+x+s[-1] l.append(y) else: l.append(s) for t in l: print(t) ```
3.977
441
A
Valera and Antique Items
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
[ "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n" ]
[ "3\n1 2 3\n", "0\n\n" ]
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
500
[ { "input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3" }, { "input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0" }, { "input": "2 100001\n1 895737\n1 541571", "output": "0" }, { "input": "1 1000000\n1 1000000", "output": "0" }, { "input": "1 1000000\n1 561774", "output": "1\n1" }, { "input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "2\n1 2" }, { "input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000", "output": "0" }, { "input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236", "output": "3\n1 2 3" }, { "input": "1 50001\n1 50000", "output": "1\n1" } ]
1,644,048,841
2,147,483,647
PyPy 3
OK
TESTS
26
93
1,536,000
n, v = map(int, input().split()) ans = [] for i in range(n): tmp = list(map(int, input().split())) if min(tmp[1:]) + 1 <= v: ans.append(i + 1) print(len(ans)) print(*ans)
Title: Valera and Antique Items Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with. Input Specification: The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller. Output Specification: In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. Demo Input: ['3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n', '3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n'] Demo Output: ['3\n1 2 3\n', '0\n\n'] Note: In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
```python n, v = map(int, input().split()) ans = [] for i in range(n): tmp = list(map(int, input().split())) if min(tmp[1:]) + 1 <= v: ans.append(i + 1) print(len(ans)) print(*ans) ```
3
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { "input": "0 0 0 0\n4132", "output": "0" }, { "input": "3163 5778 83 7640\n11141442444", "output": "64270" }, { "input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "output": "420780" }, { "input": "0 0 0 0\n1", "output": "0" }, { "input": "1 2 3 4\n4", "output": "4" }, { "input": "2343 7653 1242 5432\n1", "output": "2343" }, { "input": "2343 7653 1242 5432\n2", "output": "7653" }, { "input": "2343 7653 1242 5432\n3", "output": "1242" }, { "input": "2343 7653 1242 5432\n4", "output": "5432" }, { "input": "1 2 3 4\n123412", "output": "13" }, { "input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111", "output": "2650" }, { "input": "1 2 3 4\n11111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "1 2 3 4\n23123231321231231231231231221232123121312321", "output": "87" }, { "input": "1 2 3 4\n1111111111111222222222233333333333444444444444444", "output": "126" }, { "input": "2 3 1 4\n121321232412342112312313213123123412131231231232", "output": "105" } ]
1,660,864,278
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
#!/usr/bin/env python3 # coding:utf-8 if __name__ == "__main__": a = [int(item) for item in input().split()] s = input() t = 0 for i in s: t += a[int(i)] print(t)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python #!/usr/bin/env python3 # coding:utf-8 if __name__ == "__main__": a = [int(item) for item in input().split()] s = input() t = 0 for i in s: t += a[int(i)] print(t) ```
-1
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "input": "9149", "output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..." }, { "input": "2877", "output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..." }, { "input": "2956", "output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..." }, { "input": "3035", "output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..." }, { "input": "3114", "output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..." }, { "input": "3193", "output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..." }, { "input": "3273", "output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..." }, { "input": "7000", "output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..." }, { "input": "7079", "output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..." }, { "input": "4653", "output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..." }, { "input": "9995", "output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..." }, { "input": "9996", "output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..." }, { "input": "9997", "output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..." }, { "input": "9998", "output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..." }, { "input": "9999", "output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..." }, { "input": "10000", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..." } ]
1,688,015,143
2,147,483,647
PyPy 3-64
OK
TESTS
22
154
4,300,800
import sys input = sys.stdin.readline n = int(input()) d = n - 1 ans = [1] v = [0] * (n + 1) for i in range(n - 1): if(ans[-1] + d <= n and not v[ans[-1] + d]): ans.append(ans[-1] + d) v[ans[-1]] = 1 else: ans.append(ans[-1] - d) v[ans[-1]] = 1 d -= 1 print(*ans)
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. Input Specification: The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. Output Specification: Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any. Demo Input: ['2\n', '3\n'] Demo Output: ['1 2 ', '1 3 2 '] Note: none
```python import sys input = sys.stdin.readline n = int(input()) d = n - 1 ans = [1] v = [0] * (n + 1) for i in range(n - 1): if(ans[-1] + d <= n and not v[ans[-1] + d]): ans.append(ans[-1] + d) v[ans[-1]] = 1 else: ans.append(ans[-1] - d) v[ans[-1]] = 1 d -= 1 print(*ans) ```
3.953489
363
A
Soroban
PROGRAMMING
800
[ "implementation" ]
null
null
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: - Set the value of a digit equal to 0. - If the go-dama is shifted to the right, add 5. - Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720. Write the program that prints the way Soroban shows the given number *n*.
The first line contains a single integer *n* (0<=≤<=*n*<=&lt;<=109).
Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number *n* without leading zeroes. We can assume that number 0 has no leading zeroes.
[ "2\n", "13\n", "720\n" ]
[ "O-|OO-OO\n", "O-|OOO-O\nO-|O-OOO\n", "O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n" ]
none
500
[ { "input": "2", "output": "O-|OO-OO" }, { "input": "13", "output": "O-|OOO-O\nO-|O-OOO" }, { "input": "720", "output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO" }, { "input": "0", "output": "O-|-OOOO" }, { "input": "1", "output": "O-|O-OOO" }, { "input": "3", "output": "O-|OOO-O" }, { "input": "4", "output": "O-|OOOO-" }, { "input": "5", "output": "-O|-OOOO" }, { "input": "6", "output": "-O|O-OOO" }, { "input": "637", "output": "-O|OO-OO\nO-|OOO-O\n-O|O-OOO" }, { "input": "7", "output": "-O|OO-OO" }, { "input": "8", "output": "-O|OOO-O" }, { "input": "9", "output": "-O|OOOO-" }, { "input": "10", "output": "O-|-OOOO\nO-|O-OOO" }, { "input": "11", "output": "O-|O-OOO\nO-|O-OOO" }, { "input": "100", "output": "O-|-OOOO\nO-|-OOOO\nO-|O-OOO" }, { "input": "99", "output": "-O|OOOO-\n-O|OOOO-" }, { "input": "245", "output": "-O|-OOOO\nO-|OOOO-\nO-|OO-OO" }, { "input": "118", "output": "-O|OOO-O\nO-|O-OOO\nO-|O-OOO" }, { "input": "429", "output": "-O|OOOO-\nO-|OO-OO\nO-|OOOO-" }, { "input": "555", "output": "-O|-OOOO\n-O|-OOOO\n-O|-OOOO" }, { "input": "660", "output": "O-|-OOOO\n-O|O-OOO\n-O|O-OOO" }, { "input": "331", "output": "O-|O-OOO\nO-|OOO-O\nO-|OOO-O" }, { "input": "987", "output": "-O|OO-OO\n-O|OOO-O\n-O|OOOO-" }, { "input": "123456789", "output": "-O|OOOO-\n-O|OOO-O\n-O|OO-OO\n-O|O-OOO\n-O|-OOOO\nO-|OOOO-\nO-|OOO-O\nO-|OO-OO\nO-|O-OOO" }, { "input": "234567890", "output": "O-|-OOOO\n-O|OOOO-\n-O|OOO-O\n-O|OO-OO\n-O|O-OOO\n-O|-OOOO\nO-|OOOO-\nO-|OOO-O\nO-|OO-OO" }, { "input": "100000000", "output": "O-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO" }, { "input": "111111111", "output": "O-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO" }, { "input": "90909090", "output": "O-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-" }, { "input": "987654321", "output": "O-|O-OOO\nO-|OO-OO\nO-|OOO-O\nO-|OOOO-\n-O|-OOOO\n-O|O-OOO\n-O|OO-OO\n-O|OOO-O\n-O|OOOO-" }, { "input": "45165125", "output": "-O|-OOOO\nO-|OO-OO\nO-|O-OOO\n-O|-OOOO\n-O|O-OOO\nO-|O-OOO\n-O|-OOOO\nO-|OOOO-" }, { "input": "445511006", "output": "-O|O-OOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO\nO-|O-OOO\n-O|-OOOO\n-O|-OOOO\nO-|OOOO-\nO-|OOOO-" }, { "input": "999999999", "output": "-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-" }, { "input": "984218523", "output": "O-|OOO-O\nO-|OO-OO\n-O|-OOOO\n-O|OOO-O\nO-|O-OOO\nO-|OO-OO\nO-|OOOO-\n-O|OOO-O\n-O|OOOO-" }, { "input": "19", "output": "-O|OOOO-\nO-|O-OOO" }, { "input": "10000000", "output": "O-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO" } ]
1,668,432,266
2,147,483,647
Python 3
OK
TESTS
36
46
0
n=input() l=[] def soroban(x): if x==0: return("O-|-OOOO") elif x==1: return("O-|O-OOO") elif x==2: return("O-|OO-OO") elif x==3: return("O-|OOO-O") elif x==4: return("O-|OOOO-") elif x==5: return("-O|-OOOO") elif x==6: return("-O|O-OOO") elif x==7: return("-O|OO-OO") elif x==8: return("-O|OOO-O") else: return("-O|OOOO-") for i in range(len(n)): l.append(soroban(int(n[i]))) l.reverse() for i in l: print(i)
Title: Soroban Time Limit: None seconds Memory Limit: None megabytes Problem Description: You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: - Set the value of a digit equal to 0. - If the go-dama is shifted to the right, add 5. - Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720. Write the program that prints the way Soroban shows the given number *n*. Input Specification: The first line contains a single integer *n* (0<=≤<=*n*<=&lt;<=109). Output Specification: Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number *n* without leading zeroes. We can assume that number 0 has no leading zeroes. Demo Input: ['2\n', '13\n', '720\n'] Demo Output: ['O-|OO-OO\n', 'O-|OOO-O\nO-|O-OOO\n', 'O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n'] Note: none
```python n=input() l=[] def soroban(x): if x==0: return("O-|-OOOO") elif x==1: return("O-|O-OOO") elif x==2: return("O-|OO-OO") elif x==3: return("O-|OOO-O") elif x==4: return("O-|OOOO-") elif x==5: return("-O|-OOOO") elif x==6: return("-O|O-OOO") elif x==7: return("-O|OO-OO") elif x==8: return("-O|OOO-O") else: return("-O|OOOO-") for i in range(len(n)): l.append(soroban(int(n[i]))) l.reverse() for i in l: print(i) ```
3
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,690,969,804
2,147,483,647
Python 3
OK
TESTS
71
92
0
m=0 l=[] n=int(input()) for i in range(n): a,b=list(map(int,input().split())) m+=b-a l.append(m) print(max(l))
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python m=0 l=[] n=int(input()) for i in range(n): a,b=list(map(int,input().split())) m+=b-a l.append(m) print(max(l)) ```
3
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,694,898,857
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
1,536,000
n = int(input()) s = 0 g = 0 for i in range(n): if s == 0: g += -(i+1) s = 1 else: g += i+1 s = 0 print(g)
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python n = int(input()) s = 0 g = 0 for i in range(n): if s == 0: g += -(i+1) s = 1 else: g += i+1 s = 0 print(g) ```
0
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 539 896 668 36 896", "output": "YES" }, { "input": "7\n674 712 674 674 674 674 674", "output": "NO" }, { "input": "8\n742 742 742 742 742 289 742 742", "output": "NO" }, { "input": "9\n730 351 806 806 806 630 85 757 967", "output": "YES" }, { "input": "10\n324 539 83 440 834 640 440 440 440 440", "output": "YES" }, { "input": "7\n925 830 925 98 987 162 356", "output": "YES" }, { "input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808", "output": "YES" }, { "input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94", "output": "YES" }, { "input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402", "output": "NO" }, { "input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187", "output": "YES" }, { "input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103", "output": "YES" }, { "input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925", "output": "NO" }, { "input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353", "output": "YES" }, { "input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285", "output": "NO" }, { "input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99", "output": "YES" }, { "input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26", "output": "YES" }, { "input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516", "output": "YES" }, { "input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314", "output": "NO" }, { "input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800", "output": "NO" }, { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317", "output": "NO" }, { "input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784", "output": "YES" }, { "input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474", "output": "YES" }, { "input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499", "output": "NO" }, { "input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816", "output": "NO" }, { "input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1000", "output": "YES" }, { "input": "12\n2 2 4 4 4 4 6 6 6 6 6 6", "output": "YES" } ]
1,609,133,416
2,147,483,647
PyPy 3
OK
TESTS
37
280
0
n = int(input()) arr = list(map(int, input().strip().split())) dic = {} for x in range(n): if arr[x] not in dic: dic[arr[x]] = 1 else: dic[arr[x]] += 1 r = 0 if n % 2 ==0: r = n // 2 else: r = n // 2 + 1 flag =0 for e in dic: if dic[e] > r: print("NO") flag = 1 if flag == 0: print("YES")
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. Output Specification: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Demo Input: ['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
```python n = int(input()) arr = list(map(int, input().strip().split())) dic = {} for x in range(n): if arr[x] not in dic: dic[arr[x]] = 1 else: dic[arr[x]] += 1 r = 0 if n % 2 ==0: r = n // 2 else: r = n // 2 + 1 flag =0 for e in dic: if dic[e] > r: print("NO") flag = 1 if flag == 0: print("YES") ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,651,338,448
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
y, w = map(int, input().split()) res = (7 - max(y, w)) if res in [1, 5]: print(f'{res}/6') elif res in [2, 4]: print(f'{res//2}/3') elif res == 3: print('1/2') else: print('{res}/1')
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python y, w = map(int, input().split()) res = (7 - max(y, w)) if res in [1, 5]: print(f'{res}/6') elif res in [2, 4]: print(f'{res//2}/3') elif res == 3: print('1/2') else: print('{res}/1') ```
0
0
none
none
none
0
[ "none" ]
null
null
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
[ "helloworld\nehoolwlroz\n", "hastalavistababy\nhastalavistababy\n", "merrychristmas\nchristmasmerry\n" ]
[ "3\nh e\nl o\nd z\n", "0\n", "-1\n" ]
none
0
[ { "input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z" }, { "input": "hastalavistababy\nhastalavistababy", "output": "0" }, { "input": "merrychristmas\nchristmasmerry", "output": "-1" }, { "input": "kusyvdgccw\nkusyvdgccw", "output": "0" }, { "input": "bbbbbabbab\naaaaabaaba", "output": "1\nb a" }, { "input": "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx", "output": "-1" }, { "input": "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc", "output": "1\nd b" }, { "input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd", "output": "0" }, { "input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak", "output": "5\ng f\nn i\nd h\ne o\nb k" }, { "input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc", "output": "0" }, { "input": "ab\naa", "output": "-1" }, { "input": "a\nz", "output": "1\na z" }, { "input": "zz\nzy", "output": "-1" }, { "input": "as\ndf", "output": "2\na d\ns f" }, { "input": "abc\nbca", "output": "-1" }, { "input": "rtfg\nrftg", "output": "1\nt f" }, { "input": "y\ny", "output": "0" }, { "input": "qwertyuiopasdfghjklzx\nzzzzzzzzzzzzzzzzzzzzz", "output": "-1" }, { "input": "qazwsxedcrfvtgbyhnujmik\nqwertyuiasdfghjkzxcvbnm", "output": "-1" }, { "input": "aaaaaa\nabcdef", "output": "-1" }, { "input": "qwerty\nffffff", "output": "-1" }, { "input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh", "output": "0" }, { "input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe", "output": "-1" }, { "input": "bacccbbacabbcaacbbba\nbacccbbacabbcaacbbba", "output": "0" }, { "input": "dbadbddddb\nacbacaaaac", "output": "-1" }, { "input": "dacbdbbbdd\nadbdadddaa", "output": "-1" }, { "input": "bbbbcbcbbc\ndaddbabddb", "output": "-1" }, { "input": "dddddbcdbd\nbcbbbdacdb", "output": "-1" }, { "input": "cbadcbcdaa\nabbbababbb", "output": "-1" }, { "input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk", "output": "-1" }, { "input": "acbbccabaa\nabbbbbabaa", "output": "-1" }, { "input": "ccccaccccc\naaaabaaaac", "output": "-1" }, { "input": "acbacacbbb\nacbacacbbb", "output": "0" }, { "input": "abbababbcc\nccccccccbb", "output": "-1" }, { "input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh", "output": "-1" }, { "input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage", "output": "-1" }, { "input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai", "output": "-1" }, { "input": "z\nz", "output": "0" }, { "input": "a\nz", "output": "1\na z" }, { "input": "z\na", "output": "1\nz a" }, { "input": "aa\nzz", "output": "1\na z" }, { "input": "az\nza", "output": "1\na z" }, { "input": "aa\nza", "output": "-1" }, { "input": "za\nzz", "output": "-1" }, { "input": "aa\nab", "output": "-1" }, { "input": "hehe\nheeh", "output": "-1" }, { "input": "bd\ncc", "output": "-1" }, { "input": "he\nhh", "output": "-1" }, { "input": "hee\nheh", "output": "-1" }, { "input": "aa\nac", "output": "-1" }, { "input": "ab\naa", "output": "-1" }, { "input": "hello\nehlol", "output": "-1" }, { "input": "ac\naa", "output": "-1" }, { "input": "aaabbb\nbbbaab", "output": "-1" }, { "input": "aa\nfa", "output": "-1" }, { "input": "hg\nee", "output": "-1" }, { "input": "helloworld\nehoolwlrow", "output": "-1" }, { "input": "abb\nbab", "output": "-1" }, { "input": "aaa\naae", "output": "-1" }, { "input": "aba\nbaa", "output": "-1" }, { "input": "aa\nba", "output": "-1" }, { "input": "da\naa", "output": "-1" }, { "input": "aaa\naab", "output": "-1" }, { "input": "xy\nzz", "output": "-1" } ]
1,483,390,252
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
41
62
4,608,000
s, t = input(), input() n = len(s) a = [-1]*26 for i in range(0, n): x = s[i] y = t[i] if x != y: a[ord(y) - ord('a')] = ord(x) - ord('a') a[ord(x) - ord('a')] = ord(y) - ord('a') for i in range(0, n): if a[ord(t[i]) - ord('a')] == -1: continue if (ord(s[i]) - ord('a')) != (a[ord(t[i]) - ord('a')]): print(-1) exit() ans = [] for i in range(26): if a[i] != -1 and i < a[i]: c1 = chr(i + ord('a')) c2 = chr(a[i] + ord('a')) ans.append((c1, c2)) print(len(ans)) for x, y in ans: print(x, y)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once. Input Specification: The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. Output Specification: If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes. Demo Input: ['helloworld\nehoolwlroz\n', 'hastalavistababy\nhastalavistababy\n', 'merrychristmas\nchristmasmerry\n'] Demo Output: ['3\nh e\nl o\nd z\n', '0\n', '-1\n'] Note: none
```python s, t = input(), input() n = len(s) a = [-1]*26 for i in range(0, n): x = s[i] y = t[i] if x != y: a[ord(y) - ord('a')] = ord(x) - ord('a') a[ord(x) - ord('a')] = ord(y) - ord('a') for i in range(0, n): if a[ord(t[i]) - ord('a')] == -1: continue if (ord(s[i]) - ord('a')) != (a[ord(t[i]) - ord('a')]): print(-1) exit() ans = [] for i in range(26): if a[i] != -1 and i < a[i]: c1 = chr(i + ord('a')) c2 = chr(a[i] + ord('a')) ans.append((c1, c2)) print(len(ans)) for x, y in ans: print(x, y) ```
0
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, { "input": "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ", "output": "contest" }, { "input": "10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\nPVO->DMN\nDMN->PVO", "output": "home" }, { "input": "11\nIAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU", "output": "contest" }, { "input": "10\nHPN\nDFI->HPN\nHPN->KAB\nHPN->DFI\nVSO->HPN\nHPN->KZX\nHPN->VSO\nKZX->HPN\nLDW->HPN\nKAB->HPN\nHPN->LDW", "output": "home" }, { "input": "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE->FGH\nFGH->KQK\nFGH->QRE\nKQK->FGH\nFGH->UBK\nBRZ->FGH\nFGH->ALX\nALX->FGH\nFGH->KQK", "output": "contest" }, { "input": "50\nPFH\nJFV->PFH\nBVP->PFH\nPFH->BVP\nPFH->JFV\nPFH->ETQ\nPFH->LQJ\nZTO->PFH\nPFH->BVP\nPFH->RXO\nPFH->ZTO\nHWL->PFH\nPFH->HIV\nPFH->AFP\nPFH->HWL\nOBB->PFH\nHIV->PFH\nPFH->LSR\nAFP->PFH\nLQJ->PFH\nHWL->PFH\nETQ->PFH\nPFH->HWL\nLSR->PFH\nWBR->PFH\nBNZ->PFH\nHQR->PFH\nZTO->PFH\nPFH->WBR\nPFH->BYJ\nRXO->PFH\nFHZ->PFH\nFHZ->PFH\nPFN->PFH\nPFH->GMB\nPFH->JFV\nJFV->PFH\nGNZ->PFH\nPFH->BNZ\nPFH->GNZ\nPFH->HQR\nBYJ->PFH\nGMB->PFH\nPFH->FHZ\nPFH->FHZ\nPFH->ZTO\nPFH->UGD\nBVP->PFH\nUGD->PFH\nPFH->PFN\nPFH->OBB", "output": "home" }, { "input": "1\nAAK\nAAK->ABA", "output": "contest" }, { "input": "1\nXYZ\nXYZ->XYR", "output": "contest" } ]
1,579,341,976
2,147,483,647
PyPy 3
OK
TESTS
23
171
0
import sys import math import bisect import itertools def main(): n = int(input()) home = input() nout = 0 nin = 0 for i in range(n): s = input() src = s[0:3] dst = s[5:8] if src == home: nout += 1 if dst == home: nin += 1 if nout == nin: print('home') elif nout == nin + 1: print('contest') if __name__ == "__main__": main()
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location! Input Specification: In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. Output Specification: If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". Demo Input: ['4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n', '3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n'] Demo Output: ['home\n', 'contest\n'] Note: In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
```python import sys import math import bisect import itertools def main(): n = int(input()) home = input() nout = 0 nin = 0 for i in range(n): s = input() src = s[0:3] dst = s[5:8] if src == home: nout += 1 if dst == home: nin += 1 if nout == nin: print('home') elif nout == nin + 1: print('contest') if __name__ == "__main__": main() ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "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,592,395,329
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
78
307,200
a = input() t = list(a) c = 0 for i in range(len(t)): if t[i] == 'l': for j in range(i+1,len(t)): if t[j] == 'l': c = 1 break a = '' for i in range(len(t)): if t[i] not in a: a += t[i] if 'h' in a and 'e' in a and 'o' in a and c == 1: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a = input() t = list(a) c = 0 for i in range(len(t)): if t[i] == 'l': for j in range(i+1,len(t)): if t[j] == 'l': c = 1 break a = '' for i in range(len(t)): if t[i] not in a: a += t[i] if 'h' in a and 'e' in a and 'o' in a and c == 1: print("YES") else: print("NO") ```
0
523
C
Name Quest
PROGRAMMING
1,400
[ "*special", "greedy" ]
null
null
A Martian boy is named *s* — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if *s*=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not. However rather than being happy once, he loves twice as much being happy twice! So, when he got string *t* as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy. Help *s* determine the number of distinct ways to cut the given string *t* into two parts in the required manner.
The first line contains string *s*, consisting of lowercase English letters. The length of string *s* is from 1 to 1000 letters. The second line contains string *t*, that also consists of lowercase English letters. The length of string *t* is from 1 to 106 letters.
Print the sought number of ways to cut string *t* in two so that each part made *s* happy.
[ "aba\nbaobababbah\n", "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n" ]
[ "2\n", "0\n" ]
none
1,500
[ { "input": "aba\nbaobababbah", "output": "2" }, { "input": "mars\nsunvenusearthmarsjupitersaturnuranusneptune", "output": "0" }, { "input": "rry\nsorrymercuryismissedabove", "output": "3" }, { "input": "a\naaaaaaaaaaaaaa", "output": "13" }, { "input": "abcaba\nabcabaabcabaabcabaabcaba", "output": "13" }, { "input": "lol\nlol", "output": "0" }, { "input": "aaaaaaaaaaaa\naaaaaa", "output": "0" }, { "input": "a\na", "output": "0" } ]
1,426,355,245
10,045
Python 3
WRONG_ANSWER
PRETESTS
2
31
0
s=input() a=input() j=0 v=0 for i in range(len(s)): k=s[i] while j<len(a): if a[j]==k: if i==len(s)-1: c=j break else: break j+=1 j=len(a)-1 for i in range(len(s)-1,-1,-1): k=s[i] while j>c: if a[j]==k: if i==0: v=j-c break else: break j-=1 print(v)
Title: Name Quest Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Martian boy is named *s* — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if *s*=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not. However rather than being happy once, he loves twice as much being happy twice! So, when he got string *t* as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy. Help *s* determine the number of distinct ways to cut the given string *t* into two parts in the required manner. Input Specification: The first line contains string *s*, consisting of lowercase English letters. The length of string *s* is from 1 to 1000 letters. The second line contains string *t*, that also consists of lowercase English letters. The length of string *t* is from 1 to 106 letters. Output Specification: Print the sought number of ways to cut string *t* in two so that each part made *s* happy. Demo Input: ['aba\nbaobababbah\n', 'mars\nsunvenusearthmarsjupitersaturnuranusneptune\n'] Demo Output: ['2\n', '0\n'] Note: none
```python s=input() a=input() j=0 v=0 for i in range(len(s)): k=s[i] while j<len(a): if a[j]==k: if i==len(s)-1: c=j break else: break j+=1 j=len(a)-1 for i in range(len(s)-1,-1,-1): k=s[i] while j>c: if a[j]==k: if i==0: v=j-c break else: break j-=1 print(v) ```
0
204
A
Little Elephant and Interval
PROGRAMMING
1,500
[ "binary search", "combinatorics", "dp" ]
null
null
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*.
The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. 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.
On a single line print a single integer — the answer to the problem.
[ "2 47\n", "47 1024\n" ]
[ "12\n", "98\n" ]
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
500
[ { "input": "2 47", "output": "12" }, { "input": "47 1024", "output": "98" }, { "input": "1 1000", "output": "108" }, { "input": "1 10000", "output": "1008" }, { "input": "47 8545", "output": "849" }, { "input": "1000 1000", "output": "0" }, { "input": "47547 4587554587754542", "output": "458755458770699" }, { "input": "1 1000000", "output": "100008" }, { "input": "47 74", "output": "2" }, { "input": "10001 10000002", "output": "999001" }, { "input": "10000 100000", "output": "9000" }, { "input": "458754 4588754", "output": "413001" }, { "input": "111 111", "output": "1" }, { "input": "110 147", "output": "4" }, { "input": "1 1000000000", "output": "100000008" }, { "input": "12 10000000000", "output": "999999998" }, { "input": "1000000000 1000000000", "output": "0" }, { "input": "1 1000000000000000000", "output": "100000000000000008" }, { "input": "11 111111111111111100", "output": "11111111111111109" }, { "input": "100000000000000000 1000000000000000000", "output": "90000000000000000" }, { "input": "45481484484 848469844684844", "output": "84842436320036" }, { "input": "975400104587000 48754000000000001", "output": "4777859989541300" }, { "input": "11220451511 51511665251233335", "output": "5151165403078183" }, { "input": "77 77", "output": "1" }, { "input": "99 102", "output": "2" }, { "input": "9997 87878000008", "output": "8787799002" }, { "input": "10000000001 111111111111100001", "output": "11111110111110001" }, { "input": "7777 88888", "output": "8112" }, { "input": "999999999 10000000000", "output": "900000001" }, { "input": "235 236", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "4 7", "output": "4" }, { "input": "7 10", "output": "3" }, { "input": "1 11", "output": "10" }, { "input": "1 10", "output": "9" }, { "input": "7 8", "output": "2" }, { "input": "88 990", "output": "91" }, { "input": "458985985498001244 985458425544874008", "output": "52647244004687276" }, { "input": "115998725487587451 245744899758754501", "output": "12974617427116705" }, { "input": "595754249475458004 615044544745124547", "output": "1929029526966655" }, { "input": "9754875457700 1000000000000000000", "output": "99999024512454230" }, { "input": "8758754570000 999999999999999999", "output": "99999124124543000" }, { "input": "111111111111111111 333333333444444445", "output": "22222222233333334" }, { "input": "822981258385599125 841978899930248528", "output": "1899764154464941" }, { "input": "779547115376367013 980561039207670775", "output": "20101392383130376" }, { "input": "335408916782916802 416495628489807285", "output": "8108671170689049" }, { "input": "252509053898415172 285803555062529649", "output": "3329450116411448" }, { "input": "919845424847912645 970651082117950285", "output": "5080565727003764" }, { "input": "522842183413115088 853628713003942530", "output": "33078652959082744" }, { "input": "84324827171274023 607953653548585226", "output": "52362882637731121" }, { "input": "1312148742261681 277460340506883334", "output": "27614819176462166" }, { "input": "645762257531682046 885295120956158518", "output": "23953286342447648" }, { "input": "819875140559301752 946247219812473271", "output": "12637207925317152" }, { "input": "4 19", "output": "7" }, { "input": "5 45", "output": "9" }, { "input": "9999999999999987 99999999999999711", "output": "8999999999999973" }, { "input": "2 3", "output": "2" }, { "input": "1827171 232817181719384635", "output": "23281718171755747" }, { "input": "999999999999999999 1000000000000000000", "output": "1" }, { "input": "73 678", "output": "61" } ]
1,552,495,312
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
218
307,200
def size(x): res = 0 while x > 0: x //= 10 res += 1 return res def first(x): last = 0 while x > 0: last = x % 10 x //= 10 return last def last(x): return x % 10 def cut(x): x //= 10 x -= first(x) * 10 ** (size(x) - 1) return x l, r = list(map(int, input().split())) size_l = size(l) size_r = size(r) result = int(0) for i in range(size_l + 1, size_r): result += 9 * 10 ** (i - 2) if size_l != size_r: result += (9 - first(l)) * (10 ** (size_l - min(size_l, 2))) result += 10 ** (size_l - min(size_l, 2)) - cut(l) - 1 if first(l) >= last(l): result += 1 result += (first(r) - 1) * 10 ** (size_r - min(size_r, 2)) result += cut(r) if first(r) <= last(r): result += 1 else: result += (first(r) - first(l) - 1) * 10 ** (size_r - min(size_r, 2)) if first(l) != first(r): result += 10 ** (size_l - min(size_l, 2)) - cut(l) - 1 if first(l) >= last(l): result += 1 result += cut(r) if first(r) <= last(r): result += 1 else: result += cut(r) - cut(l) - 1 if cut(r) - cut(l) > 0: if first(l) >= last(l): result += 1 if first(r) <= last(r): result += 1 print(int(result))
Title: Little Elephant and Interval Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*. Input Specification: The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Specification: On a single line print a single integer — the answer to the problem. Demo Input: ['2 47\n', '47 1024\n'] Demo Output: ['12\n', '98\n'] Note: In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
```python def size(x): res = 0 while x > 0: x //= 10 res += 1 return res def first(x): last = 0 while x > 0: last = x % 10 x //= 10 return last def last(x): return x % 10 def cut(x): x //= 10 x -= first(x) * 10 ** (size(x) - 1) return x l, r = list(map(int, input().split())) size_l = size(l) size_r = size(r) result = int(0) for i in range(size_l + 1, size_r): result += 9 * 10 ** (i - 2) if size_l != size_r: result += (9 - first(l)) * (10 ** (size_l - min(size_l, 2))) result += 10 ** (size_l - min(size_l, 2)) - cut(l) - 1 if first(l) >= last(l): result += 1 result += (first(r) - 1) * 10 ** (size_r - min(size_r, 2)) result += cut(r) if first(r) <= last(r): result += 1 else: result += (first(r) - first(l) - 1) * 10 ** (size_r - min(size_r, 2)) if first(l) != first(r): result += 10 ** (size_l - min(size_l, 2)) - cut(l) - 1 if first(l) >= last(l): result += 1 result += cut(r) if first(r) <= last(r): result += 1 else: result += cut(r) - cut(l) - 1 if cut(r) - cut(l) > 0: if first(l) >= last(l): result += 1 if first(r) <= last(r): result += 1 print(int(result)) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "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,604,894,140
2,147,483,647
PyPy 3
OK
TESTS
30
310
0
n = input() s = 0 for i in range(len(n)): if n[i].islower(): s += 1 if s >= len(n)-s: print(n.lower()) else: print(n.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python n = input() s = 0 for i in range(len(n)): if n[i].islower(): s += 1 if s >= len(n)-s: print(n.lower()) else: print(n.upper()) ```
3.9225
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,664,096,539
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
80
92
0
m = int(input()) i=0 xi=0 yi=0 zi=0 while i <m: x,y,z=map(int,input().split()) xi=xi+x yi=yi+y zi=zi+z i+=1 if xi+yi+zi ==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python m = int(input()) i=0 xi=0 yi=0 zi=0 while i <m: x,y,z=map(int,input().split()) xi=xi+x yi=yi+y zi=zi+z i+=1 if xi+yi+zi ==0: print('YES') else: print('NO') ```
0
26
A
Almost Prime
PROGRAMMING
900
[ "number theory" ]
A. Almost Prime
2
256
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output the amount of almost prime numbers between 1 and *n*, inclusive.
[ "10\n", "21\n" ]
[ "2\n", "8\n" ]
none
500
[ { "input": "10", "output": "2" }, { "input": "21", "output": "8" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, { "input": "19", "output": "6" }, { "input": "40", "output": "19" }, { "input": "77", "output": "41" }, { "input": "222", "output": "125" }, { "input": "987", "output": "501" }, { "input": "1000", "output": "508" }, { "input": "2000", "output": "958" }, { "input": "3000", "output": "1375" }, { "input": "2999", "output": "1375" }, { "input": "2998", "output": "1375" }, { "input": "2997", "output": "1374" }, { "input": "1429", "output": "706" }, { "input": "1673", "output": "808" }, { "input": "1500", "output": "732" }, { "input": "500", "output": "266" }, { "input": "856", "output": "439" } ]
1,643,967,737
2,147,483,647
PyPy 3-64
OK
TESTS
23
218
2,457,600
n=int(input()) ans=0 v=[0]*(n+1) for i in range(2,n+1): if(v[i]==0): for j in range(i,n+1,i): v[j]+=1 if(v[i]==2): ans+=1 print(ans)
Title: Almost Prime Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. Input Specification: Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). Output Specification: Output the amount of almost prime numbers between 1 and *n*, inclusive. Demo Input: ['10\n', '21\n'] Demo Output: ['2\n', '8\n'] Note: none
```python n=int(input()) ans=0 v=[0]*(n+1) for i in range(2,n+1): if(v[i]==0): for j in range(i,n+1,i): v[j]+=1 if(v[i]==2): ans+=1 print(ans) ```
3.940922
305
A
Strange Addition
PROGRAMMING
1,600
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers. The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100).
In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
[ "4\n100 10 1 0\n", "3\n2 70 3\n" ]
[ "4\n0 1 10 100 ", "2\n2 70 " ]
none
500
[ { "input": "4\n100 10 1 0", "output": "4\n0 1 10 100 " }, { "input": "3\n2 70 3", "output": "2\n2 70 " }, { "input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29", "output": "4\n0 6 30 100 " }, { "input": "50\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 89 1 19 42 35 27 7 14 88 33", "output": "3\n1 10 100 " }, { "input": "2\n1 2", "output": "1\n1 " }, { "input": "73\n39 66 3 59 40 93 72 34 95 79 83 65 99 57 48 44 82 76 31 21 64 19 53 75 37 16 43 5 47 24 15 22 20 55 45 74 42 10 61 49 23 80 35 62 2 9 67 97 51 81 1 70 88 63 33 25 68 13 69 71 73 6 18 52 41 38 96 46 92 85 14 36 100", "output": "3\n1 10 100 " }, { "input": "15\n74 90 73 47 36 44 81 21 66 92 2 38 62 72 49", "output": "2\n2 90 " }, { "input": "96\n17 10 0 85 57 78 15 99 55 6 7 88 12 95 58 19 47 18 96 82 21 80 97 77 46 31 54 70 23 60 59 100 66 92 51 14 91 25 16 27 44 4 35 98 8 52 24 5 81 29 73 13 61 56 45 75 49 71 94 48 3 76 32 65 72 1 84 36 86 40 83 50 22 33 41 11 26 93 90 43 39 79 89 9 64 68 42 74 87 2 62 34 20 63 67 37", "output": "4\n0 1 10 100 " }, { "input": "5\n23 75 38 47 70", "output": "1\n23 " }, { "input": "12\n89 61 45 92 22 3 94 66 48 21 54 14", "output": "1\n3 " }, { "input": "1\n99", "output": "1\n99 " }, { "input": "1\n0", "output": "1\n0 " }, { "input": "2\n100 1", "output": "2\n1 100 " }, { "input": "3\n1 100 99", "output": "2\n1 100 " }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "3\n1 10 100 " }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 0", "output": "4\n0 1 10 100 " }, { "input": "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "2\n1 10 " }, { "input": "2\n5 6", "output": "1\n5 " }, { "input": "81\n11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99", "output": "1\n11 " }, { "input": "3\n99 10 6", "output": "2\n6 10 " }, { "input": "4\n11 10 100 3", "output": "3\n3 10 100 " }, { "input": "2\n99 6", "output": "1\n6 " }, { "input": "3\n23 0 100", "output": "3\n0 23 100 " }, { "input": "2\n43 0", "output": "2\n0 43 " }, { "input": "4\n99 0 100 6", "output": "3\n0 6 100 " }, { "input": "1\n100", "output": "1\n100 " }, { "input": "2\n0 100", "output": "2\n0 100 " }, { "input": "3\n0 100 10", "output": "3\n0 10 100 " }, { "input": "3\n0 100 12", "output": "3\n0 12 100 " }, { "input": "3\n0 100 1", "output": "3\n0 1 100 " }, { "input": "4\n0 100 10 1", "output": "4\n0 1 10 100 " }, { "input": "4\n0 100 10 99", "output": "3\n0 10 100 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "2\n10 12", "output": "1\n10 " }, { "input": "2\n90 9", "output": "2\n9 90 " } ]
1,593,770,542
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
n=int(input()) list1=list(map(int,input().split())) c=0 ll=[] for i in range(n): if(list1[i]%10==0): c+=1 ll.append(list1[i]) if(c<n): for i in range(n): if(list1[i]%10!=0): c+=1 ll.append(list1[i]) break print(c) print(*ll)
Title: Strange Addition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input Specification: The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers. The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100). Output Specification: In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Demo Input: ['4\n100 10 1 0\n', '3\n2 70 3\n'] Demo Output: ['4\n0 1 10 100 ', '2\n2 70 '] Note: none
```python n=int(input()) list1=list(map(int,input().split())) c=0 ll=[] for i in range(n): if(list1[i]%10==0): c+=1 ll.append(list1[i]) if(c<n): for i in range(n): if(list1[i]%10!=0): c+=1 ll.append(list1[i]) break print(c) print(*ll) ```
0
931
B
World Cup
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over. Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet.
The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal.
In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final. Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1.
[ "4 1 2\n", "8 2 6\n", "8 7 5\n" ]
[ "1\n", "Final!\n", "2\n" ]
In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.
1,000
[ { "input": "4 1 2", "output": "1" }, { "input": "8 2 6", "output": "Final!" }, { "input": "8 7 5", "output": "2" }, { "input": "128 30 98", "output": "Final!" }, { "input": "256 128 256", "output": "Final!" }, { "input": "256 2 127", "output": "7" }, { "input": "2 1 2", "output": "Final!" }, { "input": "2 2 1", "output": "Final!" }, { "input": "4 1 3", "output": "Final!" }, { "input": "4 1 4", "output": "Final!" }, { "input": "4 2 1", "output": "1" }, { "input": "4 2 3", "output": "Final!" }, { "input": "4 2 4", "output": "Final!" }, { "input": "4 3 1", "output": "Final!" }, { "input": "4 3 2", "output": "Final!" }, { "input": "4 3 4", "output": "1" }, { "input": "4 4 1", "output": "Final!" }, { "input": "4 4 2", "output": "Final!" }, { "input": "4 4 3", "output": "1" }, { "input": "8 8 7", "output": "1" }, { "input": "8 8 5", "output": "2" }, { "input": "8 8 1", "output": "Final!" }, { "input": "16 4 3", "output": "1" }, { "input": "16 2 4", "output": "2" }, { "input": "16 14 11", "output": "3" }, { "input": "16 3 11", "output": "Final!" }, { "input": "32 10 9", "output": "1" }, { "input": "32 25 28", "output": "2" }, { "input": "32 22 18", "output": "3" }, { "input": "32 17 25", "output": "4" }, { "input": "32 18 3", "output": "Final!" }, { "input": "64 40 39", "output": "1" }, { "input": "64 60 58", "output": "2" }, { "input": "64 34 37", "output": "3" }, { "input": "64 26 24", "output": "4" }, { "input": "64 50 43", "output": "5" }, { "input": "64 17 42", "output": "Final!" }, { "input": "128 116 115", "output": "1" }, { "input": "128 35 33", "output": "2" }, { "input": "128 61 59", "output": "3" }, { "input": "128 116 123", "output": "4" }, { "input": "128 17 15", "output": "5" }, { "input": "128 124 77", "output": "6" }, { "input": "128 4 80", "output": "Final!" }, { "input": "256 224 223", "output": "1" }, { "input": "256 24 22", "output": "2" }, { "input": "256 199 196", "output": "3" }, { "input": "256 148 159", "output": "4" }, { "input": "256 178 166", "output": "5" }, { "input": "256 75 97", "output": "6" }, { "input": "256 185 200", "output": "7" }, { "input": "256 3 238", "output": "Final!" }, { "input": "256 128 129", "output": "Final!" }, { "input": "256 255 129", "output": "7" }, { "input": "256 255 128", "output": "Final!" }, { "input": "256 129 256", "output": "7" }, { "input": "128 98 69", "output": "6" }, { "input": "128 47 83", "output": "Final!" }, { "input": "16 2 3", "output": "2" }, { "input": "64 32 30", "output": "2" }, { "input": "8 4 5", "output": "Final!" }, { "input": "8 7 8", "output": "1" }, { "input": "8 2 3", "output": "2" }, { "input": "8 2 5", "output": "Final!" } ]
1,524,757,807
2,147,483,647
PyPy 3
OK
TESTS
64
93
21,401,600
def f(n, aim): xs = [x for x in range(1, n+1)] rn = 1 while len(xs) > 2: new_xs = [] for i in range(len(xs)//2): f, l = xs[2*i], xs[2*i+1] if f in aim and l in aim: return rn new_xs.append(f if f in aim else l) xs = new_xs rn+=1 return "Final!" n, a, b = [int(x) for x in input().split()] print(f(n, [a, b]))
Title: World Cup Time Limit: None seconds Memory Limit: None megabytes Problem Description: The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over. Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet. Input Specification: The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. Output Specification: In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final. Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. Demo Input: ['4 1 2\n', '8 2 6\n', '8 7 5\n'] Demo Output: ['1\n', 'Final!\n', '2\n'] Note: In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.
```python def f(n, aim): xs = [x for x in range(1, n+1)] rn = 1 while len(xs) > 2: new_xs = [] for i in range(len(xs)//2): f, l = xs[2*i], xs[2*i+1] if f in aim and l in aim: return rn new_xs.append(f if f in aim else l) xs = new_xs rn+=1 return "Final!" n, a, b = [int(x) for x in input().split()] print(f(n, [a, b])) ```
3
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and 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,699,048,130
2,147,483,647
Python 3
OK
TESTS
40
122
614,400
k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) dragons = [False] * d for i in range(1, d+1): if i % k == 0 or i % l == 0 or i % m == 0 or i % n == 0: dragons[i-1] = True damaged_dragons = dragons.count(True) print(damaged_dragons)
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()) dragons = [False] * d for i in range(1, d+1): if i % k == 0 or i % l == 0 or i % m == 0 or i % n == 0: dragons[i-1] = True damaged_dragons = dragons.count(True) print(damaged_dragons) ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10", "output": "0" }, { "input": "8 20", "output": "0" }, { "input": "2 8", "output": "0" }, { "input": "20 11", "output": "0" }, { "input": "57 447", "output": "1" }, { "input": "1 1", "output": "2" }, { "input": "66 296", "output": "1" }, { "input": "75 683", "output": "1" }, { "input": "227 975", "output": "1" }, { "input": "247 499", "output": "1" }, { "input": "266 116", "output": "1" }, { "input": "286 916", "output": "1" }, { "input": "307 341", "output": "1" }, { "input": "451 121", "output": "1" }, { "input": "471 921", "output": "1" }, { "input": "502 346", "output": "1" }, { "input": "535 59", "output": "1" }, { "input": "555 699", "output": "1" }, { "input": "747 351", "output": "1" }, { "input": "790 64", "output": "1" }, { "input": "810 704", "output": "1" }, { "input": "855 225", "output": "1" }, { "input": "902 34", "output": "1" }, { "input": "922 514", "output": "1" }, { "input": "971 131", "output": "1" }, { "input": "991 931", "output": "1" }, { "input": "840 780", "output": "0" }, { "input": "102 595", "output": "0" }, { "input": "139 433", "output": "0" }, { "input": "968 288", "output": "0" }, { "input": "563 354", "output": "0" }, { "input": "994 975", "output": "0" }, { "input": "456 221", "output": "0" }, { "input": "205 210", "output": "0" }, { "input": "1 11", "output": "0" }, { "input": "1000 1000", "output": "0" }, { "input": "3 3", "output": "0" }, { "input": "11 99", "output": "0" }, { "input": "2 2", "output": "1" }, { "input": "11 1", "output": "0" }, { "input": "6 6", "output": "1" }, { "input": "100 452", "output": "0" }, { "input": "420 380", "output": "0" }, { "input": "31 31", "output": "0" }, { "input": "2 6", "output": "0" }, { "input": "112 134", "output": "0" }, { "input": "13 13", "output": "0" }, { "input": "1 571", "output": "0" } ]
1,677,369,599
2,147,483,647
Python 3
OK
TESTS
54
498
0
n,m=map(int,input().split()) count=0 for a in range(1001): for b in range(1001): if n==a*a+b and m==a+b*b and n>=1 and m>=1 and n<=1000 and m<=1000: count=count+1 print(count)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. Input Specification: A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. Output Specification: On a single line print the answer to the problem. Demo Input: ['9 3\n', '14 28\n', '4 20\n'] Demo Output: ['1\n', '1\n', '0\n'] Note: In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
```python n,m=map(int,input().split()) count=0 for a in range(1001): for b in range(1001): if n==a*a+b and m==a+b*b and n>=1 and m>=1 and n<=1000 and m<=1000: count=count+1 print(count) ```
3
355
B
Vasya and Public Transport
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are numbered by integers from 1 to *m*. Public transport is not free. There are 4 types of tickets: 1. A ticket for one ride on some bus or trolley. It costs *c*1 burles; 1. A ticket for an unlimited number of rides on some bus or on some trolley. It costs *c*2 burles; 1. A ticket for an unlimited number of rides on all buses or all trolleys. It costs *c*3 burles; 1. A ticket for an unlimited number of rides on all buses and trolleys. It costs *c*4 burles. Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets.
The first line contains four integers *c*1,<=*c*2,<=*c*3,<=*c*4 (1<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4<=≤<=1000) — the costs of the tickets. The second line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of buses and trolleys Vasya is going to use. The third line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1000) — the number of times Vasya is going to use the bus number *i*. The fourth line contains *m* integers *b**i* (0<=≤<=*b**i*<=≤<=1000) — the number of times Vasya is going to use the trolley number *i*.
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
[ "1 3 7 19\n2 3\n2 5\n4 4 4\n", "4 3 2 1\n1 3\n798\n1 2 3\n", "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n" ]
[ "12\n", "1\n", "16\n" ]
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles. In the second sample the profitable strategy is to buy one ticket of the fourth type. In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.
1,000
[ { "input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12" }, { "input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1" }, { "input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16" }, { "input": "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0", "output": "717" }, { "input": "7 11 597 948\n4 1\n5 1 0 11\n7", "output": "40" }, { "input": "7 32 109 645\n1 3\n0\n0 0 0", "output": "0" }, { "input": "680 871 347 800\n10 100\n872 156 571 136 703 201 832 213 15 333\n465 435 870 95 660 237 694 594 423 405 27 866 325 490 255 989 128 345 278 125 708 210 771 848 961 448 871 190 745 343 532 174 103 999 874 221 252 500 886 129 185 208 137 425 800 34 696 39 198 981 91 50 545 885 194 583 475 415 162 712 116 911 313 488 646 189 429 756 728 30 985 114 823 111 106 447 296 430 307 388 345 458 84 156 169 859 274 934 634 62 12 839 323 831 24 907 703 754 251 938", "output": "694" }, { "input": "671 644 748 783\n100 10\n520 363 816 957 635 753 314 210 763 819 27 970 520 164 195 230 708 587 568 707 343 30 217 227 755 277 773 497 900 589 826 666 115 784 494 467 217 892 658 388 764 812 248 447 876 581 94 915 675 967 508 754 768 79 261 934 603 712 20 199 997 501 465 91 897 257 820 645 217 105 564 8 668 171 168 18 565 840 418 42 808 918 409 617 132 268 13 161 194 628 213 199 545 448 113 410 794 261 211 539\n147 3 178 680 701 193 697 666 846 389", "output": "783" }, { "input": "2 7 291 972\n63 92\n7 0 0 6 0 13 0 20 2 8 0 17 7 0 0 0 0 2 2 0 0 8 20 0 0 0 3 0 0 0 4 20 0 0 0 12 0 8 17 9 0 0 0 0 4 0 0 0 17 11 3 0 2 15 0 18 11 19 14 0 0 20 13\n0 0 0 3 7 0 0 0 0 8 13 6 15 0 7 0 0 20 0 0 12 0 12 0 15 0 0 1 11 14 0 11 12 0 0 0 0 0 16 16 0 17 20 0 11 0 0 20 14 0 16 0 3 6 12 0 0 0 0 0 15 3 0 9 17 12 20 17 0 0 0 0 15 9 0 14 10 10 1 20 16 17 20 6 6 0 0 16 4 6 0 7", "output": "494" }, { "input": "4 43 490 945\n63 92\n0 0 0 0 0 0 6 5 18 0 6 4 0 17 0 19 0 19 7 16 0 0 0 9 10 13 7 0 10 16 0 0 0 0 0 14 0 14 9 15 0 0 2 0 0 0 0 5 0 0 0 11 11 0 0 0 0 0 10 12 3 0 0\n0 12 0 18 7 7 0 0 9 0 0 13 17 0 18 12 4 0 0 14 18 20 0 0 12 9 17 1 19 0 11 0 5 0 0 14 0 0 16 0 19 15 9 14 7 10 0 19 19 0 0 1 0 0 0 6 0 0 0 6 0 20 1 9 0 0 10 17 5 2 5 4 16 6 0 11 0 8 13 4 0 2 0 0 13 10 0 13 0 0 8 4", "output": "945" }, { "input": "2 50 258 922\n42 17\n0 2 0 1 0 1 0 11 18 9 0 0 0 0 10 15 17 4 20 0 5 0 0 13 13 0 0 2 0 7 0 20 4 0 19 3 7 0 0 0 0 0\n8 4 19 0 0 19 14 17 6 0 18 0 0 0 0 9 0", "output": "486" }, { "input": "1 1 3 4\n2 3\n1 1\n1 1 1", "output": "4" }, { "input": "4 4 4 1\n1 1\n0\n0", "output": "0" }, { "input": "100 100 1 100\n10 10\n100 100 100 100 100 100 100 100 100 100\n100 100 100 100 100 100 100 100 100 100", "output": "2" } ]
1,615,726,482
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
92
1,228,800
if __name__ == '__main__': c1,c2,c3,c4 = map(int, input().split()) n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = min(c1,c2,c3,c4) l = [] if s == c4: print(c4) else: required = 0 for i in range (n): required = required+min(c2,c1*a[i]) ans = min(c3,required) required = 0 for i in range (m): required = required + min(c2,c1*b[i]) ans = ans + min(c3,required) print(ans)
Title: Vasya and Public Transport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are numbered by integers from 1 to *m*. Public transport is not free. There are 4 types of tickets: 1. A ticket for one ride on some bus or trolley. It costs *c*1 burles; 1. A ticket for an unlimited number of rides on some bus or on some trolley. It costs *c*2 burles; 1. A ticket for an unlimited number of rides on all buses or all trolleys. It costs *c*3 burles; 1. A ticket for an unlimited number of rides on all buses and trolleys. It costs *c*4 burles. Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets. Input Specification: The first line contains four integers *c*1,<=*c*2,<=*c*3,<=*c*4 (1<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4<=≤<=1000) — the costs of the tickets. The second line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of buses and trolleys Vasya is going to use. The third line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1000) — the number of times Vasya is going to use the bus number *i*. The fourth line contains *m* integers *b**i* (0<=≤<=*b**i*<=≤<=1000) — the number of times Vasya is going to use the trolley number *i*. Output Specification: Print a single number — the minimum sum of burles Vasya will have to spend on the tickets. Demo Input: ['1 3 7 19\n2 3\n2 5\n4 4 4\n', '4 3 2 1\n1 3\n798\n1 2 3\n', '100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n'] Demo Output: ['12\n', '1\n', '16\n'] Note: In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles. In the second sample the profitable strategy is to buy one ticket of the fourth type. In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.
```python if __name__ == '__main__': c1,c2,c3,c4 = map(int, input().split()) n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = min(c1,c2,c3,c4) l = [] if s == c4: print(c4) else: required = 0 for i in range (n): required = required+min(c2,c1*a[i]) ans = min(c3,required) required = 0 for i in range (m): required = required + min(c2,c1*b[i]) ans = ans + min(c3,required) print(ans) ```
0
152
A
Marks
PROGRAMMING
900
[ "implementation" ]
null
null
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at. Your task is to find the number of successful students in the group.
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
Print the single number — the number of successful students in the given group.
[ "3 3\n223\n232\n112\n", "3 5\n91728\n11828\n11111\n" ]
[ "2\n", "3\n" ]
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
500
[ { "input": "3 3\n223\n232\n112", "output": "2" }, { "input": "3 5\n91728\n11828\n11111", "output": "3" }, { "input": "2 2\n48\n27", "output": "1" }, { "input": "2 1\n4\n6", "output": "1" }, { "input": "1 2\n57", "output": "1" }, { "input": "1 1\n5", "output": "1" }, { "input": "3 4\n2553\n6856\n5133", "output": "2" }, { "input": "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285", "output": "6" }, { "input": "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994", "output": "4" }, { "input": "10 20\n26855662887514171367\n48525577498621511535\n47683778377545341138\n47331616748732562762\n44876938191354974293\n24577238399664382695\n42724955594463126746\n79187344479926159359\n48349683283914388185\n82157191115518781898", "output": "9" }, { "input": "20 15\n471187383859588\n652657222494199\n245695867594992\n726154672861295\n614617827782772\n862889444974692\n373977167653235\n645434268565473\n785993468314573\n722176861496755\n518276853323939\n723712762593348\n728935312568886\n373898548522463\n769777587165681\n247592995114377\n182375946483965\n497496542536127\n988239919677856\n859844339819143", "output": "18" }, { "input": "13 9\n514562255\n322655246\n135162979\n733845982\n473117129\n513967187\n965649829\n799122777\n661249521\n298618978\n659352422\n747778378\n723261619", "output": "11" }, { "input": "75 1\n2\n3\n8\n3\n2\n1\n3\n1\n5\n1\n5\n4\n8\n8\n4\n2\n5\n1\n7\n6\n3\n2\n2\n3\n5\n5\n2\n4\n7\n7\n9\n2\n9\n5\n1\n4\n9\n5\n2\n4\n6\n6\n3\n3\n9\n3\n3\n2\n3\n4\n2\n6\n9\n1\n1\n1\n1\n7\n2\n3\n2\n9\n7\n4\n9\n1\n7\n5\n6\n8\n3\n4\n3\n4\n6", "output": "7" }, { "input": "92 3\n418\n665\n861\n766\n529\n416\n476\n676\n561\n995\n415\n185\n291\n176\n776\n631\n556\n488\n118\n188\n437\n496\n466\n131\n914\n118\n766\n365\n113\n897\n386\n639\n276\n946\n759\n169\n494\n837\n338\n351\n783\n311\n261\n862\n598\n132\n246\n982\n575\n364\n615\n347\n374\n368\n523\n132\n774\n161\n552\n492\n598\n474\n639\n681\n635\n342\n516\n483\n141\n197\n571\n336\n175\n596\n481\n327\n841\n133\n142\n146\n246\n396\n287\n582\n556\n996\n479\n814\n497\n363\n963\n162", "output": "23" }, { "input": "100 1\n1\n6\n9\n1\n1\n5\n5\n4\n6\n9\n6\n1\n7\n8\n7\n3\n8\n8\n7\n6\n2\n1\n5\n8\n7\n3\n5\n4\n9\n7\n1\n2\n4\n1\n6\n5\n1\n3\n9\n4\n5\n8\n1\n2\n1\n9\n7\n3\n7\n1\n2\n2\n2\n2\n3\n9\n7\n2\n4\n7\n1\n6\n8\n1\n5\n6\n1\n1\n2\n9\n7\n4\n9\n1\n9\n4\n1\n3\n5\n2\n4\n4\n6\n5\n1\n4\n5\n8\n4\n7\n6\n5\n6\n9\n5\n8\n1\n5\n1\n6", "output": "10" }, { "input": "100 2\n71\n87\n99\n47\n22\n87\n49\n73\n21\n12\n77\n43\n18\n41\n78\n62\n61\n16\n64\n89\n81\n54\n53\n92\n93\n94\n68\n93\n15\n68\n42\n93\n28\n19\n86\n16\n97\n17\n11\n43\n72\n76\n54\n95\n58\n53\n48\n45\n85\n85\n74\n21\n44\n51\n89\n75\n76\n17\n38\n62\n81\n22\n66\n59\n89\n85\n91\n87\n12\n97\n52\n87\n43\n89\n51\n58\n57\n98\n78\n68\n82\n41\n87\n29\n75\n72\n48\n14\n35\n71\n74\n91\n66\n67\n42\n98\n52\n54\n22\n41", "output": "21" }, { "input": "5 20\n11111111111111111111\n11111111111111111111\n11111111111111111111\n99999999999999999999\n11111111111111111119", "output": "2" }, { "input": "3 3\n111\n111\n999", "output": "1" }, { "input": "3 3\n119\n181\n711", "output": "3" }, { "input": "15 5\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111", "output": "15" }, { "input": "2 20\n22222222222222222222\n11111111111111111111", "output": "1" }, { "input": "3 3\n233\n222\n111", "output": "2" }, { "input": "4 15\n222222222222222\n111111111111119\n111111111111119\n111111111111111", "output": "3" }, { "input": "4 1\n1\n9\n9\n9", "output": "3" }, { "input": "3 3\n123\n321\n132", "output": "3" }, { "input": "3 3\n113\n332\n322", "output": "3" }, { "input": "2 100\n2222222222222222222222222222222222222222222222222222222222222222222222221222222222222222222222222222\n1111111111111111111111111111111111111111111111111111111111111111111111119111111111111111111111111111", "output": "2" }, { "input": "3 3\n321\n231\n123", "output": "3" }, { "input": "2 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222", "output": "1" }, { "input": "3 3\n221\n111\n111", "output": "3" } ]
1,622,036,002
2,147,483,647
PyPy 3
OK
TESTS
44
108
1,740,800
def main_function(): n, m = [int(i) for i in input().split(" ")] students = [] for i in range(n): students.append(input()) hash_table = {} max_scores = [] for i in range(m): maxis = 0 for j in range(n): if int(students[j][i]) > maxis: maxis = int(students[j][i]) max_scores.append(maxis) hash_table = [0 for i in range(n)] for i in range(m): maxu = max_scores[i] for j in range(n): if int(students[j][i]) == maxu: hash_table[j] += 1 counter = 0 for i in hash_table: if i != 0: counter += 1 return counter return max_scores print(main_function())
Title: Marks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at. Your task is to find the number of successful students in the group. Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces. Output Specification: Print the single number — the number of successful students in the given group. Demo Input: ['3 3\n223\n232\n112\n', '3 5\n91728\n11828\n11111\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
```python def main_function(): n, m = [int(i) for i in input().split(" ")] students = [] for i in range(n): students.append(input()) hash_table = {} max_scores = [] for i in range(m): maxis = 0 for j in range(n): if int(students[j][i]) > maxis: maxis = int(students[j][i]) max_scores.append(maxis) hash_table = [0 for i in range(n)] for i in range(m): maxu = max_scores[i] for j in range(n): if int(students[j][i]) == maxu: hash_table[j] += 1 counter = 0 for i in hash_table: if i != 0: counter += 1 return counter return max_scores print(main_function()) ```
3
469
B
Chat Online
PROGRAMMING
1,300
[ "implementation" ]
null
null
Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between *a*1 and *b*1, between *a*2 and *b*2, ..., between *a**p* and *b**p* (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between *c*1 and *d*1, between *c*2 and *d*2, ..., between *c**q* and *d**q* (all borders inclusive). But if he gets up at time *t*, these segments will be shifted by *t*. They become [*c**i*<=+<=*t*,<=*d**i*<=+<=*t*] (for all *i*). If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between *l* and *r* (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [*l*,<=*r*] suit for that?
The first line contains four space-separated integers *p*,<=*q*,<=*l*,<=*r* (1<=≤<=<=*p*,<=*q*<=≤<=50; 0<=≤<=*l*<=≤<=*r*<=≤<=1000). Each of the next *p* lines contains two space-separated integers *a**i*,<=*b**i* (0<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=1000). Each of the next *q* lines contains two space-separated integers *c**j*,<=*d**j* (0<=≤<=*c**j*<=&lt;<=*d**j*<=≤<=1000). It's guaranteed that *b**i*<=&lt;<=*a**i*<=+<=1 and *d**j*<=&lt;<=*c**j*<=+<=1 for all valid *i* and *j*.
Output a single integer — the number of moments of time from the segment [*l*,<=*r*] which suit for online conversation.
[ "1 1 0 4\n2 3\n0 1\n", "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17\n" ]
[ "3\n", "20\n" ]
none
1,000
[ { "input": "1 1 0 4\n2 3\n0 1", "output": "3" }, { "input": "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "output": "20" }, { "input": "5 2 27 452\n148 154\n421 427\n462 470\n777 786\n969 978\n245 247\n313 322", "output": "54" }, { "input": "3 6 25 785\n273 275\n391 397\n775 783\n84 89\n348 354\n480 483\n552 556\n711 716\n838 844", "output": "99" }, { "input": "1 6 364 421\n649 688\n31 39\n438 441\n516 524\n609 615\n708 710\n850 851", "output": "0" }, { "input": "7 10 87 239\n8 23\n325 374\n516 540\n633 658\n728 742\n833 839\n960 995\n99 114\n213 232\n264 269\n321 327\n492 540\n551 559\n587 590\n625 637\n704 723\n750 764", "output": "151" }, { "input": "33 17 295 791\n41 49\n66 73\n95 102\n118 126\n157 158\n189 198\n228 237\n247 251\n301 307\n318 326\n328 333\n356 363\n373 381\n454 460\n463 466\n471 477\n500 501\n505 510\n559 566\n585 588\n597 604\n675 684\n688 695\n699 705\n749 755\n780 788\n869 873\n879 888\n890 892\n909 918\n953 954\n973 978\n993 996\n53 60\n68 74\n102 105\n149 153\n191 206\n230 242\n249 252\n320 325\n483 488\n509 513\n523 524\n544 560\n651 655\n670 672\n691 708\n742 748\n920 939", "output": "497" }, { "input": "5 4 520 527\n257 263\n309 315\n434 439\n540 541\n759 763\n168 176\n313 316\n546 548\n880 881", "output": "0" }, { "input": "11 40 58 976\n14 22\n85 92\n110 112\n173 181\n188 190\n212 218\n494 498\n530 531\n647 656\n943 948\n960 968\n2 16\n20 31\n40 86\n90 91\n93 96\n103 118\n128 155\n170 173\n176 192\n205 207\n210 217\n237 245\n250 280\n302 304\n311 328\n332 376\n387 419\n422 442\n449 454\n462 491\n496 498\n501 516\n525 552\n556 565\n567 573\n577 578\n586 635\n651 677\n688 699\n704 714\n718 719\n733 766\n768 769\n773 811\n822 826\n830 870\n885 917\n937 961\n971 981\n991 1000", "output": "909" }, { "input": "10 28 435 847\n48 57\n86 95\n186 188\n297 304\n500 506\n594 600\n602 609\n802 811\n906 911\n916 921\n20 22\n115 118\n139 141\n170 171\n184 188\n193 197\n227 230\n232 235\n250 252\n256 260\n271 275\n322 324\n326 328\n379 381\n433 434\n528 529\n563 565\n583 584\n614 615\n617 619\n631 632\n726 729\n750 754\n814 817\n853 855\n881 882\n946 947\n981 984", "output": "284" }, { "input": "13 42 292 733\n304 308\n362 365\n396 397\n686 688\n719 722\n815 816\n901 902\n904 905\n921 924\n929 933\n953 954\n977 980\n982 985\n28 30\n36 37\n108 112\n123 127\n134 135\n151 153\n160 162\n203 205\n208 212\n240 243\n261 264\n271 274\n294 297\n356 358\n383 385\n408 412\n415 418\n435 439\n444 447\n500 502\n507 511\n515 519\n525 529\n541 543\n566 569\n577 579\n606 609\n618 622\n655 656\n715 718\n744 745\n767 771\n798 802\n828 830\n839 840\n842 845\n893 894\n897 898\n902 906\n958 960\n981 983\n988 992", "output": "412" }, { "input": "5 46 211 943\n367 371\n405 408\n639 642\n821 825\n974 978\n13 14\n31 34\n36 39\n48 51\n82 86\n173 174\n193 196\n227 230\n249 250\n259 261\n292 294\n325 327\n329 330\n352 353\n380 383\n390 391\n398 399\n411 414\n418 420\n424 427\n478 479\n488 489\n500 502\n511 514\n534 535\n548 552\n581 584\n596 600\n609 611\n618 622\n641 642\n656 657\n674 678\n707 709\n718 720\n746 748\n752 755\n771 773\n775 777\n865 869\n892 896\n910 911\n946 948\n963 964\n977 978\n986 990", "output": "428" }, { "input": "1 8 169 472\n63 553\n32 65\n75 204\n263 277\n289 326\n342 441\n452 911\n945 956\n971 986", "output": "304" }, { "input": "2 1 17 179\n159 202\n579 602\n115 126", "output": "55" }, { "input": "1 1 0 1000\n0 1000\n0 1000", "output": "1001" }, { "input": "10 11 201 515\n2 3\n102 103\n202 203\n302 304\n401 402\n502 503\n600 603\n701 702\n800 803\n900 902\n1 2\n103 104\n201 202\n302 304\n400 404\n501 504\n600 601\n603 604\n701 704\n800 801\n900 902", "output": "26" }, { "input": "1 7 140 478\n400 404\n3 4\n100 105\n301 304\n403 405\n504 506\n600 605\n904 906", "output": "16" }, { "input": "9 8 453 552\n5 18\n23 28\n125 132\n208 209\n215 230\n516 527\n808 819\n906 913\n926 929\n4 18\n221 229\n316 330\n403 424\n506 516\n805 828\n904 914\n916 917", "output": "49" }, { "input": "9 1 24 52\n63 94\n150 164\n244 275\n379 385\n413 420\n441 490\n506 545\n614 661\n752 776\n531 534", "output": "0" }, { "input": "1 1 0 0\n1 3\n2 5", "output": "1" } ]
1,694,036,583
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; int main() { int p, q, l, r; scanf("%d%d%d%d", &p, &q, &l, &r); vector<pair<int, int>> Z(p), X(q); int ans = 0; for (int i = 0; i < p; i++) cin >> Z[i].first >> Z[i].second; for (int i = 0; i < q; i++) cin >> X[i].first >> X[i].second; for (auto Q: X) { int c = Q.first, d = Q.second; for (auto P: Z) { int a = P.first, b = P.second; int u = min(b - c + 1, r), v = max(a - d, l + 1); int diff = u - v; ans += diff; } } printf("%d", ans); return 0; }
Title: Chat Online Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between *a*1 and *b*1, between *a*2 and *b*2, ..., between *a**p* and *b**p* (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between *c*1 and *d*1, between *c*2 and *d*2, ..., between *c**q* and *d**q* (all borders inclusive). But if he gets up at time *t*, these segments will be shifted by *t*. They become [*c**i*<=+<=*t*,<=*d**i*<=+<=*t*] (for all *i*). If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between *l* and *r* (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [*l*,<=*r*] suit for that? Input Specification: The first line contains four space-separated integers *p*,<=*q*,<=*l*,<=*r* (1<=≤<=<=*p*,<=*q*<=≤<=50; 0<=≤<=*l*<=≤<=*r*<=≤<=1000). Each of the next *p* lines contains two space-separated integers *a**i*,<=*b**i* (0<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=1000). Each of the next *q* lines contains two space-separated integers *c**j*,<=*d**j* (0<=≤<=*c**j*<=&lt;<=*d**j*<=≤<=1000). It's guaranteed that *b**i*<=&lt;<=*a**i*<=+<=1 and *d**j*<=&lt;<=*c**j*<=+<=1 for all valid *i* and *j*. Output Specification: Output a single integer — the number of moments of time from the segment [*l*,<=*r*] which suit for online conversation. Demo Input: ['1 1 0 4\n2 3\n0 1\n', '2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17\n'] Demo Output: ['3\n', '20\n'] Note: none
```python #include <bits/stdc++.h> using namespace std; int main() { int p, q, l, r; scanf("%d%d%d%d", &p, &q, &l, &r); vector<pair<int, int>> Z(p), X(q); int ans = 0; for (int i = 0; i < p; i++) cin >> Z[i].first >> Z[i].second; for (int i = 0; i < q; i++) cin >> X[i].first >> X[i].second; for (auto Q: X) { int c = Q.first, d = Q.second; for (auto P: Z) { int a = P.first, b = P.second; int u = min(b - c + 1, r), v = max(a - d, l + 1); int diff = u - v; ans += diff; } } printf("%d", ans); return 0; } ```
-1
597
C
Subsequences
PROGRAMMING
1,900
[ "data structures", "dp" ]
null
null
For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018.
First line contain two integer values *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=10) — the length of sequence and the number of elements in increasing subsequences. Next *n* lines contains one integer *a**i* (1<=≤<=*a**i*<=≤<=*n*) each — elements of sequence. All values *a**i* are different.
Print one integer — the answer to the problem.
[ "5 2\n1\n2\n3\n5\n4\n" ]
[ "7\n" ]
none
1,500
[ { "input": "5 2\n1\n2\n3\n5\n4", "output": "7" }, { "input": "1 0\n1", "output": "1" }, { "input": "2 1\n1\n2", "output": "1" }, { "input": "2 1\n2\n1", "output": "0" }, { "input": "3 2\n1\n2\n3", "output": "1" }, { "input": "3 1\n1\n3\n2", "output": "2" }, { "input": "3 1\n2\n1\n3", "output": "2" }, { "input": "3 1\n2\n3\n1", "output": "1" }, { "input": "3 1\n3\n1\n2", "output": "1" }, { "input": "3 2\n3\n2\n1", "output": "0" }, { "input": "10 2\n6\n10\n9\n7\n1\n2\n8\n5\n4\n3", "output": "5" }, { "input": "100 7\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100", "output": "186087894300" } ]
1,647,854,273
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n, k = map(int, input().split()) nums = [] for i in range(n): nums.append(int(input())) dp = [[0] * (k + 1) for _ in range(n)] dp[-1][0] = 1 dp[-1][1] = 1 for i in range(n - 2, -1, -1): dp[i][0] = 1 dp[i][1] = 1 for length in range(1, k): for j in range(i + 1, n): if nums[i] > nums[j]: dp[i][length + 1] += dp[j][length] result = 0 for i in range(n): result += dp[i][k] print(result)
Title: Subsequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018. Input Specification: First line contain two integer values *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=10) — the length of sequence and the number of elements in increasing subsequences. Next *n* lines contains one integer *a**i* (1<=≤<=*a**i*<=≤<=*n*) each — elements of sequence. All values *a**i* are different. Output Specification: Print one integer — the answer to the problem. Demo Input: ['5 2\n1\n2\n3\n5\n4\n'] Demo Output: ['7\n'] Note: none
```python n, k = map(int, input().split()) nums = [] for i in range(n): nums.append(int(input())) dp = [[0] * (k + 1) for _ in range(n)] dp[-1][0] = 1 dp[-1][1] = 1 for i in range(n - 2, -1, -1): dp[i][0] = 1 dp[i][1] = 1 for length in range(1, k): for j in range(i + 1, n): if nums[i] > nums[j]: dp[i][length + 1] += dp[j][length] result = 0 for i in range(n): result += dp[i][k] print(result) ```
0
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
1,598,257,452
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
139
20,172,800
s = input() l = len(s) num = s.count('bear') occurences = num * (l - 3) + 4 * (num - 1) print(occurences)
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python s = input() l = len(s) num = s.count('bear') occurences = num * (l - 3) + 4 * (num - 1) print(occurences) ```
0
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20 1 80", "output": "1 20 40 60 80 100 " }, { "input": "10\n10 8 6 7 5 3 4 2 9 1", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "100\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": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 " }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 1 2 3 4 6 7 7 8 9 " }, { "input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59", "output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 " }, { "input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12", "output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 " }, { "input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84", "output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 " }, { "input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 " }, { "input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52", "output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 " }, { "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": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "100\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 " }, { "input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6", "output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 " }, { "input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3", "output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 " }, { "input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32", "output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 " }, { "input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41", "output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 " }, { "input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82", "output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 " }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 " }, { "input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 " }, { "input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88", "output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 " }, { "input": "100\n100 51 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", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 " }, { "input": "10\n100 90 80 70 60 50 40 30 20 10", "output": "10 20 30 40 50 60 70 80 90 100 " }, { "input": "1\n10", "output": "10 " } ]
1,699,118,343
2,147,483,647
Python 3
OK
TESTS
32
46
0
lst = int(input()) num = list(map(int,input().split())) num.sort() print(*num,sep=" ")
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! Input Specification: The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. Output Specification: Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. Demo Input: ['4\n3 2 1 2\n', '3\n2 3 8\n'] Demo Output: ['1 2 2 3 \n', '2 3 8 \n'] Note: The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
```python lst = int(input()) num = list(map(int,input().split())) num.sort() print(*num,sep=" ") ```
3
983
A
Finite or not?
PROGRAMMING
1,700
[ "implementation", "math" ]
null
null
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction. A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries. Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$.
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
[ "2\n6 12 10\n4 3 10\n", "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n" ]
[ "Finite\nInfinite\n", "Finite\nFinite\nFinite\nInfinite\n" ]
$\frac{6}{12} = \frac{1}{2} = 0,5_{10}$ $\frac{4}{3} = 1,(3)_{10}$ $\frac{9}{36} = \frac{1}{4} = 0,01_2$ $\frac{4}{12} = \frac{1}{3} = 0,1_3$
500
[ { "input": "2\n6 12 10\n4 3 10", "output": "Finite\nInfinite" }, { "input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4", "output": "Finite\nFinite\nFinite\nInfinite" }, { "input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2", "output": "Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite" }, { "input": "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10", "output": "Infinite\nFinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite" }, { "input": "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4", "output": "Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\nFinite" }, { "input": "10\n5 8 2\n0 5 8\n5 9 7\n0 7 2\n6 7 2\n10 3 7\n8 1 10\n9 1 8\n0 7 10\n9 1 4", "output": "Finite\nFinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite" }, { "input": "1\n1 864691128455135232 2", "output": "Infinite" }, { "input": "11\n1 1000000000000000000 10000000\n2 999 9\n2 999 333111\n0 9 7\n17 128 2\n13 311992186885373952 18\n1971402979058461 750473176484995605 75\n14 19 23\n3 21914624432020321 23\n3 21914624432020321 46\n3 21914624432020321 47", "output": "Finite\nInfinite\nFinite\nFinite\nFinite\nFinite\nFinite\nInfinite\nFinite\nFinite\nInfinite" }, { "input": "1\n1 100000000000000000 10000000000000000", "output": "Finite" }, { "input": "1\n1 4294967297 4294967296", "output": "Infinite" }, { "input": "1\n1 5244319080000 30030", "output": "Finite" } ]
1,548,944,583
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
186
23,142,400
import math for _ in range(int(input())): a,b,c=map(int,input().split()) s=str(a/b) k='0'+s[s.find('.'):] #print("Initial:",k) count=0;t=1 while(float(k)!=0): count+=1 s=str(float(k)*c) k='0'+s[s.find('.'):] #print(k) if count>8: break if count!=9: print("Finite") else: print("Infinite")
Title: Finite or not? Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction. A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries. Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. Output Specification: For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Demo Input: ['2\n6 12 10\n4 3 10\n', '4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n'] Demo Output: ['Finite\nInfinite\n', 'Finite\nFinite\nFinite\nInfinite\n'] Note: $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$ $\frac{4}{3} = 1,(3)_{10}$ $\frac{9}{36} = \frac{1}{4} = 0,01_2$ $\frac{4}{12} = \frac{1}{3} = 0,1_3$
```python import math for _ in range(int(input())): a,b,c=map(int,input().split()) s=str(a/b) k='0'+s[s.find('.'):] #print("Initial:",k) count=0;t=1 while(float(k)!=0): count+=1 s=str(float(k)*c) k='0'+s[s.find('.'):] #print(k) if count>8: break if count!=9: print("Finite") else: print("Infinite") ```
0
813
A
The Contest
PROGRAMMING
1,100
[ "implementation" ]
null
null
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in *a**i* time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment. Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during *m* time periods, *j*th period is represented by its starting moment *l**j* and ending moment *r**j*. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment *T* iff there exists a period *x* such that *l**x*<=≤<=*T*<=≤<=*r**x*. Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=105) — the time Pasha needs to solve *i*th problem. The third line contains one integer *m* (0<=≤<=*m*<=≤<=1000) — the number of periods of time when the website is working. Next *m* lines represent these periods. *j*th line contains two numbers *l**j* and *r**j* (1<=≤<=*l**j*<=&lt;<=*r**j*<=≤<=105) — the starting and the ending moment of *j*th period. It is guaranteed that the periods are not intersecting and are given in chronological order, so for every *j*<=&gt;<=1 the condition *l**j*<=&gt;<=*r**j*<=-<=1 is met.
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets).
[ "2\n3 4\n2\n1 4\n7 9\n", "1\n5\n1\n1 4\n", "1\n5\n1\n1 5\n" ]
[ "7\n", "-1\n", "5\n" ]
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again. In the second example Pasha invents the solution only after the website stops working for the last time. In the third example Pasha sends the solution exactly at the end of the first period.
0
[ { "input": "2\n3 4\n2\n1 4\n7 9", "output": "7" }, { "input": "1\n5\n1\n1 4", "output": "-1" }, { "input": "1\n5\n1\n1 5", "output": "5" }, { "input": "5\n100000 100000 100000 100000 100000\n0", "output": "-1" }, { "input": "5\n886 524 128 4068 298\n3\n416 3755\n4496 11945\n17198 18039", "output": "5904" }, { "input": "10\n575 3526 1144 1161 889 1038 790 19 765 357\n2\n4475 10787\n16364 21678", "output": "10264" }, { "input": "1\n4\n1\n5 9", "output": "5" }, { "input": "1\n200\n4\n1 10\n20 40\n50 55\n190 210", "output": "200" }, { "input": "4\n643 70 173 745\n14\n990 995\n1256 1259\n1494 1499\n1797 1804\n2443 2450\n2854 2859\n3164 3167\n4084 4092\n4615 4622\n5555 5563\n6412 6421\n7173 7180\n7566 7571\n8407 8415", "output": "1797" }, { "input": "42\n749 516 256 497 37 315 184 518 103 726 80 983 474 884 209 706 10 543 587 371 199 315 967 707 948 736 590 734 715 184 230 513 199 898 287 468 250 600 352 29 408 22\n2\n312 314\n1293 1302", "output": "-1" }, { "input": "1\n10000\n2\n1 10\n9998 10000", "output": "10000" }, { "input": "1\n547\n15\n774 779\n1598 1605\n2458 2464\n3138 3140\n3372 3378\n4268 4272\n4730 4733\n5064 5067\n5074 5075\n5483 5490\n5894 5901\n5931 5938\n6750 6756\n7487 7491\n8328 8332", "output": "774" }, { "input": "1\n10\n2\n1 2\n11 12", "output": "11" }, { "input": "2\n4 6\n2\n5 10\n15 20", "output": "10" }, { "input": "2\n16 5\n3\n5 10\n15 20\n25 30", "output": "25" }, { "input": "1\n16\n2\n5 10\n15 20", "output": "16" }, { "input": "44\n750 672 846 969 981 698 380 968 813 587 156 28 446 917 849 449 173 764 226 958 335 622 236 782 416 689 113 728 452 265 585 217 707 50 520 712 946 275 423 123 175 268 583 528\n4\n869 870\n1353 1354\n1683 1685\n2532 2540", "output": "-1" }, { "input": "1\n1\n0", "output": "-1" }, { "input": "3\n1 2 5\n3\n5 6\n7 8\n9 13", "output": "8" }, { "input": "1\n2\n0", "output": "-1" }, { "input": "1\n5\n3\n1 2\n3 4\n10 11", "output": "10" }, { "input": "1\n4\n0", "output": "-1" }, { "input": "1\n5\n0", "output": "-1" }, { "input": "1\n239\n0", "output": "-1" } ]
1,592,253,059
2,147,483,647
Python 3
OK
TESTS
29
109
307,200
import math n=int(input()) list=[int(i) for i in input().split()] some=sum(list) m=int(input()) for i in range(m): a,b=map(int,input().split()) if(some<=b): if(some<a): print(a) else: print(some) exit() print("-1")
Title: The Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in *a**i* time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment. Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during *m* time periods, *j*th period is represented by its starting moment *l**j* and ending moment *r**j*. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment *T* iff there exists a period *x* such that *l**x*<=≤<=*T*<=≤<=*r**x*. Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=105) — the time Pasha needs to solve *i*th problem. The third line contains one integer *m* (0<=≤<=*m*<=≤<=1000) — the number of periods of time when the website is working. Next *m* lines represent these periods. *j*th line contains two numbers *l**j* and *r**j* (1<=≤<=*l**j*<=&lt;<=*r**j*<=≤<=105) — the starting and the ending moment of *j*th period. It is guaranteed that the periods are not intersecting and are given in chronological order, so for every *j*<=&gt;<=1 the condition *l**j*<=&gt;<=*r**j*<=-<=1 is met. Output Specification: If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets). Demo Input: ['2\n3 4\n2\n1 4\n7 9\n', '1\n5\n1\n1 4\n', '1\n5\n1\n1 5\n'] Demo Output: ['7\n', '-1\n', '5\n'] Note: In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again. In the second example Pasha invents the solution only after the website stops working for the last time. In the third example Pasha sends the solution exactly at the end of the first period.
```python import math n=int(input()) list=[int(i) for i in input().split()] some=sum(list) m=int(input()) for i in range(m): a,b=map(int,input().split()) if(some<=b): if(some<a): print(a) else: print(some) exit() print("-1") ```
3
962
C
Make a Square
PROGRAMMING
1,400
[ "brute force", "implementation", "math" ]
null
null
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible. An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
[ "8314\n", "625\n", "333\n" ]
[ "2\n", "0\n", "-1\n" ]
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$. In the second example the given $625$ is the square of the integer $25$, so you should not delete anything. In the third example it is impossible to make the square from $333$, so the answer is -1.
0
[ { "input": "8314", "output": "2" }, { "input": "625", "output": "0" }, { "input": "333", "output": "-1" }, { "input": "1881388645", "output": "6" }, { "input": "1059472069", "output": "3" }, { "input": "1354124829", "output": "4" }, { "input": "149723943", "output": "4" }, { "input": "101", "output": "2" }, { "input": "1999967841", "output": "0" }, { "input": "2000000000", "output": "-1" }, { "input": "1999431225", "output": "0" }, { "input": "30", "output": "-1" }, { "input": "1000", "output": "1" }, { "input": "3081", "output": "2" }, { "input": "10", "output": "1" }, { "input": "2003064", "output": "3" }, { "input": "701", "output": "2" }, { "input": "1234567891", "output": "4" }, { "input": "10625", "output": "2" }, { "input": "13579", "output": "4" }, { "input": "1999999999", "output": "9" }, { "input": "150000", "output": "1" }, { "input": "8010902", "output": "3" }, { "input": "20100", "output": "2" }, { "input": "40404", "output": "2" }, { "input": "70000729", "output": "5" }, { "input": "1899933124", "output": "5" }, { "input": "1999999081", "output": "8" }, { "input": "326700", "output": "2" }, { "input": "1", "output": "0" }, { "input": "1000000990", "output": "3" }, { "input": "10000", "output": "0" }, { "input": "100001", "output": "1" }, { "input": "1410065408", "output": "7" }, { "input": "1409865409", "output": "5" }, { "input": "1000050001", "output": "3" }, { "input": "1044435556", "output": "2" }, { "input": "520993450", "output": "6" }, { "input": "131073", "output": "5" }, { "input": "500040004", "output": "6" }, { "input": "237555493", "output": "7" }, { "input": "1120671621", "output": "5" }, { "input": "298755045", "output": "5" }, { "input": "1476838469", "output": "5" }, { "input": "654921893", "output": "4" }, { "input": "1538038021", "output": "4" }, { "input": "716121445", "output": "6" }, { "input": "1894204869", "output": "5" }, { "input": "1800098866", "output": "7" }, { "input": "890665277", "output": "8" }, { "input": "1686264392", "output": "6" }, { "input": "1336639314", "output": "6" }, { "input": "132238429", "output": "5" }, { "input": "927837544", "output": "4" }, { "input": "18403955", "output": "4" }, { "input": "1668778878", "output": "8" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "4", "output": "0" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "7", "output": "-1" }, { "input": "8", "output": "-1" }, { "input": "9", "output": "0" }, { "input": "11", "output": "1" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "14", "output": "1" }, { "input": "15", "output": "1" }, { "input": "16", "output": "0" } ]
1,523,611,473
2,147,483,647
Python 3
OK
TESTS
70
280
7,372,800
def check(a, b): k = 0 asize = len(a) for j in range(asize): if a[j] == b[k]: k += 1 if k == len(b): break if k == len(b): return asize - len(b) return -1 s = input() for i in range(45000, 0, -1): d = check(s, str(i * i)) if d != -1: print(d) exit() print(-1)
Title: Make a Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible. An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes. Output Specification: If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it. Demo Input: ['8314\n', '625\n', '333\n'] Demo Output: ['2\n', '0\n', '-1\n'] Note: In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$. In the second example the given $625$ is the square of the integer $25$, so you should not delete anything. In the third example it is impossible to make the square from $333$, so the answer is -1.
```python def check(a, b): k = 0 asize = len(a) for j in range(asize): if a[j] == b[k]: k += 1 if k == len(b): break if k == len(b): return asize - len(b) return -1 s = input() for i in range(45000, 0, -1): d = check(s, str(i * i)) if d != -1: print(d) exit() print(-1) ```
3
787
A
The Monster
PROGRAMMING
1,200
[ "brute force", "math", "number theory" ]
null
null
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=.... The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100). The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100).
Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time.
[ "20 2\n9 19\n", "2 1\n16 12\n" ]
[ "82\n", "-1\n" ]
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
500
[ { "input": "20 2\n9 19", "output": "82" }, { "input": "2 1\n16 12", "output": "-1" }, { "input": "39 52\n88 78", "output": "1222" }, { "input": "59 96\n34 48", "output": "1748" }, { "input": "87 37\n91 29", "output": "211" }, { "input": "11 81\n49 7", "output": "301" }, { "input": "39 21\n95 89", "output": "3414" }, { "input": "59 70\n48 54", "output": "1014" }, { "input": "87 22\n98 32", "output": "718" }, { "input": "15 63\n51 13", "output": "-1" }, { "input": "39 7\n97 91", "output": "1255" }, { "input": "18 18\n71 71", "output": "1278" }, { "input": "46 71\n16 49", "output": "209" }, { "input": "70 11\n74 27", "output": "2321" }, { "input": "94 55\n20 96", "output": "-1" }, { "input": "18 4\n77 78", "output": "1156" }, { "input": "46 44\n23 55", "output": "-1" }, { "input": "74 88\n77 37", "output": "1346" }, { "input": "94 37\n34 7", "output": "789" }, { "input": "22 81\n80 88", "output": "-1" }, { "input": "46 30\n34 62", "output": "674" }, { "input": "40 4\n81 40", "output": "364" }, { "input": "69 48\n39 9", "output": "48" }, { "input": "89 93\n84 87", "output": "5967" }, { "input": "17 45\n42 65", "output": "317" }, { "input": "41 85\n95 46", "output": "331" }, { "input": "69 30\n41 16", "output": "1410" }, { "input": "93 74\n99 93", "output": "-1" }, { "input": "17 19\n44 75", "output": "427" }, { "input": "45 63\n98 53", "output": "3483" }, { "input": "69 11\n48 34", "output": "-1" }, { "input": "55 94\n3 96", "output": "204" }, { "input": "100 100\n100 100", "output": "100" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 1\n1 100", "output": "100" }, { "input": "1 100\n100 1", "output": "101" }, { "input": "98 1\n99 100", "output": "9703" }, { "input": "98 1\n99 2", "output": "9605" }, { "input": "97 2\n99 100", "output": "4852" }, { "input": "3 3\n3 1", "output": "-1" }, { "input": "3 2\n7 2", "output": "2" }, { "input": "2 3\n2 5", "output": "5" }, { "input": "2 3\n2 3", "output": "3" }, { "input": "100 3\n100 5", "output": "-1" }, { "input": "6 10\n12 14", "output": "-1" }, { "input": "4 2\n4 4", "output": "-1" }, { "input": "2 3\n2 2", "output": "-1" }, { "input": "2 3\n4 99", "output": "99" }, { "input": "1 5\n1 5", "output": "5" }, { "input": "1 100\n3 1", "output": "100" }, { "input": "2 2\n2 1", "output": "-1" }, { "input": "2 10\n6 20", "output": "20" }, { "input": "2 2\n2 10", "output": "10" }, { "input": "3 7\n3 6", "output": "-1" }, { "input": "1 100\n1 100", "output": "100" }, { "input": "7 25\n39 85", "output": "319" }, { "input": "84 82\n38 6", "output": "82" }, { "input": "7 7\n7 14", "output": "14" } ]
1,682,013,502
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
35
92
1,331,200
a, b = map(int, input().split()) c, d = map(int, input().split()) n = -1 for i in range(10000): tmp = d-b+i*c if tmp%a == 0: #print(tmp//a, i) n = i break if n == -1: print(-1) else: print(d+n*c)
Title: The Monster Time Limit: None seconds Memory Limit: None megabytes Problem Description: A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=.... The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time. Input Specification: The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100). The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). Output Specification: Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. Demo Input: ['20 2\n9 19\n', '2 1\n16 12\n'] Demo Output: ['82\n', '-1\n'] Note: In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
```python a, b = map(int, input().split()) c, d = map(int, input().split()) n = -1 for i in range(10000): tmp = d-b+i*c if tmp%a == 0: #print(tmp//a, i) n = i break if n == -1: print(-1) else: print(d+n*c) ```
0
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, { "input": "2 7\n1 1", "output": "1" }, { "input": "3 3\n18 1 9", "output": "10" }, { "input": "3 3\n15 17 9", "output": "3" }, { "input": "3 3\n10 9 12", "output": "2" }, { "input": "10 3\n2 1 17 10 5 16 8 4 15 17", "output": "31" }, { "input": "10 3\n6 11 4 12 22 15 23 26 24 26", "output": "13" }, { "input": "10 3\n10 24 13 15 18 14 15 26 33 35", "output": "29" }, { "input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580", "output": "15717" }, { "input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327", "output": "16133" } ]
1,442,828,263
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
1,000
0
n,d = input().split() d = int(d) def inp(s): j = 0 a = [] for i in range(len(s)): if s[i] == " ": a.append(int(s[j:i])) j = i+1 if i == len(s)-1: a.append(int(s[j:])) return a s = input() a = inp(s) c = 0 for i in range(len(a)-1): while a[i+1] <= a[i]: a[i+1] = a[i+1] + d c = c+1 print (c)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? Input Specification: The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). Output Specification: Output the minimal number of moves needed to make the sequence increasing. Demo Input: ['4 2\n1 3 3 2\n'] Demo Output: ['3\n'] Note: none
```python n,d = input().split() d = int(d) def inp(s): j = 0 a = [] for i in range(len(s)): if s[i] == " ": a.append(int(s[j:i])) j = i+1 if i == len(s)-1: a.append(int(s[j:])) return a s = input() a = inp(s) c = 0 for i in range(len(a)-1): while a[i+1] <= a[i]: a[i+1] = a[i+1] + d c = c+1 print (c) ```
0
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,620,386,239
2,147,483,647
Python 3
OK
TESTS
67
342
11,059,200
from collections import Counter n = int(input()) lookup = [input() for _ in range(n)] lookup=Counter(lookup).most_common() print(lookup[0][1])
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 from collections import Counter n = int(input()) lookup = [input() for _ in range(n)] lookup=Counter(lookup).most_common() print(lookup[0][1]) ```
3
1,006
C
Three Parts of the Array
PROGRAMMING
1,200
[ "binary search", "data structures", "two pointers" ]
null
null
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array. Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then: $$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$ The sum of an empty array is $0$. Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$. The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.
Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met. Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
[ "5\n1 3 1 1 4\n", "5\n1 3 2 1 4\n", "3\n4 1 2\n" ]
[ "5\n", "4\n", "0\n" ]
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$. In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$. In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$.
0
[ { "input": "5\n1 3 1 1 4", "output": "5" }, { "input": "5\n1 3 2 1 4", "output": "4" }, { "input": "3\n4 1 2", "output": "0" }, { "input": "1\n1000000000", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "5\n1 3 5 4 5", "output": "9" } ]
1,622,472,457
2,147,483,647
Python 3
OK
TESTS
27
343
18,329,600
n = int(input()) a = list(map(int, input().split())) s1, s2 = 0, 0 r = n ans = 0 for l in range(n): s1 += a[l] while s2 < s1: r -= 1 s2 += a[r] if s1 == s2 and r > l: ans = max(ans, s1) print(ans)
Title: Three Parts of the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array. Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then: $$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$ The sum of an empty array is $0$. Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$. The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. Output Specification: Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met. Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). Demo Input: ['5\n1 3 1 1 4\n', '5\n1 3 2 1 4\n', '3\n4 1 2\n'] Demo Output: ['5\n', '4\n', '0\n'] Note: In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$. In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$. In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$.
```python n = int(input()) a = list(map(int, input().split())) s1, s2 = 0, 0 r = n ans = 0 for l in range(n): s1 += a[l] while s2 < s1: r -= 1 s2 += a[r] if s1 == s2 and r > l: ans = max(ans, s1) print(ans) ```
3
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,680,328,238
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
n,m = map(int,input().split()) def Gcd(a,b): if b == 0: return a return Gcd(b,a%b) print(Gcd(n,m))
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python n,m = map(int,input().split()) def Gcd(a,b): if b == 0: return a return Gcd(b,a%b) print(Gcd(n,m)) ```
0
447
A
DZY Loves Hash
PROGRAMMING
800
[ "implementation" ]
null
null
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1.
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output a single integer — the answer to the problem.
[ "10 5\n0\n21\n53\n41\n53\n", "5 5\n0\n1\n2\n3\n4\n" ]
[ "4\n", "-1\n" ]
none
500
[ { "input": "10 5\n0\n21\n53\n41\n53", "output": "4" }, { "input": "5 5\n0\n1\n2\n3\n4", "output": "-1" }, { "input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537", "output": "4" }, { "input": "2 2\n788371161\n801743052", "output": "-1" }, { "input": "10 6\n812796223\n122860157\n199259103\n597650585\n447742024\n521549402", "output": "3" }, { "input": "300 2\n822454942\n119374431", "output": "-1" }, { "input": "300 2\n823284367\n507345500", "output": "-1" }, { "input": "2 5\n791579811\n35613889\n997079893\n878677665\n693717467", "output": "2" }, { "input": "20 5\n793926268\n28931770\n842870287\n974950617\n859404206", "output": "-1" }, { "input": "100 15\n805069249\n778178198\n633897389\n844316223\n146759898\n870527016\n82668754\n42060733\n943602929\n979451110\n746979598\n47406033\n607284062\n850870259\n229415316", "output": "5" }, { "input": "100 15\n806204335\n189490323\n718805086\n716787474\n262315718\n822030596\n894644222\n724054623\n141384399\n579354205\n192622443\n672556242\n97417563\n243354557\n208957882", "output": "8" }, { "input": "100 15\n807033760\n577461392\n275221433\n532633429\n295714486\n783298996\n255799943\n99107143\n729119412\n59302896\n37640015\n313610861\n630550567\n534283052\n681062462", "output": "8" }, { "input": "100 15\n808103310\n136224397\n360129131\n405104681\n263786657\n734802577\n67808179\n928584682\n926900882\n511722343\n483348395\n938695534\n120684068\n74152694\n808088675", "output": "9" }, { "input": "2 2\n2\n2", "output": "2" }, { "input": "300 2\n0\n300", "output": "2" }, { "input": "2 2\n0\n0", "output": "2" } ]
1,595,957,105
2,147,483,647
PyPy 3
OK
TESTS
29
140
20,172,800
p,n = list(map(int,input().split(" "))) l = [] for i in range(n): l.append(int(input())) s = set() for i in range(len(l)): m = l[i]%p if m in s: print(i+1) break s.add(m) else: print("-1")
Title: DZY Loves Hash Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1. Input Specification: The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). Output Specification: Output a single integer — the answer to the problem. Demo Input: ['10 5\n0\n21\n53\n41\n53\n', '5 5\n0\n1\n2\n3\n4\n'] Demo Output: ['4\n', '-1\n'] Note: none
```python p,n = list(map(int,input().split(" "))) l = [] for i in range(n): l.append(int(input())) s = set() for i in range(len(l)): m = l[i]%p if m in s: print(i+1) break s.add(m) else: print("-1") ```
3
816
A
Karen and Morning
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome? Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59).
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
[ "05:39\n", "13:31\n", "23:59\n" ]
[ "11\n", "0\n", "1\n" ]
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome. In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
500
[ { "input": "05:39", "output": "11" }, { "input": "13:31", "output": "0" }, { "input": "23:59", "output": "1" }, { "input": "13:32", "output": "69" }, { "input": "14:40", "output": "1" }, { "input": "14:00", "output": "41" }, { "input": "05:50", "output": "0" }, { "input": "12:22", "output": "69" }, { "input": "12:34", "output": "57" }, { "input": "05:30", "output": "20" }, { "input": "14:14", "output": "27" }, { "input": "01:10", "output": "0" }, { "input": "02:20", "output": "0" }, { "input": "03:30", "output": "0" }, { "input": "04:40", "output": "0" }, { "input": "10:01", "output": "0" }, { "input": "11:11", "output": "0" }, { "input": "12:21", "output": "0" }, { "input": "14:41", "output": "0" }, { "input": "15:51", "output": "0" }, { "input": "20:02", "output": "0" }, { "input": "21:12", "output": "0" }, { "input": "22:22", "output": "0" }, { "input": "23:32", "output": "0" }, { "input": "01:11", "output": "69" }, { "input": "02:21", "output": "69" }, { "input": "03:31", "output": "69" }, { "input": "04:41", "output": "69" }, { "input": "05:51", "output": "250" }, { "input": "10:02", "output": "69" }, { "input": "11:12", "output": "69" }, { "input": "14:42", "output": "69" }, { "input": "15:52", "output": "250" }, { "input": "20:03", "output": "69" }, { "input": "21:13", "output": "69" }, { "input": "22:23", "output": "69" }, { "input": "23:33", "output": "27" }, { "input": "00:00", "output": "0" }, { "input": "00:01", "output": "69" }, { "input": "22:21", "output": "1" }, { "input": "20:01", "output": "1" }, { "input": "11:10", "output": "1" }, { "input": "06:59", "output": "182" }, { "input": "02:00", "output": "20" }, { "input": "02:19", "output": "1" }, { "input": "17:31", "output": "151" }, { "input": "19:00", "output": "62" }, { "input": "13:37", "output": "64" }, { "input": "07:59", "output": "122" }, { "input": "04:20", "output": "20" }, { "input": "07:10", "output": "171" }, { "input": "06:00", "output": "241" }, { "input": "06:01", "output": "240" }, { "input": "08:15", "output": "106" }, { "input": "06:59", "output": "182" }, { "input": "01:00", "output": "10" }, { "input": "07:00", "output": "181" }, { "input": "06:10", "output": "231" }, { "input": "18:52", "output": "70" }, { "input": "09:59", "output": "2" }, { "input": "19:00", "output": "62" }, { "input": "15:52", "output": "250" }, { "input": "06:50", "output": "191" }, { "input": "00:00", "output": "0" }, { "input": "19:20", "output": "42" }, { "input": "05:51", "output": "250" }, { "input": "06:16", "output": "225" }, { "input": "10:10", "output": "61" }, { "input": "17:11", "output": "171" }, { "input": "18:00", "output": "122" }, { "input": "00:01", "output": "69" }, { "input": "05:04", "output": "46" }, { "input": "16:00", "output": "242" }, { "input": "23:31", "output": "1" }, { "input": "17:25", "output": "157" }, { "input": "23:32", "output": "0" }, { "input": "23:58", "output": "2" }, { "input": "02:21", "output": "69" }, { "input": "01:11", "output": "69" }, { "input": "23:46", "output": "14" }, { "input": "00:09", "output": "61" }, { "input": "09:20", "output": "41" }, { "input": "05:59", "output": "242" }, { "input": "18:59", "output": "63" }, { "input": "02:02", "output": "18" }, { "input": "00:30", "output": "40" }, { "input": "05:54", "output": "247" }, { "input": "19:59", "output": "3" }, { "input": "16:59", "output": "183" }, { "input": "17:51", "output": "131" }, { "input": "09:30", "output": "31" }, { "input": "10:01", "output": "0" }, { "input": "16:55", "output": "187" }, { "input": "20:02", "output": "0" }, { "input": "16:12", "output": "230" }, { "input": "20:00", "output": "2" }, { "input": "01:01", "output": "9" }, { "input": "23:01", "output": "31" }, { "input": "06:05", "output": "236" }, { "input": "19:19", "output": "43" }, { "input": "17:00", "output": "182" }, { "input": "07:50", "output": "131" }, { "input": "21:20", "output": "62" }, { "input": "23:23", "output": "9" }, { "input": "19:30", "output": "32" }, { "input": "00:59", "output": "11" }, { "input": "22:59", "output": "33" }, { "input": "18:18", "output": "104" }, { "input": "17:46", "output": "136" }, { "input": "07:30", "output": "151" }, { "input": "17:16", "output": "166" }, { "input": "06:06", "output": "235" }, { "input": "23:30", "output": "2" }, { "input": "05:57", "output": "244" }, { "input": "19:46", "output": "16" }, { "input": "11:10", "output": "1" }, { "input": "17:07", "output": "175" }, { "input": "18:53", "output": "69" }, { "input": "07:06", "output": "175" }, { "input": "17:50", "output": "132" }, { "input": "09:15", "output": "46" }, { "input": "09:55", "output": "6" }, { "input": "20:05", "output": "67" }, { "input": "22:55", "output": "37" }, { "input": "10:00", "output": "1" }, { "input": "07:55", "output": "126" }, { "input": "07:40", "output": "141" }, { "input": "19:08", "output": "54" }, { "input": "23:24", "output": "8" }, { "input": "16:15", "output": "227" }, { "input": "07:20", "output": "161" }, { "input": "23:10", "output": "22" }, { "input": "06:51", "output": "190" }, { "input": "16:30", "output": "212" }, { "input": "17:54", "output": "128" }, { "input": "07:07", "output": "174" }, { "input": "08:01", "output": "120" }, { "input": "09:58", "output": "3" }, { "input": "18:03", "output": "119" }, { "input": "07:59", "output": "122" }, { "input": "05:55", "output": "246" }, { "input": "07:39", "output": "142" }, { "input": "05:52", "output": "249" }, { "input": "12:02", "output": "19" }, { "input": "08:59", "output": "62" }, { "input": "09:21", "output": "40" }, { "input": "16:04", "output": "238" }, { "input": "04:00", "output": "40" }, { "input": "18:21", "output": "101" }, { "input": "09:13", "output": "48" }, { "input": "17:20", "output": "162" }, { "input": "06:15", "output": "226" }, { "input": "19:21", "output": "41" }, { "input": "16:02", "output": "240" }, { "input": "15:59", "output": "243" }, { "input": "06:07", "output": "234" }, { "input": "08:08", "output": "113" }, { "input": "09:09", "output": "52" }, { "input": "02:19", "output": "1" }, { "input": "21:59", "output": "23" } ]
1,503,151,740
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
28
77
0
s=list(map(int,input().split(':'))) a=s[0]%10*10+s[0]//10 if s[1]<=a: print(a-s[1]) elif s[0]==23: print(60-s[1]) elif s[0]%10<5 or s[0]%10>8: print(60-s[1]+a+10) else: print(60-s[1]+2+60*(9-s[0]%10)) #print(' '.join([str(i) for i in s]))
Title: Karen and Morning Time Limit: None seconds Memory Limit: None megabytes Problem Description: Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome? Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50. Input Specification: The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59). Output Specification: Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome. Demo Input: ['05:39\n', '13:31\n', '23:59\n'] Demo Output: ['11\n', '0\n', '1\n'] Note: In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome. In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
```python s=list(map(int,input().split(':'))) a=s[0]%10*10+s[0]//10 if s[1]<=a: print(a-s[1]) elif s[0]==23: print(60-s[1]) elif s[0]%10<5 or s[0]%10>8: print(60-s[1]+a+10) else: print(60-s[1]+2+60*(9-s[0]%10)) #print(' '.join([str(i) for i in s])) ```
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,564,339,501
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
108
0
s = input() a = s.find('h') b = s.find('e', a, -1) c = s.find('l', b, -1) d = s.find('l', c, -1) e = s.find('o', d, -1) if a>=0 and b>=0 and c>=0 and e>=0 and d>=0: print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s = input() a = s.find('h') b = s.find('e', a, -1) c = s.find('l', b, -1) d = s.find('l', c, -1) e = s.find('o', d, -1) if a>=0 and b>=0 and c>=0 and e>=0 and d>=0: print('YES') else: print('NO') ```
0
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,577,154,712
2,147,483,647
Python 3
OK
TESTS
18
124
0
def fun(n): return sum(int(n[i]) for i in range (0,len(n))) n=int(input()) p=[] for i in range (1,min(100,n+1)): if i==fun(str(n-i)): p.append(n-i) p=sorted(p) print(len(p)) for i in range (0,len(p)): print(p[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 def fun(n): return sum(int(n[i]) for i in range (0,len(n))) n=int(input()) p=[] for i in range (1,min(100,n+1)): if i==fun(str(n-i)): p.append(n-i) p=sorted(p) print(len(p)) for i in range (0,len(p)): print(p[i]) ```
3
991
B
Getting an A
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
[ "3\n4 4 4\n", "4\n5 4 5 5\n", "4\n5 3 3 5\n" ]
[ "2\n", "0\n", "1\n" ]
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
1,000
[ { "input": "3\n4 4 4", "output": "2" }, { "input": "4\n5 4 5 5", "output": "0" }, { "input": "4\n5 3 3 5", "output": "1" }, { "input": "1\n5", "output": "0" }, { "input": "4\n3 2 5 4", "output": "2" }, { "input": "5\n5 4 3 2 5", "output": "2" }, { "input": "8\n5 4 2 5 5 2 5 5", "output": "1" }, { "input": "5\n5 5 2 5 5", "output": "1" }, { "input": "6\n5 5 5 5 5 2", "output": "0" }, { "input": "6\n2 2 2 2 2 2", "output": "5" }, { "input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4", "output": "40" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n4", "output": "1" }, { "input": "4\n3 2 5 5", "output": "1" }, { "input": "6\n4 3 3 3 3 4", "output": "4" }, { "input": "8\n3 3 5 3 3 3 5 5", "output": "3" }, { "input": "10\n2 4 5 5 5 5 2 3 3 2", "output": "3" }, { "input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2", "output": "10" }, { "input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4", "output": "13" }, { "input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2", "output": "15" }, { "input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5", "output": "14" }, { "input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2", "output": "33" }, { "input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4", "output": "34" }, { "input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5", "output": "16" }, { "input": "99\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", "output": "83" }, { "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": "84" }, { "input": "99\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", "output": "75" }, { "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": "75" }, { "input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3", "output": "75" }, { "input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2", "output": "75" }, { "input": "99\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "50" }, { "input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "50" }, { "input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4", "output": "54" }, { "input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4", "output": "50" }, { "input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3", "output": "51" }, { "input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4", "output": "51" }, { "input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3", "output": "58" }, { "input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3", "output": "61" }, { "input": "99\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5", "output": "48" }, { "input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5", "output": "38" }, { "input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3", "output": "32" }, { "input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5", "output": "32" }, { "input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3", "output": "39" }, { "input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2", "output": "42" }, { "input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4", "output": "0" }, { "input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4", "output": "1" }, { "input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4", "output": "37" }, { "input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2", "output": "31" }, { "input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3", "output": "24" }, { "input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5", "output": "19" }, { "input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4", "output": "37" }, { "input": "2\n5 2", "output": "1" }, { "input": "5\n2 2 2 2 2", "output": "5" }, { "input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2", "output": "61" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "1" }, { "input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5", "output": "35" }, { "input": "2\n2 2", "output": "2" }, { "input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5", "output": "1" } ]
1,643,291,512
2,147,483,647
Python 3
OK
TESTS
61
61
0
a = int(input()) nota = (list(map(int,input().split()))) count = 0 while sum(nota) / len(nota) < 4.5: nota = sorted(nota) nota[0] = 5 count += 1 print(count)
Title: Getting an A Time Limit: None seconds Memory Limit: None megabytes Problem Description: Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo. Input Specification: The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. Output Specification: Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. Demo Input: ['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
```python a = int(input()) nota = (list(map(int,input().split()))) count = 0 while sum(nota) / len(nota) < 4.5: nota = sorted(nota) nota[0] = 5 count += 1 print(count) ```
3