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
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz", "output": "105" }, { "input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g", "output": "1" }, { "input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez", "output": "50" }, { "input": "1\ne", "output": "0" }, { "input": "1\nA", "output": "1" }, { "input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ", "output": "10" }, { "input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "200" }, { "input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "output": "0" }, { "input": "24\nHarbour Space UniversitY", "output": "2" }, { "input": "5\naA AA", "output": "2" }, { "input": "10\nas AS ASDA", "output": "4" }, { "input": "10\nas AS ASDZ", "output": "4" }, { "input": "3\na A", "output": "1" }, { "input": "24\nHarbour space UniversitY", "output": "2" }, { "input": "10\nas AS ASAa", "output": "3" }, { "input": "15\naAb ABCDFGRHTJS", "output": "11" }, { "input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR", "output": "6" }, { "input": "10\nABC ABc AB", "output": "3" }, { "input": "10\nA c de CDE", "output": "3" }, { "input": "4\nA AB", "output": "2" }, { "input": "18\nHARbour Space UNIV", "output": "4" }, { "input": "13\na b c d e f A", "output": "1" }, { "input": "6\nA B CA", "output": "2" }, { "input": "4\naa A", "output": "1" }, { "input": "3\nA a", "output": "1" } ]
1,650,639,186
2,147,483,647
Python 3
OK
TESTS
29
46
0
a = set() a.add(0) n = int(input()) s = input().split() c = 0 for i in s: for j in i: if j.isupper(): c+=1 a.add(c) c = 0 a = sorted(a) print(a[-1])
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. Output Specification: Print one integer number — volume of text. Demo Input: ['7\nNonZERO\n', '24\nthis is zero answer text\n', '24\nHarbour Space University\n'] Demo Output: ['5\n', '0\n', '1\n'] Note: In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
```python a = set() a.add(0) n = int(input()) s = input().split() c = 0 for i in s: for j in i: if j.isupper(): c+=1 a.add(c) c = 0 a = sorted(a) print(a[-1]) ```
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,616,153,094
2,147,483,647
Python 3
OK
TESTS
28
62
0
a, b = 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 = input().split() print(a if a == b else 1) ```
3
883
M
Quadcopter Competition
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1). Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside. What is the minimal length of the quadcopter path?
The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter starting point and the flag do not coincide.
Print the length of minimal path of the quadcopter to surround the flag and return back.
[ "1 5\n5 2\n", "0 1\n0 0\n" ]
[ "18\n", "8\n" ]
none
0
[ { "input": "1 5\n5 2", "output": "18" }, { "input": "0 1\n0 0", "output": "8" }, { "input": "-100 -100\n100 100", "output": "804" }, { "input": "-100 -100\n-100 100", "output": "406" }, { "input": "-100 -100\n100 -100", "output": "406" }, { "input": "100 -100\n-100 -100", "output": "406" }, { "input": "100 -100\n-100 100", "output": "804" }, { "input": "100 -100\n100 100", "output": "406" }, { "input": "-100 100\n-100 -100", "output": "406" }, { "input": "-100 100\n100 -100", "output": "804" }, { "input": "-100 100\n100 100", "output": "406" }, { "input": "100 100\n-100 -100", "output": "804" }, { "input": "100 100\n-100 100", "output": "406" }, { "input": "100 100\n100 -100", "output": "406" }, { "input": "45 -43\n45 -44", "output": "8" }, { "input": "76 76\n75 75", "output": "8" }, { "input": "-34 -56\n-35 -56", "output": "8" }, { "input": "56 -7\n55 -6", "output": "8" }, { "input": "43 -11\n43 -10", "output": "8" }, { "input": "1 -3\n2 -2", "output": "8" }, { "input": "55 71\n56 71", "output": "8" }, { "input": "54 -87\n55 -88", "output": "8" }, { "input": "22 98\n100 33", "output": "290" }, { "input": "37 84\n-83 5", "output": "402" }, { "input": "52 74\n-73 -39", "output": "480" }, { "input": "66 51\n51 -71", "output": "278" }, { "input": "-31 44\n73 86", "output": "296" }, { "input": "-20 34\n-9 55", "output": "68" }, { "input": "-5 19\n-91 -86", "output": "386" }, { "input": "-82 5\n28 -17", "output": "268" }, { "input": "-90 -100\n55 48", "output": "590" }, { "input": "-75 -14\n-32 8", "output": "134" }, { "input": "-53 -28\n-13 -28", "output": "86" }, { "input": "-42 -46\n10 -64", "output": "144" }, { "input": "55 -42\n25 2", "output": "152" }, { "input": "70 -64\n-54 70", "output": "520" }, { "input": "93 -78\n-32 -75", "output": "260" }, { "input": "8 -93\n79 -6", "output": "320" }, { "input": "50 43\n54 10", "output": "78" }, { "input": "65 32\n-37 71", "output": "286" }, { "input": "80 18\n-15 -58", "output": "346" }, { "input": "94 92\n4 -1", "output": "370" }, { "input": "-10 96\n27 64", "output": "142" }, { "input": "-96 78\n-56 32", "output": "176" }, { "input": "-81 64\n-37 -8", "output": "236" }, { "input": "-58 49\n74 -40", "output": "446" }, { "input": "-62 -55\n1 18", "output": "276" }, { "input": "-51 -69\n-78 86", "output": "368" }, { "input": "-29 -80\n-56 -47", "output": "124" }, { "input": "-14 -94\n55 -90", "output": "150" }, { "input": "83 -2\n82 83", "output": "176" }, { "input": "98 -16\n-96 40", "output": "504" }, { "input": "17 -34\n-86 -93", "output": "328" }, { "input": "32 -48\n33 -37", "output": "28" }, { "input": "74 87\n3 92", "output": "156" }, { "input": "89 73\n-80 49", "output": "390" }, { "input": "4 58\n-61 -80", "output": "410" }, { "input": "15 48\n50 -20", "output": "210" }, { "input": "-82 45\n81 46", "output": "332" }, { "input": "-68 26\n-2 6", "output": "176" }, { "input": "-53 4\n-92 -31", "output": "152" }, { "input": "-30 94\n31 -58", "output": "430" }, { "input": "-38 -11\n58 99", "output": "416" }, { "input": "-27 -25\n-28 68", "output": "192" }, { "input": "-5 -39\n-10 -77", "output": "90" }, { "input": "-90 -54\n9 -9", "output": "292" }, { "input": "7 -57\n28 61", "output": "282" }, { "input": "18 -67\n-51 21", "output": "318" }, { "input": "41 -82\n-33 -15", "output": "286" }, { "input": "56 -8\n91 -55", "output": "168" }, { "input": "-23 -13\n-24 -12", "output": "8" }, { "input": "1 32\n1 33", "output": "8" }, { "input": "25 76\n24 76", "output": "8" }, { "input": "-29 -78\n-28 -79", "output": "8" }, { "input": "-77 19\n-76 19", "output": "8" }, { "input": "-53 63\n-53 62", "output": "8" }, { "input": "86 12\n86 11", "output": "8" }, { "input": "14 56\n13 56", "output": "8" }, { "input": "63 41\n62 40", "output": "8" }, { "input": "0 -4\n1 -4", "output": "8" }, { "input": "24 41\n24 42", "output": "8" }, { "input": "48 85\n49 86", "output": "8" }, { "input": "0 0\n0 1", "output": "8" }, { "input": "0 0\n1 0", "output": "8" }, { "input": "0 0\n1 1", "output": "8" }, { "input": "0 1\n0 0", "output": "8" }, { "input": "0 1\n1 0", "output": "8" }, { "input": "0 1\n1 1", "output": "8" }, { "input": "1 0\n0 0", "output": "8" }, { "input": "1 0\n0 1", "output": "8" }, { "input": "1 0\n1 1", "output": "8" }, { "input": "1 1\n0 0", "output": "8" }, { "input": "1 1\n0 1", "output": "8" }, { "input": "1 1\n1 0", "output": "8" }, { "input": "100 100\n99 -100", "output": "406" }, { "input": "100 100\n-100 99", "output": "406" }, { "input": "-100 -100\n-99 100", "output": "406" }, { "input": "-100 -100\n100 -99", "output": "406" }, { "input": "0 0\n1 2", "output": "10" }, { "input": "0 0\n2 1", "output": "10" } ]
1,508,843,356
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
4,608,000
x,y=map(int,input().split()) m,n=map(int,input().split()) print(abs(x-m)*2+abs(y-n)*2+4)
Title: Quadcopter Competition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1). Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside. What is the minimal length of the quadcopter path? Input Specification: The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter starting point and the flag do not coincide. Output Specification: Print the length of minimal path of the quadcopter to surround the flag and return back. Demo Input: ['1 5\n5 2\n', '0 1\n0 0\n'] Demo Output: ['18\n', '8\n'] Note: none
```python x,y=map(int,input().split()) m,n=map(int,input().split()) print(abs(x-m)*2+abs(y-n)*2+4) ```
0
578
B
"Or" Game
PROGRAMMING
1,700
[ "brute force", "greedy" ]
null
null
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally.
The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output the maximum value of a bitwise OR of sequence elements after performing operations.
[ "3 1 2\n1 1 1\n", "4 2 3\n1 2 4 8\n" ]
[ "3\n", "79\n" ]
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
500
[ { "input": "3 1 2\n1 1 1", "output": "3" }, { "input": "4 2 3\n1 2 4 8", "output": "79" }, { "input": "2 1 2\n12 9", "output": "30" }, { "input": "2 1 2\n12 7", "output": "31" }, { "input": "3 1 3\n3 2 0", "output": "11" }, { "input": "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1073741825000000000" }, { "input": "1 2 3\n612635770", "output": "5513721930" }, { "input": "3 2 5\n0 2 3", "output": "75" }, { "input": "2 1 8\n18 17", "output": "154" }, { "input": "5 10 8\n0 0 0 0 0", "output": "0" }, { "input": "1 1 2\n1", "output": "2" }, { "input": "1 1 2\n0", "output": "0" }, { "input": "3 2 6\n724148075 828984987 810015532", "output": "29996605423" }, { "input": "3 1 2\n17 18 4", "output": "54" }, { "input": "3 1 2\n4 17 18", "output": "54" }, { "input": "2 2 2\n60 59", "output": "252" }, { "input": "2 2 2\n9 10", "output": "46" }, { "input": "3 1 2\n10 12 5", "output": "31" }, { "input": "3 1 2\n20 17 8", "output": "62" }, { "input": "3 1 2\n5 12 10", "output": "31" }, { "input": "3 1 8\n10 17 18", "output": "155" }, { "input": "3 1 2\n17 20 28", "output": "62" }, { "input": "5 1 3\n1 5 13 8 16", "output": "63" } ]
1,695,837,149
2,147,483,647
PyPy 3-64
OK
TESTS
32
140
31,641,600
n, k, x = map(int, input().split()) x = x**k left_or = [None]*(n) right_or = [None]*(n) a = list(map(int, input().split())) current_or = 0 for i in range(n): current_or |= a[i] left_or[i] = current_or current_or = 0 for i in range(n-1, -1, -1): current_or |= a[i] right_or[i] = current_or best_res = 0 for i in range(n): res = a[i]*x if i != 0: res |= left_or[i-1] if i != n-1: res |= right_or[i+1] best_res = max(res, best_res) print(best_res)
Title: "Or" Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. Input Specification: The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: Output the maximum value of a bitwise OR of sequence elements after performing operations. Demo Input: ['3 1 2\n1 1 1\n', '4 2 3\n1 2 4 8\n'] Demo Output: ['3\n', '79\n'] Note: For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
```python n, k, x = map(int, input().split()) x = x**k left_or = [None]*(n) right_or = [None]*(n) a = list(map(int, input().split())) current_or = 0 for i in range(n): current_or |= a[i] left_or[i] = current_or current_or = 0 for i in range(n-1, -1, -1): current_or |= a[i] right_or[i] = current_or best_res = 0 for i in range(n): res = a[i]*x if i != 0: res |= left_or[i-1] if i != n-1: res |= right_or[i+1] best_res = max(res, best_res) print(best_res) ```
3
312
B
Archer
PROGRAMMING
1,300
[ "math", "probabilities" ]
null
null
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match.
A single line contains four integers .
Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "1 2 1 2\n" ]
[ "0.666666666667" ]
none
1,000
[ { "input": "1 2 1 2", "output": "0.666666666667" }, { "input": "1 3 1 3", "output": "0.600000000000" }, { "input": "1 3 2 3", "output": "0.428571428571" }, { "input": "3 4 3 4", "output": "0.800000000000" }, { "input": "1 2 10 11", "output": "0.523809523810" }, { "input": "4 5 4 5", "output": "0.833333333333" }, { "input": "466 701 95 721", "output": "0.937693791148" }, { "input": "268 470 444 885", "output": "0.725614009325" }, { "input": "632 916 713 821", "output": "0.719292895126" }, { "input": "269 656 918 992", "output": "0.428937461623" }, { "input": "71 657 187 695", "output": "0.310488463257" }, { "input": "435 852 973 978", "output": "0.511844133157" }, { "input": "518 816 243 359", "output": "0.719734031025" }, { "input": "882 962 311 811", "output": "0.966386645447" }, { "input": "684 774 580 736", "output": "0.906051574446" }, { "input": "486 868 929 999", "output": "0.577723252958" }, { "input": "132 359 996 998", "output": "0.368154532345" }, { "input": "933 977 266 450", "output": "0.972879407907" }, { "input": "298 833 615 872", "output": "0.441270817024" }, { "input": "34 554 14 958", "output": "0.817324099167" }, { "input": "836 934 800 905", "output": "0.906105535462" }, { "input": "482 815 69 509", "output": "0.914365577772" }, { "input": "284 423 137 521", "output": "0.885974839378" }, { "input": "648 881 486 703", "output": "0.800911421248" }, { "input": "450 885 755 836", "output": "0.533901011176" }, { "input": "533 773 823 998", "output": "0.729222130525" }, { "input": "897 957 92 898", "output": "0.993193806364" }, { "input": "699 925 441 928", "output": "0.866816866175" }, { "input": "64 704 148 603", "output": "0.289486317811" }, { "input": "719 735 626 990", "output": "0.986124079764" }, { "input": "1 1000 1 1000", "output": "0.500250125063" } ]
1,658,151,116
2,147,483,647
PyPy 3-64
OK
TESTS
31
62
0
import sys import math import collections import heapq input=sys.stdin.readline a,b,c,d=(int(i) for i in input().split()) k1=1-(a/b) k2=1-(c/d) print((1-k1)/(1-k1*k2))
Title: Archer Time Limit: None seconds Memory Limit: None megabytes Problem Description: SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input Specification: A single line contains four integers . Output Specification: Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. Demo Input: ['1 2 1 2\n'] Demo Output: ['0.666666666667'] Note: none
```python import sys import math import collections import heapq input=sys.stdin.readline a,b,c,d=(int(i) for i in input().split()) k1=1-(a/b) k2=1-(c/d) print((1-k1)/(1-k1*k2)) ```
3
975
A
Aramic script
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script. The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$. It is guaranteed that all characters of the strings are small latin letters.
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
[ "5\na aa aaa ab abb\n", "3\namer arem mrea\n" ]
[ "2", "1" ]
In the first test, there are two objects mentioned. The roots that represent them are "a","ab". In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
500
[ { "input": "5\na aa aaa ab abb", "output": "2" }, { "input": "3\namer arem mrea", "output": "1" }, { "input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd", "output": "6" }, { "input": "2\nfhjlqs aceginpr", "output": "2" }, { "input": "2\nbcdfghimn efghijlmo", "output": "2" } ]
1,526,092,001
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
24
1,000
10,035,200
def checkList(arr,word): for i in arr: if i == word: return True return False def getRoot(word): newWord = "" for i in range(26): if checkList(word,chr(i+97)): newWord += chr(i+97) return newWord num = int(input()) array = input().split(' ') roots = [] for i in array: if not checkList(roots,getRoot(i)): roots.append(getRoot(i)) print(len(roots))
Title: Aramic script Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script? Input Specification: The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script. The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$. It is guaranteed that all characters of the strings are small latin letters. Output Specification: Output one integer — the number of different objects mentioned in the given ancient Aramic script. Demo Input: ['5\na aa aaa ab abb\n', '3\namer arem mrea\n'] Demo Output: ['2', '1'] Note: In the first test, there are two objects mentioned. The roots that represent them are "a","ab". In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
```python def checkList(arr,word): for i in arr: if i == word: return True return False def getRoot(word): newWord = "" for i in range(26): if checkList(word,chr(i+97)): newWord += chr(i+97) return newWord num = int(input()) array = input().split(' ') roots = [] for i in array: if not checkList(roots,getRoot(i)): roots.append(getRoot(i)) print(len(roots)) ```
0
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "534204", "output": "106841" }, { "input": "469569", "output": "93914" }, { "input": "502877", "output": "100576" }, { "input": "942212", "output": "188443" }, { "input": "97", "output": "20" }, { "input": "53", "output": "11" }, { "input": "89", "output": "18" }, { "input": "574", "output": "115" }, { "input": "716", "output": "144" }, { "input": "729", "output": "146" }, { "input": "8901", "output": "1781" }, { "input": "3645", "output": "729" }, { "input": "4426", "output": "886" }, { "input": "46573", "output": "9315" }, { "input": "86380", "output": "17276" }, { "input": "94190", "output": "18838" }, { "input": "999990", "output": "199998" }, { "input": "999991", "output": "199999" }, { "input": "999992", "output": "199999" }, { "input": "999993", "output": "199999" }, { "input": "999994", "output": "199999" }, { "input": "999995", "output": "199999" }, { "input": "999996", "output": "200000" }, { "input": "999997", "output": "200000" }, { "input": "999998", "output": "200000" } ]
1,699,365,538
2,147,483,647
PyPy 3-64
OK
TESTS
34
62
0
n = int(input()) r = n %5 q = n // 5 if r == 0: print(q) else: print(q+1)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. Input Specification: The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. Output Specification: Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. Demo Input: ['5\n', '12\n'] Demo Output: ['1\n', '3\n'] Note: In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
```python n = int(input()) r = n %5 q = n // 5 if r == 0: print(q) else: print(q+1) ```
3
725
A
Jumping Ball
PROGRAMMING
1,000
[ "implementation" ]
null
null
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '&gt;', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '&lt;'. If there is no such position, in other words if *i*<=-<=1<=&lt;<=1 or *i*<=+<=1<=&gt;<=*n*, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
[ "4\n&lt;&lt;&gt;&lt;\n", "5\n&gt;&gt;&gt;&gt;&gt;\n", "4\n&gt;&gt;&lt;&lt;\n" ]
[ "2", "5", "0" ]
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
500
[ { "input": "4\n<<><", "output": "2" }, { "input": "5\n>>>>>", "output": "5" }, { "input": "4\n>><<", "output": "0" }, { "input": "3\n<<>", "output": "3" }, { "input": "3\n<<<", "output": "3" }, { "input": "3\n><<", "output": "0" }, { "input": "1\n<", "output": "1" }, { "input": "2\n<>", "output": "2" }, { "input": "3\n<>>", "output": "3" }, { "input": "3\n><>", "output": "1" }, { "input": "2\n><", "output": "0" }, { "input": "2\n>>", "output": "2" }, { "input": "2\n<<", "output": "2" }, { "input": "1\n>", "output": "1" }, { "input": "3\n>><", "output": "0" }, { "input": "3\n>>>", "output": "3" }, { "input": "3\n<><", "output": "1" }, { "input": "10\n<<<><<<>>>", "output": "6" }, { "input": "20\n><><<><<<>>>>>>>>>>>", "output": "11" }, { "input": "20\n<<<<<<<<<<><<<<>>>>>", "output": "15" }, { "input": "50\n<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>", "output": "50" }, { "input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>", "output": "49" }, { "input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><", "output": "50" }, { "input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", "output": "100" }, { "input": "100\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "output": "100" }, { "input": "12\n<<>><<>><<>>", "output": "4" }, { "input": "6\n<<><>>", "output": "4" }, { "input": "6\n><>>>>", "output": "4" }, { "input": "8\n>>>><<<>", "output": "1" }, { "input": "4\n<><>", "output": "2" }, { "input": "4\n><><", "output": "0" }, { "input": "7\n<<>>><>", "output": "3" }, { "input": "10\n><><>>>>>>", "output": "6" }, { "input": "5\n<><>>", "output": "3" }, { "input": "12\n<><<<<>>>>>>", "output": "7" }, { "input": "6\n<>><<>", "output": "2" }, { "input": "6\n>>><>>", "output": "2" }, { "input": "10\n><><>>>><>", "output": "1" }, { "input": "5\n><>>>", "output": "3" }, { "input": "5\n<<><>", "output": "3" }, { "input": "5\n<><<<", "output": "1" }, { "input": "4\n<><<", "output": "1" }, { "input": "8\n<<>><<>>", "output": "4" }, { "input": "7\n<<><>>>", "output": "5" }, { "input": "5\n><<>>", "output": "2" }, { "input": "10\n<<<<<>>>>>", "output": "10" }, { "input": "6\n><<<<<", "output": "0" }, { "input": "8\n<<><><>>", "output": "4" }, { "input": "10\n<<<<><<<><", "output": "4" }, { "input": "12\n<<<>>>><<>>>", "output": "6" }, { "input": "4\n><>>", "output": "2" }, { "input": "11\n<<><<>><<>>", "output": "4" } ]
1,477,148,929
229
Python 3
OK
TESTS
78
62
614,400
n = int(input() ) s = input() pos = s.find("><") if pos == -1 : print(n) else : ans = 0 for i in s : if i == '>' : break; else : ans += 1; for i in range(n-1,-1,-1) : t = s[i] if t=="<" : break; else : ans += 1; print(ans)
Title: Jumping Ball Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '&gt;', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '&lt;'. If there is no such position, in other words if *i*<=-<=1<=&lt;<=1 or *i*<=+<=1<=&gt;<=*n*, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. Output Specification: Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Demo Input: ['4\n&lt;&lt;&gt;&lt;\n', '5\n&gt;&gt;&gt;&gt;&gt;\n', '4\n&gt;&gt;&lt;&lt;\n'] Demo Output: ['2', '5', '0'] Note: In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
```python n = int(input() ) s = input() pos = s.find("><") if pos == -1 : print(n) else : ans = 0 for i in s : if i == '>' : break; else : ans += 1; for i in range(n-1,-1,-1) : t = s[i] if t=="<" : break; else : ans += 1; print(ans) ```
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,587,792,277
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
6
187
2,150,400
n=int(input()) num=['o']*n num[0]=num[1]='O' a=b=1 while a+b-1<n: num[a+b-1]='O' c=b b=a+b a=c print(*num,sep='')
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()) num=['o']*n num[0]=num[1]='O' a=b=1 while a+b-1<n: num[a+b-1]='O' c=b b=a+b a=c print(*num,sep='') ```
-1
569
B
Inventory
PROGRAMMING
1,200
[ "greedy", "math" ]
null
null
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal.
The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items.
Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
[ "3\n1 3 2\n", "4\n2 2 3 3\n", "1\n2\n" ]
[ "1 3 2 \n", "2 1 3 4 \n", "1 \n" ]
In the first test the numeration is already a permutation, so there is no need to change anything. In the second test there are two pairs of equal numbers, in each pair you need to replace one number. In the third test you need to replace 2 by 1, as the numbering should start from one.
1,000
[ { "input": "3\n1 3 2", "output": "1 3 2 " }, { "input": "4\n2 2 3 3", "output": "2 1 3 4 " }, { "input": "1\n2", "output": "1 " }, { "input": "3\n3 3 1", "output": "3 2 1 " }, { "input": "5\n1 1 1 1 1", "output": "1 2 3 4 5 " }, { "input": "5\n5 3 4 4 2", "output": "5 3 4 1 2 " }, { "input": "5\n19 11 8 8 10", "output": "1 2 3 4 5 " }, { "input": "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2", "output": "2 4 1 5 6 7 3 8 9 10 11 12 13 14 15 " }, { "input": "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9", "output": "3 11 5 9 10 4 6 12 13 7 14 1 8 15 16 2 17 18 " }, { "input": "42\n999 863 440 1036 1186 908 330 265 382 417 858 286 834 922 42 569 79 158 312 1175 1069 188 21 1207 985 375 59 417 256 595 732 742 629 737 25 699 484 517 37 1134 472 720", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 42 15 16 17 18 19 20 22 21 23 24 26 27 28 29 30 31 32 33 34 25 35 36 38 37 39 40 41 " }, { "input": "111\n15 45 14 65 49 25 102 86 14 80 54 73 43 78 42 32 47 60 55 66 84 69 49 22 26 72 89 52 26 80 71 35 56 2 88 23 23 53 65 92 46 73 29 65 88 99 19 99 87 10 47 96 109 20 60 89 63 105 29 92 109 20 95 65 31 89 107 3 3 50 58 9 28 39 104 42 41 36 70 49 59 96 16 9 3 108 38 42 2 67 32 86 20 6 101 70 101 91 38 10 74 3 27 15 103 63 51 60 62 10 70", "output": "15 45 14 65 49 25 102 86 1 80 54 73 43 78 42 32 47 60 55 66 84 69 4 22 26 72 89 52 5 7 71 35 56 2 88 23 8 53 11 92 46 12 29 13 17 99 19 18 87 10 21 96 109 20 24 30 63 105 33 34 37 40 95 44 31 48 107 3 57 50 58 9 28 39 104 61 41 36 70 64 59 68 16 75 76 108 38 77 79 67 81 82 83 6 101 85 90 91 93 94 74 97 27 98 103 100 51 106 62 110 111 " }, { "input": "7\n45301 14370 61599 42695 46301 24556 26812", "output": "1 2 3 4 5 6 7 " }, { "input": "22\n70150 17718 11731 6488 72633 41249 12141 71465 88562 6167 71659 34151 60508 24942 77343 35882 80424 67225 92746 55412 79 53642", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 " }, { "input": "2\n1 4", "output": "1 2 " } ]
1,580,301,669
2,147,483,647
PyPy 3
OK
TESTS
29
280
18,739,200
n = int(input()) a = list(map(int, input().split())) s = set(a) k = set(range(1, n+1)) need = k-s vis = set() for i in range(n): if a[i] in vis: a[i] = need.pop() else: if a[i] not in k: a[i] = need.pop() vis.add(a[i]) else: vis.add(a[i]) print(*a)
Title: Inventory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal. Input Specification: The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. Output Specification: Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. Demo Input: ['3\n1 3 2\n', '4\n2 2 3 3\n', '1\n2\n'] Demo Output: ['1 3 2 \n', '2 1 3 4 \n', '1 \n'] Note: In the first test the numeration is already a permutation, so there is no need to change anything. In the second test there are two pairs of equal numbers, in each pair you need to replace one number. In the third test you need to replace 2 by 1, as the numbering should start from one.
```python n = int(input()) a = list(map(int, input().split())) s = set(a) k = set(range(1, n+1)) need = k-s vis = set() for i in range(n): if a[i] in vis: a[i] = need.pop() else: if a[i] not in k: a[i] = need.pop() vis.add(a[i]) else: vis.add(a[i]) print(*a) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,689,571,192
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
122
0
a=int(input()) b=int(input()) s=list(str(a)) d=list(str(b)) t=a+b r=list(str(t)) k=0 try: s.remove("0") except: k+=1 try: d.remove('0') except: k+=1 try: r.remove("0") except: if k==2: print("NO") quit() x=int("".join(s)) y=int("".join(d)) z=int(''.join(r)) print("YNEOS"[x+y!=z or k!=2::2])
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a=int(input()) b=int(input()) s=list(str(a)) d=list(str(b)) t=a+b r=list(str(t)) k=0 try: s.remove("0") except: k+=1 try: d.remove('0') except: k+=1 try: r.remove("0") except: if k==2: print("NO") quit() x=int("".join(s)) y=int("".join(d)) z=int(''.join(r)) print("YNEOS"[x+y!=z or k!=2::2]) ```
0
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\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": "100" }, { "input": "9 3\n9 5 2 3 7 1 8 4 6", "output": "7" }, { "input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58", "output": "16" }, { "input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54", "output": "48" }, { "input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1", "output": "44" }, { "input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3", "output": "46" }, { "input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78", "output": "40" }, { "input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69", "output": "11" }, { "input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95", "output": "50" }, { "input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9", "output": "86" }, { "input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7", "output": "93" }, { "input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42", "output": "77" }, { "input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48", "output": "97" }, { "input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78", "output": "20" }, { "input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41", "output": "97" }, { "input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82", "output": "51" }, { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58", "output": "97" }, { "input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88", "output": "47" }, { "input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51", "output": "98" }, { "input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67", "output": "94" }, { "input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19", "output": "95" }, { "input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49", "output": "88" }, { "input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1", "output": "99" }, { "input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95", "output": "100" }, { "input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15", "output": "98" }, { "input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16", "output": "100" }, { "input": "1 3\n5", "output": "1" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 3\n4 2", "output": "1" }, { "input": "2 5\n99 97", "output": "2" }, { "input": "3 4\n7 5 2", "output": "2" }, { "input": "3 50\n47 86 51", "output": "3" }, { "input": "5 100\n82 100 85 1 37", "output": "5" }, { "input": "5 20\n40 39 21 5 20", "output": "3" }, { "input": "1 27\n81", "output": "1" }, { "input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1", "output": "7" }, { "input": "2 1\n100 2", "output": "1" }, { "input": "2 2\n6 4", "output": "1" }, { "input": "5 2\n6 4 4 1 1", "output": "1" }, { "input": "1 4\n3", "output": "1" }, { "input": "3 2\n1 5 3", "output": "2" }, { "input": "3 1\n3 2 2", "output": "1" }, { "input": "3 1\n2 3 2", "output": "2" }, { "input": "5 1\n5 1 1 1 1", "output": "1" }, { "input": "2 3\n7 4", "output": "1" } ]
1,657,396,831
2,147,483,647
Python 3
OK
TESTS
49
62
102,400
import collections d = collections.deque() nm = list(map(int, input().split())) a = list(map(int, input().split())) z = d for i in range(nm[0]): d.append(a[i]) z.append(i+1) dop = 0 dops = 0 while len(d) > 1: dop = d.popleft() dops = z.popleft() if dop > nm[1]: dop -= nm[1] d.append((dop)) z.append((dops)) dop += nm[1] print(dops) # Sat Jul 09 2022 20:00:29 GMT+0000 (Coordinated Universal Time)
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output a single integer, representing the number of the last child. Demo Input: ['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n'] Demo Output: ['4\n', '6\n'] Note: Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
```python import collections d = collections.deque() nm = list(map(int, input().split())) a = list(map(int, input().split())) z = d for i in range(nm[0]): d.append(a[i]) z.append(i+1) dop = 0 dops = 0 while len(d) > 1: dop = d.popleft() dops = z.popleft() if dop > nm[1]: dop -= nm[1] d.append((dop)) z.append((dops)) dop += nm[1] print(dops) # Sat Jul 09 2022 20:00:29 GMT+0000 (Coordinated Universal Time) ```
3
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,568,919,393
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n,v=map(int,input().strip().split(' ')) count=0 for a0 in range(n): arr=list(map(int,input().strip().split(' '))) k=arr.pop(0) if v>min(arr): count+=1 print(count)
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().strip().split(' ')) count=0 for a0 in range(n): arr=list(map(int,input().strip().split(' '))) k=arr.pop(0) if v>min(arr): count+=1 print(count) ```
0
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n1 1\n1 1", "output": "maybe" }, { "input": "2\n4126 4126\n4126 4126", "output": "maybe" }, { "input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423", "output": "rated" }, { "input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110", "output": "unrated" }, { "input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143", "output": "maybe" }, { "input": "2\n3936 3936\n2967 2967", "output": "maybe" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 1\n1 2", "output": "rated" }, { "input": "2\n2967 2967\n3936 3936", "output": "unrated" }, { "input": "3\n1200 1200\n1200 1200\n1300 1300", "output": "unrated" }, { "input": "3\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "3\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "2\n3 2\n3 2", "output": "rated" }, { "input": "3\n5 5\n4 4\n3 4", "output": "rated" }, { "input": "3\n200 200\n200 200\n300 300", "output": "unrated" }, { "input": "3\n1 1\n2 2\n3 3", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699", "output": "maybe" }, { "input": "2\n10 10\n8 8", "output": "maybe" }, { "input": "3\n1500 1500\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "3\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n100 100\n100 100\n70 70\n80 80", "output": "unrated" }, { "input": "2\n1 2\n2 1", "output": "rated" }, { "input": "3\n5 5\n4 3\n3 3", "output": "rated" }, { "input": "3\n1600 1650\n1500 1550\n1400 1450", "output": "rated" }, { "input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700", "output": "unrated" }, { "input": "2\n1600 1600\n1400 1400", "output": "maybe" }, { "input": "2\n3 1\n9 8", "output": "rated" }, { "input": "2\n2 1\n1 1", "output": "rated" }, { "input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670", "output": "unrated" }, { "input": "2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n10 11\n5 4", "output": "rated" }, { "input": "2\n15 14\n13 12", "output": "rated" }, { "input": "2\n2 1\n2 2", "output": "rated" }, { "input": "3\n2670 2670\n3670 3670\n4106 4106", "output": "unrated" }, { "input": "3\n4 5\n3 3\n2 2", "output": "rated" }, { "input": "2\n10 9\n10 10", "output": "rated" }, { "input": "3\n1011 1011\n1011 999\n2200 2100", "output": "rated" }, { "input": "2\n3 3\n5 5", "output": "unrated" }, { "input": "2\n1500 1500\n3000 2000", "output": "rated" }, { "input": "2\n5 6\n5 5", "output": "rated" }, { "input": "3\n2000 2000\n1500 1501\n500 500", "output": "rated" }, { "input": "2\n2 3\n2 2", "output": "rated" }, { "input": "2\n3 3\n2 2", "output": "maybe" }, { "input": "2\n1 2\n1 1", "output": "rated" }, { "input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n15 14\n14 13", "output": "rated" }, { "input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900", "output": "unrated" }, { "input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884", "output": "rated" }, { "input": "2\n100 99\n100 100", "output": "rated" }, { "input": "4\n2 2\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "3\n100 101\n100 100\n100 100", "output": "rated" }, { "input": "4\n1000 1001\n900 900\n950 950\n890 890", "output": "rated" }, { "input": "2\n2 3\n1 1", "output": "rated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n3 2\n2 2", "output": "rated" }, { "input": "2\n3 2\n3 3", "output": "rated" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "3\n3 2\n3 3\n3 3", "output": "rated" }, { "input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "3\n1000 1000\n500 500\n400 300", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000", "output": "unrated" }, { "input": "2\n1 1\n2 3", "output": "rated" }, { "input": "2\n6 2\n6 2", "output": "rated" }, { "input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246", "output": "unrated" }, { "input": "2\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699", "output": "maybe" }, { "input": "2\n20 30\n10 5", "output": "rated" }, { "input": "3\n1 1\n2 2\n1 1", "output": "unrated" }, { "input": "2\n1 2\n3 3", "output": "rated" }, { "input": "5\n5 5\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 2\n2 1", "output": "rated" }, { "input": "2\n100 100\n90 89", "output": "rated" }, { "input": "2\n1000 900\n2000 2000", "output": "rated" }, { "input": "2\n50 10\n10 50", "output": "rated" }, { "input": "2\n200 200\n100 100", "output": "maybe" }, { "input": "3\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "3\n1000 1000\n300 300\n100 100", "output": "maybe" }, { "input": "4\n2 2\n2 2\n3 3\n4 4", "output": "unrated" }, { "input": "2\n5 3\n6 3", "output": "rated" }, { "input": "2\n1200 1100\n1200 1000", "output": "rated" }, { "input": "2\n5 5\n4 4", "output": "maybe" }, { "input": "2\n5 5\n3 3", "output": "maybe" }, { "input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100", "output": "unrated" }, { "input": "5\n10 10\n9 9\n8 8\n7 7\n6 6", "output": "maybe" }, { "input": "3\n1000 1000\n300 300\n10 10", "output": "maybe" }, { "input": "5\n6 6\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "2\n3 3\n1 1", "output": "maybe" }, { "input": "4\n2 2\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n1000 1000\n700 700", "output": "maybe" }, { "input": "2\n4 3\n5 3", "output": "rated" }, { "input": "2\n1000 1000\n1100 1100", "output": "unrated" }, { "input": "4\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "3\n1 1\n2 3\n2 2", "output": "rated" }, { "input": "2\n1 2\n1 3", "output": "rated" }, { "input": "2\n3 3\n1 2", "output": "rated" }, { "input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "5\n1 1\n2 2\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "2\n10 10\n1 2", "output": "rated" }, { "input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900", "output": "unrated" }, { "input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699", "output": "unrated" }, { "input": "2\n100 100\n110 110", "output": "unrated" }, { "input": "3\n3 3\n3 3\n4 4", "output": "unrated" }, { "input": "3\n3 3\n3 2\n4 4", "output": "rated" }, { "input": "3\n5 2\n4 4\n3 3", "output": "rated" }, { "input": "4\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n1 1\n3 2", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699", "output": "unrated" }, { "input": "3\n3 3\n3 3\n3 4", "output": "rated" }, { "input": "3\n1 2\n2 2\n3 3", "output": "rated" }, { "input": "3\n1 2\n1 2\n1 2", "output": "rated" }, { "input": "2\n2 1\n2 1", "output": "rated" }, { "input": "2\n1 2\n3 4", "output": "rated" }, { "input": "2\n3 2\n2 3", "output": "rated" }, { "input": "3\n1500 1500\n1600 1600\n1600 1600", "output": "unrated" }, { "input": "3\n1 1\n3 3\n4 4", "output": "unrated" }, { "input": "3\n1 1\n2 2\n2 2", "output": "unrated" }, { "input": "2\n10 12\n8 8", "output": "rated" }, { "input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500", "output": "unrated" }, { "input": "2\n1 2\n2 2", "output": "rated" }, { "input": "3\n1500 1400\n1200 1200\n1100 1100", "output": "rated" }, { "input": "2\n10 12\n10 10", "output": "rated" }, { "input": "3\n1500 1500\n1400 1400\n1300 1300", "output": "maybe" }, { "input": "3\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "3\n2 6\n3 5\n4 4", "output": "rated" }, { "input": "2\n5 6\n4 6", "output": "rated" }, { "input": "4\n10 10\n10 10\n7 7\n8 8", "output": "unrated" }, { "input": "2\n4 4\n3 3", "output": "maybe" } ]
1,517,768,346
2,147,483,647
Python 3
OK
TESTS
150
77
5,632,000
n=eval(input()) a=list(map(int,input().split())) i=2 flag1=0 while (i<=n): b=list(map(int,input().split())) a=a+b i+=1 i=0 while (i<len(a)) and (flag1==0): if (a[i]==a[i+1]): flag1=0 else: flag1=1 i+=2 if (flag1==0): i=1 flag2=0 while (i<len(a)-1) and (flag2==0): if (a[i]>=a[i+2]): flag2=0 else: flag2=1 i+=2 if flag1==1 : print ("rated") elif flag2==0 : print ("maybe") elif flag2==1 : print ("unrated")
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. Output Specification: If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". Demo Input: ['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'] Demo Output: ['rated\n', 'unrated\n', 'maybe\n'] Note: In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
```python n=eval(input()) a=list(map(int,input().split())) i=2 flag1=0 while (i<=n): b=list(map(int,input().split())) a=a+b i+=1 i=0 while (i<len(a)) and (flag1==0): if (a[i]==a[i+1]): flag1=0 else: flag1=1 i+=2 if (flag1==0): i=1 flag2=0 while (i<len(a)-1) and (flag2==0): if (a[i]>=a[i+2]): flag2=0 else: flag2=1 i+=2 if flag1==1 : print ("rated") elif flag2==0 : print ("maybe") elif flag2==1 : print ("unrated") ```
3
766
A
Mahmoud and Longest Uncommon Subsequence
PROGRAMMING
1,000
[ "constructive algorithms", "strings" ]
null
null
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
[ "abcd\ndefgh\n", "a\na\n" ]
[ "5\n", "-1\n" ]
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
500
[ { "input": "abcd\ndefgh", "output": "5" }, { "input": "a\na", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "output": "100" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "199" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb", "output": "99" }, { "input": "abcde\nfghij", "output": "5" }, { "input": "abcde\nabcdf", "output": "5" }, { "input": "abcde\nbbcde", "output": "5" }, { "input": "abcde\neabcd", "output": "5" }, { "input": "abcdefgh\nabdcefgh", "output": "8" }, { "input": "mmmmm\nmnmmm", "output": "5" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa", "output": "34" }, { "input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy", "output": "26" }, { "input": "a\nab", "output": "2" }, { "input": "b\nab", "output": "2" }, { "input": "ab\nb", "output": "2" }, { "input": "ab\nc", "output": "2" }, { "input": "aaaaaa\naaaaaa", "output": "-1" }, { "input": "abacaba\nabacaba", "output": "-1" }, { "input": "aabb\nbbaa", "output": "4" }, { "input": "ab\nba", "output": "2" }, { "input": "abcd\nabc", "output": "4" }, { "input": "abaa\nabaa", "output": "-1" }, { "input": "ab\nab", "output": "-1" }, { "input": "ab\nabcd", "output": "4" }, { "input": "abc\nabcd", "output": "4" }, { "input": "mo\nmomo", "output": "4" }, { "input": "koooooooooooooooo\nloooooooooooooooo", "output": "17" }, { "input": "aaa\naa", "output": "3" }, { "input": "abc\nabc", "output": "-1" }, { "input": "abcd\nabcd", "output": "-1" }, { "input": "abc\ncba", "output": "3" }, { "input": "ahc\nahc", "output": "-1" }, { "input": "abc\nbac", "output": "3" }, { "input": "aa\naaa", "output": "3" }, { "input": "aaa\naaa", "output": "-1" }, { "input": "abc\nacb", "output": "3" }, { "input": "abc\nab", "output": "3" }, { "input": "abb\nabb", "output": "-1" }, { "input": "abc\ncab", "output": "3" }, { "input": "aaaaaa\naaaaa", "output": "6" }, { "input": "aa\naab", "output": "3" }, { "input": "len\nlena", "output": "4" }, { "input": "aaaaa\naa", "output": "5" }, { "input": "aaa\naaaa", "output": "4" }, { "input": "bcd\nabcd", "output": "4" }, { "input": "aaabbc\naaaccc", "output": "6" }, { "input": "abcd\nzycd", "output": "4" }, { "input": "baa\nzaa", "output": "3" }, { "input": "asdf\nadfs", "output": "4" }, { "input": "abcdefgh\nabcdefgh", "output": "-1" }, { "input": "aba\naab", "output": "3" }, { "input": "aba\naba", "output": "-1" }, { "input": "abcccc\naccccc", "output": "6" }, { "input": "acb\nabc", "output": "3" }, { "input": "a\naa", "output": "2" }, { "input": "abababab\nab", "output": "8" }, { "input": "ababab\nab", "output": "6" } ]
1,662,464,195
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
s = len(input()) s2 = len(input()) if s!=s2: print(max(s,s2)) else: print(-1)
Title: Mahmoud and Longest Uncommon Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input Specification: The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output Specification: If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. Demo Input: ['abcd\ndefgh\n', 'a\na\n'] Demo Output: ['5\n', '-1\n'] Note: In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
```python s = len(input()) s2 = len(input()) if s!=s2: print(max(s,s2)) else: print(-1) ```
0
915
B
Browser
PROGRAMMING
1,300
[ "implementation" ]
null
null
Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible. Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab *i*, then she can move it to the tab *max*(*i*<=-<=1,<=*a*) or to the tab *min*(*i*<=+<=1,<=*b*)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab *i*, she can close all the tabs with indices from segment [*a*,<=*i*<=-<=1] or from segment [*i*<=+<=1,<=*b*]). In the aforementioned expressions *a* and *b* denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then *a*<==<=3, *b*<==<=6. What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from *l* to *r* inclusive opened?
The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*].
[ "6 3 2 4\n", "6 3 1 3\n", "5 2 1 5\n" ]
[ "5\n", "1\n", "0\n" ]
In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it. In the second test she only needs to close all the tabs to the right of the current position of the cursor. In the third test Luba doesn't need to do anything.
0
[ { "input": "6 3 2 4", "output": "5" }, { "input": "6 3 1 3", "output": "1" }, { "input": "5 2 1 5", "output": "0" }, { "input": "100 1 1 99", "output": "99" }, { "input": "100 50 1 99", "output": "50" }, { "input": "100 99 1 99", "output": "1" }, { "input": "100 100 1 99", "output": "2" }, { "input": "100 50 2 100", "output": "49" }, { "input": "100 1 100 100", "output": "100" }, { "input": "100 50 50 50", "output": "2" }, { "input": "6 4 2 5", "output": "6" }, { "input": "100 5 2 50", "output": "53" }, { "input": "10 7 3 9", "output": "10" }, { "input": "7 4 2 5", "output": "6" }, { "input": "43 16 2 18", "output": "20" }, { "input": "100 50 2 51", "output": "52" }, { "input": "6 5 2 4", "output": "5" }, { "input": "10 5 2 7", "output": "9" }, { "input": "10 10 2 9", "output": "10" }, { "input": "10 7 3 7", "output": "6" }, { "input": "64 64 8 44", "output": "58" }, { "input": "5 4 2 4", "output": "4" }, { "input": "6 6 3 5", "output": "5" }, { "input": "10 6 2 7", "output": "8" }, { "input": "8 6 2 7", "output": "8" }, { "input": "7 5 2 4", "output": "5" }, { "input": "7 5 2 6", "output": "7" }, { "input": "100 50 49 99", "output": "53" }, { "input": "100 50 2 99", "output": "147" }, { "input": "10 9 2 9", "output": "9" }, { "input": "10 10 7 9", "output": "5" }, { "input": "8 4 2 7", "output": "9" }, { "input": "100 50 2 2", "output": "50" }, { "input": "10 4 3 7", "output": "7" }, { "input": "6 3 2 5", "output": "6" }, { "input": "53 17 13 18", "output": "8" }, { "input": "10 6 3 6", "output": "5" }, { "input": "9 8 2 5", "output": "8" }, { "input": "100 50 2 3", "output": "50" }, { "input": "10 7 2 9", "output": "11" }, { "input": "6 1 2 5", "output": "6" }, { "input": "7 6 2 4", "output": "6" }, { "input": "26 12 2 4", "output": "12" }, { "input": "10 8 3 7", "output": "7" }, { "input": "100 97 3 98", "output": "98" }, { "input": "6 2 2 4", "output": "4" }, { "input": "9 2 4 6", "output": "6" }, { "input": "6 6 2 4", "output": "6" }, { "input": "50 2 25 49", "output": "49" }, { "input": "5 5 2 3", "output": "5" }, { "input": "49 11 2 17", "output": "23" }, { "input": "10 3 2 9", "output": "10" }, { "input": "10 6 3 7", "output": "7" }, { "input": "6 1 5 5", "output": "6" }, { "input": "5 5 3 4", "output": "4" }, { "input": "10 2 5 6", "output": "6" }, { "input": "7 7 3 4", "output": "6" }, { "input": "7 3 2 3", "output": "3" }, { "input": "5 1 2 4", "output": "5" }, { "input": "100 53 2 99", "output": "145" }, { "input": "10 2 4 7", "output": "7" }, { "input": "5 2 1 4", "output": "3" }, { "input": "100 65 41 84", "output": "64" }, { "input": "33 20 7 17", "output": "15" }, { "input": "7 2 3 6", "output": "6" }, { "input": "77 64 10 65", "output": "58" }, { "input": "6 1 3 4", "output": "5" }, { "input": "6 4 2 4", "output": "4" }, { "input": "11 8 2 10", "output": "12" }, { "input": "7 1 3 6", "output": "7" }, { "input": "100 50 2 50", "output": "50" }, { "input": "50 49 5 8", "output": "46" }, { "input": "15 1 10 13", "output": "14" }, { "input": "13 9 5 11", "output": "10" }, { "input": "20 3 5 8", "output": "7" }, { "input": "10 5 2 3", "output": "5" }, { "input": "7 1 3 5", "output": "6" }, { "input": "7 2 3 4", "output": "4" }, { "input": "10 5 2 5", "output": "5" }, { "input": "8 5 2 6", "output": "7" }, { "input": "8 5 3 6", "output": "6" }, { "input": "9 6 3 7", "output": "7" }, { "input": "50 46 34 37", "output": "14" }, { "input": "10 7 2 8", "output": "9" }, { "input": "8 3 1 4", "output": "2" }, { "input": "100 3 10 20", "output": "19" }, { "input": "6 2 1 5", "output": "4" }, { "input": "12 11 5 10", "output": "8" }, { "input": "98 97 72 83", "output": "27" }, { "input": "100 5 3 98", "output": "99" }, { "input": "8 5 2 7", "output": "9" }, { "input": "10 10 4 6", "output": "8" }, { "input": "10 4 2 5", "output": "6" }, { "input": "3 3 2 3", "output": "2" }, { "input": "75 30 6 33", "output": "32" }, { "input": "4 3 2 3", "output": "3" }, { "input": "2 2 1 1", "output": "2" }, { "input": "2 2 1 2", "output": "0" }, { "input": "1 1 1 1", "output": "0" }, { "input": "20 9 7 17", "output": "14" }, { "input": "10 2 3 7", "output": "7" }, { "input": "100 40 30 80", "output": "62" }, { "input": "10 6 2 3", "output": "6" }, { "input": "7 3 2 5", "output": "6" }, { "input": "10 6 2 9", "output": "12" }, { "input": "23 20 19 22", "output": "6" }, { "input": "100 100 1 1", "output": "100" }, { "input": "10 2 5 9", "output": "9" }, { "input": "9 7 2 8", "output": "9" }, { "input": "100 50 50 100", "output": "1" }, { "input": "3 1 2 2", "output": "3" }, { "input": "16 13 2 15", "output": "17" }, { "input": "9 8 2 6", "output": "8" }, { "input": "43 22 9 24", "output": "19" }, { "input": "5 4 2 3", "output": "4" }, { "input": "82 72 66 75", "output": "14" }, { "input": "7 4 5 6", "output": "4" }, { "input": "100 50 51 51", "output": "3" }, { "input": "6 5 2 6", "output": "4" }, { "input": "4 4 2 2", "output": "4" }, { "input": "4 3 2 4", "output": "2" }, { "input": "2 2 2 2", "output": "1" }, { "input": "6 1 2 4", "output": "5" }, { "input": "2 1 1 1", "output": "1" }, { "input": "4 2 2 3", "output": "3" }, { "input": "2 1 1 2", "output": "0" }, { "input": "5 4 1 2", "output": "3" }, { "input": "100 100 2 99", "output": "100" }, { "input": "10 6 3 4", "output": "5" }, { "input": "100 74 30 60", "output": "46" }, { "input": "4 1 2 3", "output": "4" }, { "input": "100 50 3 79", "output": "107" }, { "input": "10 6 2 8", "output": "10" }, { "input": "100 51 23 33", "output": "30" }, { "input": "3 1 2 3", "output": "2" }, { "input": "29 13 14 23", "output": "12" }, { "input": "6 5 2 5", "output": "5" }, { "input": "10 2 3 5", "output": "5" }, { "input": "9 3 1 6", "output": "4" }, { "input": "45 33 23 37", "output": "20" }, { "input": "100 99 1 98", "output": "2" }, { "input": "100 79 29 68", "output": "52" }, { "input": "7 7 6 6", "output": "3" }, { "input": "100 4 30 60", "output": "58" }, { "input": "100 33 50 50", "output": "19" }, { "input": "50 2 34 37", "output": "37" }, { "input": "100 70 2 99", "output": "128" }, { "input": "6 6 4 4", "output": "4" }, { "input": "41 24 14 19", "output": "12" }, { "input": "100 54 52 55", "output": "6" }, { "input": "10 5 3 6", "output": "6" }, { "input": "6 5 4 6", "output": "2" }, { "input": "10 9 2 3", "output": "9" }, { "input": "6 4 2 3", "output": "4" }, { "input": "100 68 5 49", "output": "65" }, { "input": "8 4 3 6", "output": "6" }, { "input": "9 3 2 8", "output": "9" }, { "input": "100 50 1 1", "output": "50" }, { "input": "10 9 5 9", "output": "6" }, { "input": "62 54 2 54", "output": "54" }, { "input": "100 54 30 60", "output": "38" }, { "input": "6 6 6 6", "output": "1" }, { "input": "10 2 2 9", "output": "9" }, { "input": "50 3 23 25", "output": "24" }, { "input": "24 1 5 18", "output": "19" }, { "input": "43 35 23 34", "output": "14" }, { "input": "50 46 23 26", "output": "25" }, { "input": "10 8 5 9", "output": "7" }, { "input": "6 2 2 5", "output": "5" }, { "input": "43 1 13 41", "output": "42" }, { "input": "13 2 1 5", "output": "4" }, { "input": "6 3 3 5", "output": "4" }, { "input": "14 10 4 12", "output": "12" }, { "input": "5 1 4 4", "output": "5" }, { "input": "3 3 1 1", "output": "3" }, { "input": "17 17 12 14", "output": "7" }, { "input": "20 15 6 7", "output": "11" }, { "input": "86 36 8 70", "output": "92" }, { "input": "100 69 39 58", "output": "32" }, { "input": "3 3 2 2", "output": "3" }, { "input": "3 2 1 1", "output": "2" }, { "input": "9 7 3 8", "output": "8" }, { "input": "4 4 2 3", "output": "4" }, { "input": "100 4 2 5", "output": "6" }, { "input": "100 65 5 13", "output": "62" }, { "input": "3 2 2 3", "output": "1" }, { "input": "44 38 20 28", "output": "20" }, { "input": "100 65 58 60", "output": "9" }, { "input": "16 12 8 13", "output": "8" }, { "input": "11 8 4 9", "output": "8" }, { "input": "20 9 2 10", "output": "11" }, { "input": "5 5 4 5", "output": "2" }, { "input": "100 99 1 50", "output": "50" }, { "input": "6 5 3 5", "output": "4" }, { "input": "50 29 7 48", "output": "62" }, { "input": "26 11 1 24", "output": "14" }, { "input": "5 2 3 4", "output": "4" }, { "input": "100 1 2 3", "output": "4" }, { "input": "100 60 27 56", "output": "35" }, { "input": "6 4 2 6", "output": "3" }, { "input": "8 7 3 5", "output": "6" }, { "input": "4 1 3 3", "output": "4" }, { "input": "12 9 2 10", "output": "11" }, { "input": "100 25 9 19", "output": "18" }, { "input": "10 7 3 8", "output": "8" }, { "input": "7 3 2 6", "output": "7" }, { "input": "100 39 4 40", "output": "39" }, { "input": "100 51 2 99", "output": "147" }, { "input": "15 6 4 10", "output": "10" }, { "input": "10 4 4 9", "output": "7" }, { "input": "6 4 3 4", "output": "3" }, { "input": "14 7 4 12", "output": "13" }, { "input": "4 4 1 2", "output": "3" }, { "input": "6 5 2 3", "output": "5" }, { "input": "12 12 5 5", "output": "9" }, { "input": "10 5 3 5", "output": "4" }, { "input": "8 6 2 2", "output": "6" }, { "input": "8 7 2 7", "output": "7" }, { "input": "100 33 5 60", "output": "84" }, { "input": "100 32 5 60", "output": "84" }, { "input": "79 5 3 5", "output": "4" }, { "input": "85 85 85 85", "output": "1" }, { "input": "69 69 69 69", "output": "1" }, { "input": "7 5 3 6", "output": "6" }, { "input": "7 4 2 6", "output": "8" }, { "input": "2 1 2 2", "output": "2" }, { "input": "100 2 1 90", "output": "89" }, { "input": "100 89 11 90", "output": "82" }, { "input": "10 1 2 8", "output": "9" } ]
1,689,255,232
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689255231.97741")# 1689255231.9774551
Title: Browser Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible. Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab *i*, then she can move it to the tab *max*(*i*<=-<=1,<=*a*) or to the tab *min*(*i*<=+<=1,<=*b*)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab *i*, she can close all the tabs with indices from segment [*a*,<=*i*<=-<=1] or from segment [*i*<=+<=1,<=*b*]). In the aforementioned expressions *a* and *b* denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then *a*<==<=3, *b*<==<=6. What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from *l* to *r* inclusive opened? Input Specification: The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. Output Specification: Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*]. Demo Input: ['6 3 2 4\n', '6 3 1 3\n', '5 2 1 5\n'] Demo Output: ['5\n', '1\n', '0\n'] Note: In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it. In the second test she only needs to close all the tabs to the right of the current position of the cursor. In the third test Luba doesn't need to do anything.
```python print("_RANDOM_GUESS_1689255231.97741")# 1689255231.9774551 ```
0
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 2 5 3 4", "output": "chest" }, { "input": "8\n7 2 9 10 3 8 10 6", "output": "chest" }, { "input": "9\n5 4 2 3 4 4 5 2 2", "output": "chest" }, { "input": "10\n4 9 8 5 3 8 8 10 4 2", "output": "biceps" }, { "input": "11\n10 9 7 6 1 3 9 7 1 3 5", "output": "chest" }, { "input": "12\n24 22 6 16 5 21 1 7 2 19 24 5", "output": "chest" }, { "input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "output": "chest" }, { "input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7", "output": "back" }, { "input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12", "output": "chest" }, { "input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8", "output": "biceps" }, { "input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19", "output": "chest" }, { "input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21", "output": "back" }, { "input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24", "output": "chest" }, { "input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20", "output": "chest" }, { "input": "1\n10", "output": "chest" }, { "input": "2\n15 3", "output": "chest" }, { "input": "3\n21 11 19", "output": "chest" }, { "input": "4\n19 24 13 15", "output": "chest" }, { "input": "5\n4 24 1 9 19", "output": "biceps" }, { "input": "6\n6 22 24 7 15 24", "output": "back" }, { "input": "7\n10 8 23 23 14 18 14", "output": "chest" }, { "input": "8\n5 16 8 9 17 16 14 7", "output": "biceps" }, { "input": "9\n12 3 10 23 6 4 22 13 12", "output": "chest" }, { "input": "10\n1 9 20 18 20 17 7 24 23 2", "output": "back" }, { "input": "11\n22 25 8 2 18 15 1 13 1 11 4", "output": "biceps" }, { "input": "12\n20 12 14 2 15 6 24 3 11 8 11 14", "output": "chest" }, { "input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18", "output": "back" }, { "input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22", "output": "biceps" }, { "input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6", "output": "back" }, { "input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14", "output": "chest" }, { "input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10", "output": "biceps" }, { "input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17", "output": "chest" }, { "input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14", "output": "back" }, { "input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6", "output": "back" }, { "input": "1\n19", "output": "chest" }, { "input": "2\n1 7", "output": "biceps" }, { "input": "3\n18 18 23", "output": "back" }, { "input": "4\n12 15 1 13", "output": "chest" }, { "input": "5\n11 14 25 21 21", "output": "biceps" }, { "input": "6\n11 9 12 11 22 18", "output": "biceps" }, { "input": "7\n11 1 16 20 21 25 20", "output": "chest" }, { "input": "8\n1 2 20 9 3 22 17 4", "output": "back" }, { "input": "9\n19 2 10 19 15 20 3 1 13", "output": "back" }, { "input": "10\n11 2 11 8 21 16 2 3 19 9", "output": "back" }, { "input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24", "output": "chest" }, { "input": "12\n4 24 21 3 13 24 22 13 12 21 1 15", "output": "back" }, { "input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3", "output": "biceps" }, { "input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11", "output": "biceps" }, { "input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17", "output": "back" }, { "input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17", "output": "chest" }, { "input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8", "output": "chest" }, { "input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22", "output": "chest" }, { "input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24", "output": "chest" }, { "input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23", "output": "biceps" }, { "input": "1\n19", "output": "chest" }, { "input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22", "output": "biceps" } ]
1,656,360,856
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
n=int(input()) exercises=list(map(int, int() .split())) biceps=0 chest=0 back=0 for i in range(n): if i%3==0: chest += exercises[i] elif i%3==1: biceps+=exercises[i] else: back+=exercises[i] if biceps<chest and back<chest: print("chest") if chest<biceps and back<biceps: print("biceps") if biceps<back and chest<back: print("back")
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. Output Specification: Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. Demo Input: ['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n'] Demo Output: ['biceps\n', 'back\n', 'chest\n'] Note: In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
```python n=int(input()) exercises=list(map(int, int() .split())) biceps=0 chest=0 back=0 for i in range(n): if i%3==0: chest += exercises[i] elif i%3==1: biceps+=exercises[i] else: back+=exercises[i] if biceps<chest and back<chest: print("chest") if chest<biceps and back<biceps: print("biceps") if biceps<back and chest<back: print("back") ```
-1
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,544,247,591
2,147,483,647
Python 3
OK
TESTS
25
248
0
(n,m) = tuple(map(int,input().strip().split(' '))) a = list(map(int,input().strip().split(' '))) a.sort() sums=0 i=0 while(i<m and a[i]<0): sums+=a[i] i+=1 print(-sums)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python (n,m) = tuple(map(int,input().strip().split(' '))) a = list(map(int,input().strip().split(' '))) a.sort() sums=0 i=0 while(i<m and a[i]<0): sums+=a[i] i+=1 print(-sums) ```
3.938
408
B
Garland
PROGRAMMING
1,200
[ "implementation" ]
null
null
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.
The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
[ "aaabbac\naabbccac\n", "a\nz\n" ]
[ "6\n", "-1" ]
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.
1,000
[ { "input": "aaabbac\naabbccac", "output": "6" }, { "input": "a\nz", "output": "-1" }, { "input": "r\nr", "output": "1" }, { "input": "stnsdn\nndnndsn", "output": "4" }, { "input": "yqfqfp\ntttwtqq", "output": "-1" }, { "input": "zzbbrrtrtzr\ntbbtrrrzr", "output": "9" }, { "input": "ivvfisvsvii\npaihjinno", "output": "-1" }, { "input": "zbvwnlgkshqerxptyod\nz", "output": "1" }, { "input": "xlktwjymocqrahnbesf\nfoo", "output": "2" }, { "input": "bbzmzqazmbambnmzaabznmbabzqnaabmabmnnabbmnzaanzzezebzabqaabzqaemeqqammmbazmmz\naznnbbmeebmanbeemzmemqbaeebnqenqzzbanebmnzqqebqmmnmqqzmmeqqqaaezemmazqqmqaqnnqqzbzeeazammmenbbamzbmnaenemenaaaebnmanebqmqnznqbenmqqnnnaeaebqmamennmqqeaaqqbammnzqmnmqnqbbezmemznqmanzmmqzzzzembqnzqbanamezqaqbazenenqqznqaebzaeezbqqbmeeaqnmmbnqbbnmaqqemaeaezaabmbnbzzaae", "output": "77" }, { "input": "lccfdfnfflncddlksndcwnfcllnnaswcdnldafcalssfcdnkkaklwnnacsncfwanwnwfadawcsdcfwflnnlfsfclkfknlaldna\nuaaldlllhedgugugueahddhedbuddaedhaaeugdubaealbgbagedldbl", "output": "-1" }, { "input": "hvewdvwdwudrwarwmddwnazmwauzatrmwptwwevavpmwrtruwnpwantewrnwmepdwvtmnveanunrvrtwpvhhnuhnmpptdttzmmndtvudmzhhannmmnahdpzamuvhzaavnhtnumwrwvttdetvuewaaennddwuvzvaptdzrzhtetwwzmzedrwuvrwznprhdvnavrruvvhzuwpdtmpwmzrwvermrhdamv\nuvzhwtpuputnahwwarduzddhpnwwvettprwavdmnztdnrddmarmvuevtdezndnezvarhmppwwnmvnrtddzhhnzrwuhvpwmezuurundarwdazwptrpeurrnwautddnhdmhtwhwvvtavdzezumetzezpazndhuentmrhamutrtttpevtuutemdnvwnwnmnvmznatneweuaahdavmaddhnrdenwwztrwh", "output": "199" }, { "input": "aaccddff\nabcdf", "output": "-1" } ]
1,693,429,790
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
t = input() t = int(t) for _ in range(t): mymap = {} s = input() for j in range(len(s)): if mymap.get(s[j] , 0) == 0 : mymap[s[j]] = 1 else: mymap[s[j]] += 1 mx = max(mymap) if mymap.get(mx) == 3 : print(6) elif mymap.get(mx) == 2 : print(4) elif mymap.get(mx) == 4 : print(-1) elif mymap.get(mx) == 1 : print(4)
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get. Input Specification: The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make. Output Specification: Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. Demo Input: ['aaabbac\naabbccac\n', 'a\nz\n'] Demo Output: ['6\n', '-1'] Note: In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.
```python t = input() t = int(t) for _ in range(t): mymap = {} s = input() for j in range(len(s)): if mymap.get(s[j] , 0) == 0 : mymap[s[j]] = 1 else: mymap[s[j]] += 1 mx = max(mymap) if mymap.get(mx) == 3 : print(6) elif mymap.get(mx) == 2 : print(4) elif mymap.get(mx) == 4 : print(-1) elif mymap.get(mx) == 1 : print(4) ```
-1
598
C
Nearest vectors
PROGRAMMING
2,300
[ "geometry", "sortings" ]
null
null
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors. The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=&gt;<=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
[ "4\n-1 0\n0 -1\n1 0\n1 1\n", "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n" ]
[ "3 4\n", "6 5" ]
none
0
[ { "input": "4\n-1 0\n0 -1\n1 0\n1 1", "output": "3 4" }, { "input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6", "output": "5 6" }, { "input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7", "output": "1 3" }, { "input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2", "output": "13 16" }, { "input": "2\n351 -4175\n-328 -657", "output": "2 1" }, { "input": "3\n620 -1189\n8101 -2770\n3347 3473", "output": "1 2" }, { "input": "4\n-7061 -5800\n-3471 -9470\n-7639 2529\n5657 -6522", "output": "1 2" }, { "input": "5\n-7519 -3395\n-32 -257\n-4827 -1889\n9545 -7037\n2767 583", "output": "3 1" }, { "input": "6\n-5120 -3251\n8269 -7984\n841 3396\n3136 -7551\n-1280 -3013\n-3263 -3278", "output": "1 6" }, { "input": "7\n-2722 6597\n-3303 200\n6508 -1021\n-1107 -1042\n6875 7616\n-3047 6749\n662 -1979", "output": "1 6" }, { "input": "8\n-36 749\n5126 943\n1165 533\n-1647 -5725\n5031 6532\n5956 8447\n2297 -2284\n1986 6937", "output": "5 6" }, { "input": "9\n-391 -1706\n995 -5756\n-5013 -154\n1121 3160\n-7111 8303\n-7303 -2414\n-7791 -935\n7576 -9361\n1072 203", "output": "3 7" }, { "input": "10\n-9920 -5477\n9691 -3200\n754 885\n-1895 1768\n-941 1588\n6293 -2631\n-2288 9129\n4067 696\n-6754 9869\n-5747 701", "output": "5 9" }, { "input": "2\n1 0\n-1 0", "output": "1 2" }, { "input": "2\n0 1\n0 -1", "output": "1 2" }, { "input": "2\n2131 -3249\n-2131 3249", "output": "2 1" }, { "input": "3\n-5 1\n-5 -1\n5 0", "output": "1 2" }, { "input": "3\n-100 1\n-100 -1\n0 100", "output": "1 2" }, { "input": "3\n1 10\n10 1\n10 -1", "output": "3 2" }, { "input": "3\n3 0\n0 3\n1 -3", "output": "3 1" }, { "input": "3\n1 1\n-1 0\n1 -1", "output": "3 1" }, { "input": "3\n-1 0\n10 -1\n1 0", "output": "2 3" }, { "input": "4\n1 10\n10 1\n-2 -2\n10 -1", "output": "4 2" }, { "input": "3\n-6 0\n6 1\n6 -1", "output": "3 2" }, { "input": "3\n114 1\n-514 0\n114 -1", "output": "3 1" }, { "input": "4\n-1 0\n0 -1\n-1 1\n1 0", "output": "3 1" }, { "input": "4\n2 1\n2 -1\n-1 1\n-1 -1", "output": "2 1" }, { "input": "3\n3 1\n3 -1\n0 3", "output": "2 1" }, { "input": "3\n1 1\n9000 1\n9000 -1", "output": "3 2" }, { "input": "3\n1 0\n-1 1\n-1 -1", "output": "2 3" }, { "input": "6\n1 1\n-1 -1\n0 20\n100 1\n-100 0\n100 -1", "output": "6 4" }, { "input": "4\n1 0\n0 1\n-1 0\n-13 -1", "output": "3 4" }, { "input": "3\n1 0\n-1 0\n1 -1", "output": "3 1" }, { "input": "3\n100 1\n-100 0\n100 -1", "output": "3 1" }, { "input": "3\n-100 1\n100 0\n-100 -1", "output": "1 3" }, { "input": "3\n1 100\n0 -100\n-1 100", "output": "1 3" }, { "input": "11\n-7945 386\n7504 -576\n-6020 -8277\n930 9737\n1682 474\n-8279 1197\n2790 2607\n-5514 -9601\n-3159 5939\n-1806 4207\n-9073 -2138", "output": "10 9" }, { "input": "3\n1 0\n10000 -1\n1 1", "output": "2 1" }, { "input": "4\n-7125 -1643\n-1235 4071\n-75 -8717\n2553 9278", "output": "4 2" }, { "input": "5\n-6 0\n6 1\n6 -1\n0 6\n0 -6", "output": "3 2" }, { "input": "4\n5 5\n5 -5\n-555 1\n-555 -1", "output": "3 4" }, { "input": "4\n1 1\n-1 1\n-1 -1\n2 -1", "output": "4 1" }, { "input": "4\n-1 -100\n1 -100\n-100 -100\n100 -100", "output": "1 2" }, { "input": "3\n1 0\n1 -1\n-4 -6", "output": "2 1" }, { "input": "4\n-1 -100\n1 -100\n100 -100\n-100 -100", "output": "1 2" }, { "input": "4\n-1 0\n0 -2\n-3 3\n4 0", "output": "3 1" }, { "input": "4\n-2 0\n0 -3\n-5 5\n4 0", "output": "3 1" }, { "input": "3\n1 -100\n0 100\n-1 -100", "output": "3 1" }, { "input": "5\n10000 2\n10000 -1\n10000 -5\n10000 -9\n10000 -13", "output": "2 1" }, { "input": "8\n-9580 8545\n-9379 -1139\n5824 -391\n-8722 2765\n-1357 -5547\n-7700 217\n9323 -7008\n957 -8356", "output": "6 2" }, { "input": "4\n5 5\n5 -5\n-500 1\n-500 -1", "output": "3 4" }, { "input": "3\n30 1\n30 -1\n0 30", "output": "2 1" }, { "input": "4\n3966 -1107\n8007 -5457\n-7753 4945\n-2209 -4221", "output": "2 1" }, { "input": "4\n1 9999\n0 1\n10000 0\n10000 -1", "output": "4 3" }, { "input": "3\n10000 1\n10000 -1\n-10000 0", "output": "2 1" }, { "input": "13\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n13 14\n12 13", "output": "12 13" }, { "input": "4\n2 1\n2 -1\n0 1\n-1 0", "output": "2 1" }, { "input": "4\n10 3\n10 -3\n-500 1\n-500 -1", "output": "3 4" }, { "input": "4\n1 10000\n-1 1\n10000 0\n10000 -1", "output": "4 3" }, { "input": "3\n0 1\n1 0\n1 -1", "output": "3 2" }, { "input": "3\n1 0\n0 1\n1 -1", "output": "3 1" }, { "input": "4\n1 1\n-1 1\n1 -2\n-1 -2", "output": "4 3" }, { "input": "4\n0 -1\n-1 0\n-1 1\n1 0", "output": "3 2" }, { "input": "3\n-100 1\n-100 -1\n1 1", "output": "1 2" }, { "input": "3\n-3 1\n-3 -1\n2 -3", "output": "1 2" }, { "input": "3\n1 -1\n1 0\n0 1", "output": "1 2" }, { "input": "5\n-5 1\n0 5\n4 1\n0 -4\n-5 -1", "output": "1 5" }, { "input": "4\n1 10000\n0 1\n10000 0\n9999 -1", "output": "1 2" }, { "input": "4\n2 3\n2 -3\n-3 2\n-3 -2", "output": "3 4" }, { "input": "3\n1 -3\n1 0\n0 1", "output": "1 2" }, { "input": "3\n1 0\n-1 0\n-1 -1", "output": "2 3" }, { "input": "4\n-2 1\n-2 -1\n1 1\n1 -1", "output": "1 2" }, { "input": "3\n1 -1\n-1 1\n-1 -2", "output": "3 1" }, { "input": "3\n1 0\n-1 -1\n1 -1", "output": "3 1" }, { "input": "3\n5 5\n-5 0\n5 -5", "output": "3 1" }, { "input": "4\n1 -2\n1 0\n-1 0\n10 -1", "output": "4 2" }, { "input": "3\n-1000 1\n-1000 -1\n1000 0", "output": "1 2" }, { "input": "6\n1 1\n1 -1\n-1 1\n-1 -1\n1 -10000\n-1 -10000", "output": "6 5" }, { "input": "3\n1 1\n-1 0\n0 -1", "output": "2 3" }, { "input": "4\n5000 1\n5000 -1\n-2 -1\n2 -1", "output": "2 1" }, { "input": "3\n1 0\n-1 1\n-1 -5", "output": "3 1" }, { "input": "3\n-5374 1323\n-4463 -8462\n6118 -7918", "output": "2 3" }, { "input": "4\n-6427 -6285\n-5386 -5267\n-3898 7239\n-3905 7252", "output": "4 3" }, { "input": "10\n-7 -3\n-2 8\n9 -9\n0 1\n4 5\n5 3\n-3 0\n10 2\n4 -1\n2 -10", "output": "4 2" }, { "input": "4\n9999 1\n9999 -1\n-9998 1\n-10000 -1", "output": "2 1" }, { "input": "4\n10000 9999\n9999 9998\n9998 9997\n9997 9996", "output": "2 1" }, { "input": "4\n-6285 -6427\n-5267 -5386\n7239 -3898\n7252 -3905", "output": "3 4" }, { "input": "4\n-6427 6285\n-5386 5267\n3898 -7239\n3905 -7252", "output": "4 3" }, { "input": "4\n-6427 -6285\n-5386 -5267\n-3898 -7239\n-3905 -7252", "output": "3 4" }, { "input": "3\n0 1\n-1 -1\n1 -1", "output": "2 3" }, { "input": "4\n10000 1\n9998 -1\n-9999 1\n-9999 -1", "output": "3 4" }, { "input": "3\n100 0\n100 2\n100 -1", "output": "3 1" }, { "input": "3\n-1 1\n-1 -1\n1 0", "output": "1 2" }, { "input": "4\n9844 9986\n181 9967\n-9812 -9925\n-194 -9900", "output": "1 2" }, { "input": "4\n9800 9981\n61 9899\n-9926 -9932\n-149 -9926", "output": "3 4" }, { "input": "4\n-9901 9900\n-10000 9899\n9899 9801\n9899 9900", "output": "3 4" }, { "input": "4\n9934 9989\n199 9949\n-9917 -9974\n-197 -9901", "output": "3 4" }, { "input": "3\n-1 1\n1 0\n-1 -1", "output": "1 3" }, { "input": "3\n1 1\n-10 -10\n-10 -9", "output": "3 2" }, { "input": "3\n1 0\n10000 -1\n-1 0", "output": "2 1" }, { "input": "4\n9999 1\n9999 -1\n-10000 1\n-10000 -1", "output": "3 4" }, { "input": "3\n-5 1\n-5 -1\n1 0", "output": "1 2" }, { "input": "3\n1 0\n10000 1\n-1 0", "output": "1 2" }, { "input": "4\n-9990 9995\n9994 -9991\n-9999 -9992\n9993 9992", "output": "2 4" }, { "input": "8\n1 0\n1 1\n0 1\n-1 1\n-1 0\n-1 -1\n0 -1\n1 -2", "output": "7 8" }, { "input": "3\n-9930 9932\n9909 -9909\n-9932 -9931", "output": "3 2" }, { "input": "4\n9876 9977\n127 9938\n-9820 -9934\n-120 -9921", "output": "3 4" }, { "input": "3\n10000 -1\n-1 0\n0 -1", "output": "3 1" }, { "input": "4\n6427 -6285\n5386 -5267\n3898 7239\n3905 7252", "output": "3 4" }, { "input": "4\n9811 9970\n155 9994\n-9826 -9977\n-159 -9986", "output": "1 2" }, { "input": "4\n9851 9917\n74 9921\n-9855 -9916\n-77 -9984", "output": "1 2" }, { "input": "4\n9826 9977\n159 9986\n-9811 -9970\n-155 -9994", "output": "3 4" }, { "input": "4\n9849 9986\n148 9980\n-9800 -9999\n-116 -9927", "output": "3 4" }, { "input": "4\n9822 9967\n111 9905\n-9943 -9986\n-163 -9953", "output": "1 2" }, { "input": "4\n9959 9995\n113 9940\n-9965 -9931\n-148 -9945", "output": "1 2" }, { "input": "4\n9851 9972\n153 9983\n-9866 -9926\n-183 -9946", "output": "1 2" }, { "input": "4\n9816 -9979\n127 -9940\n-9876 9915\n-190 9978", "output": "2 1" }, { "input": "4\n9887 -9917\n138 -9977\n-9826 9995\n-68 9971", "output": "2 1" }, { "input": "4\n9936 -9965\n135 -9949\n-9928 9980\n-123 9908", "output": "2 1" }, { "input": "4\n9981 -9985\n191 -9956\n-9893 9937\n-171 9962", "output": "2 1" }, { "input": "4\n-9811 9970\n-155 9994\n9826 -9977\n159 -9986", "output": "2 1" }, { "input": "4\n9808 9899\n179 9966\n-9870 -9961\n-179 -9950", "output": "3 4" }, { "input": "4\n9815 -9936\n168 -9937\n-9896 9995\n-180 9969", "output": "2 1" }, { "input": "4\n1 1\n1 -1\n-100 1\n-100 -1", "output": "3 4" }, { "input": "4\n9965 114\n87 9916\n-9957 -106\n-95 -9929", "output": "3 4" }, { "input": "4\n9895 -9949\n188 -9978\n-9810 9935\n-151 9914", "output": "2 1" }, { "input": "4\n-9957 106\n-95 9929\n9965 -114\n87 -9916", "output": "2 1" }, { "input": "4\n-9862 9980\n-174 9917\n9845 -9967\n173 -9980", "output": "2 1" }, { "input": "4\n9944 9926\n9927 9935\n-9961 -9929\n-9997 -9991", "output": "3 4" }, { "input": "4\n9917 9909\n196 9925\n-9971 -9991\n-183 -9977", "output": "3 4" } ]
1,682,806,183
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
483
0
#!/usr/bin/env python3 import math n = int(input()) vectors = [] best = [0,0,6] for _ in range(n): a = input() a = a.split() a = [int(x) for x in a] vectors.append(a) for i in range(n): for j in range(i+1, n): dot = vectors[i][0] * vectors[j][0] + vectors[i][1] * vectors[j][1] magnitudes = math.sqrt((vectors[i][0])**2 + (vectors[i][1])**2) * math.sqrt((vectors[j][0])**2 + (vectors[j][1])**2) theta = math.acos(dot/magnitudes) if theta < best[2]: best[2] = theta best[0] = i best[1] = j print(best[0] + 1, best[1] + 1)
Title: Nearest vectors Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π. Input Specification: First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors. The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=&gt;<=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions). Output Specification: Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any. Demo Input: ['4\n-1 0\n0 -1\n1 0\n1 1\n', '6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n'] Demo Output: ['3 4\n', '6 5'] Note: none
```python #!/usr/bin/env python3 import math n = int(input()) vectors = [] best = [0,0,6] for _ in range(n): a = input() a = a.split() a = [int(x) for x in a] vectors.append(a) for i in range(n): for j in range(i+1, n): dot = vectors[i][0] * vectors[j][0] + vectors[i][1] * vectors[j][1] magnitudes = math.sqrt((vectors[i][0])**2 + (vectors[i][1])**2) * math.sqrt((vectors[j][0])**2 + (vectors[j][1])**2) theta = math.acos(dot/magnitudes) if theta < best[2]: best[2] = theta best[0] = i best[1] = j print(best[0] + 1, best[1] + 1) ```
-1
299
B
Ksusha the Squirrel
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks. Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".".
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
[ "2 1\n..\n", "5 2\n.#.#.\n", "7 3\n.#.###.\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
1,000
[ { "input": "2 1\n..", "output": "YES" }, { "input": "5 2\n.#.#.", "output": "YES" }, { "input": "7 3\n.#.###.", "output": "NO" }, { "input": "2 200\n..", "output": "YES" }, { "input": "2 1\n..", "output": "YES" }, { "input": "2 2\n..", "output": "YES" }, { "input": "2 100000\n..", "output": "YES" }, { "input": "3 1\n.#.", "output": "NO" }, { "input": "3 2\n.#.", "output": "YES" }, { "input": "3 10000\n.#.", "output": "YES" } ]
1,687,268,059
2,147,483,647
PyPy 3-64
OK
TESTS
33
186
10,444,800
n,k=map(int,input().split()) a=input() b=[] r=0 i=0 while i<n: if a[i]=='#': r+=1 else: b+=[r] r=0 i+=1 cr=max(b) if cr>=k: print("NO") else: print("YES")
Title: Ksusha the Squirrel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks. Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". Output Specification: Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). Demo Input: ['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python n,k=map(int,input().split()) a=input() b=[] r=0 i=0 while i<n: if a[i]=='#': r+=1 else: b+=[r] r=0 i+=1 cr=max(b) if cr>=k: print("NO") else: print("YES") ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "output": "5464380" }, { "input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "output": "9535765" }, { "input": "3\n1 3 2", "output": "3" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n228503", "output": "0" }, { "input": "2\n32576 550340", "output": "517764" }, { "input": "3\n910648 542843 537125", "output": "741328" }, { "input": "4\n751720 572344 569387 893618", "output": "787403" }, { "input": "6\n433864 631347 597596 794426 713555 231193", "output": "1364575" }, { "input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "output": "4647430" }, { "input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "output": "13488674" }, { "input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "output": "21993384" }, { "input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "output": "26984185" }, { "input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "output": "32816391" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n5 0 0", "output": "10" }, { "input": "5\n2 10 0 0 0", "output": "38" } ]
1,674,662,900
2,147,483,647
Python 3
OK
TESTS
41
46
0
a=int(input()) b=list(map(int,input().split())) m=max(b) q=sum(b) print(a*m-q)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. Output Specification: In the only line print the integer *S* — the minimum number of burles which are had to spend. Demo Input: ['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n'] Demo Output: ['10', '1', '4', '0'] Note: In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
```python a=int(input()) b=list(map(int,input().split())) m=max(b) q=sum(b) print(a*m-q) ```
3
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased. You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars. As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses. It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars.
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away.
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "output": "20" }, { "input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20", "output": "10" }, { "input": "7 5 1\n0 100 2 2 0 2 1", "output": "20" }, { "input": "100 50 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 0 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": "10" }, { "input": "100 50 1\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 0 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": "490" }, { "input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0", "output": "10" }, { "input": "100 1 1\n0 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 0", "output": "980" }, { "input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "10" }, { "input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98", "output": "890" }, { "input": "7 4 5\n1 0 6 0 5 6 0", "output": "10" }, { "input": "7 4 5\n1 6 5 0 0 6 0", "output": "10" }, { "input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0", "output": "90" }, { "input": "2 1 100\n0 1", "output": "10" }, { "input": "2 2 100\n1 0", "output": "10" }, { "input": "10 1 88\n0 95 0 0 0 0 0 94 0 85", "output": "90" }, { "input": "10 2 14\n2 0 1 26 77 39 41 100 13 32", "output": "10" }, { "input": "10 3 11\n0 0 0 0 0 62 0 52 1 35", "output": "60" }, { "input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88", "output": "10" }, { "input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82", "output": "70" }, { "input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1", "output": "180" }, { "input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0", "output": "210" }, { "input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37", "output": "80" }, { "input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77", "output": "190" }, { "input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84", "output": "190" }, { "input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15", "output": "580" }, { "input": "97 44 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51 19", "output": "520" }, { "input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67", "output": "490" }, { "input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23", "output": "890" }, { "input": "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14", "output": "970" }, { "input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10", "output": "990" }, { "input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10", "output": "490" }, { "input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2", "output": "500" }, { "input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20", "output": "50" }, { "input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0", "output": "990" }, { "input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0", "output": "10" }, { "input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51", "output": "140" }, { "input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4", "output": "390" }, { "input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68", "output": "130" }, { "input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59", "output": "10" }, { "input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32", "output": "10" }, { "input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98", "output": "160" }, { "input": "5 2 20\n27 0 32 21 19", "output": "30" }, { "input": "6 4 10\n10 0 0 0 0 10", "output": "20" }, { "input": "8 7 100\n1 0 0 0 0 0 0 1", "output": "10" }, { "input": "5 3 20\n1 21 0 0 1", "output": "20" }, { "input": "4 3 1\n0 0 0 1", "output": "10" }, { "input": "5 2 3\n4 0 5 6 1", "output": "30" }, { "input": "5 3 87\n88 89 0 1 90", "output": "10" }, { "input": "5 3 20\n15 30 0 15 35", "output": "10" }, { "input": "6 3 50\n0 0 0 1 2 0", "output": "10" }, { "input": "6 4 9\n100 9 10 0 0 9", "output": "20" }, { "input": "5 4 20\n0 20 0 0 20", "output": "10" }, { "input": "6 3 3\n1 5 0 2 2 0", "output": "10" }, { "input": "5 4 100\n0 1 0 0 1", "output": "10" } ]
1,613,618,514
2,147,483,647
PyPy 3
OK
TESTS
58
109
0
n,m,k=map(int,input().split()) a=list(map(int,input().split())) l=a[:m-1] l=l[::-1] r=a[m:] ind1=100000 ind2=100000 if(m!=1): for i in range(0,len(l)): if(l[i]<=k and l[i]!=0): ind1=i ind1=len(l)-i-1 break if(m!=n): for i in range(len(r)): if(r[i]!=0 and r[i]<=k): ind2=i+m #print(r[i]) break #print(ind2) mini=min(abs(m-1-ind1),abs(m-1-ind2)) print(mini*10)
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased. You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars. As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. Input Specification: The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses. It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. Output Specification: Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. Demo Input: ['5 1 20\n0 27 32 21 19\n', '7 3 50\n62 0 0 0 99 33 22\n', '10 5 100\n1 0 1 0 0 0 0 0 1 1\n'] Demo Output: ['40', '30', '20'] Note: In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away.
```python n,m,k=map(int,input().split()) a=list(map(int,input().split())) l=a[:m-1] l=l[::-1] r=a[m:] ind1=100000 ind2=100000 if(m!=1): for i in range(0,len(l)): if(l[i]<=k and l[i]!=0): ind1=i ind1=len(l)-i-1 break if(m!=n): for i in range(len(r)): if(r[i]!=0 and r[i]<=k): ind2=i+m #print(r[i]) break #print(ind2) mini=min(abs(m-1-ind1),abs(m-1-ind2)) print(mini*10) ```
3
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,686,480,789
2,147,483,647
PyPy 3-64
OK
TESTS
20
46
0
for j in range(int(input())): a=input() s = len(a) - 2 if s > 8: print(a[0] + str(s) + a[-1]) else: print(a)
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 j in range(int(input())): a=input() s = len(a) - 2 if s > 8: print(a[0] + str(s) + a[-1]) else: print(a) ```
3.977
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,661,156,462
2,147,483,647
Python 3
OK
TESTS
44
92
0
s=str(input()) c=0 d=0 k=0 p=0 for i in s: if i=='1': c=c+1 else: k=max(k,c) c=0 k=max(k,c) for i in s: if i=='0': d=d+1 else: p=max(p,d) d=0 p=max(p,d) if k>=7 or p>=7: print("YES") else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python s=str(input()) c=0 d=0 k=0 p=0 for i in s: if i=='1': c=c+1 else: k=max(k,c) c=0 k=max(k,c) for i in s: if i=='0': d=d+1 else: p=max(p,d) d=0 p=max(p,d) if k>=7 or p>=7: print("YES") else: print("NO") ```
3.977
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,613,916,881
2,147,483,647
Python 3
OK
TESTS
30
154
0
word = input() uppercase, lowercase = 0, 0 for char in word: if 65 <= ord(char) <= 90: uppercase += 1 else: lowercase += 1 if lowercase >= uppercase: print(word.lower()) else: print(word.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 word = input() uppercase, lowercase = 0, 0 for char in word: if 65 <= ord(char) <= 90: uppercase += 1 else: lowercase += 1 if lowercase >= uppercase: print(word.lower()) else: print(word.upper()) ```
3.9615
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111", "output": "10" }, { "input": "1\n0", "output": "0" }, { "input": "8\n10101010", "output": "10000" }, { "input": "2\n10", "output": "10" }, { "input": "3\n111", "output": "1" }, { "input": "5\n11100", "output": "100" }, { "input": "2\n11", "output": "1" }, { "input": "3\n110", "output": "10" }, { "input": "50\n10010010000000000000000000000000000000001000000000", "output": "10000000000000000000000000000000000000000000000" } ]
1,612,809,063
363
Python 3
WRONG_ANSWER
TESTS
2
46
307,200
import bisect import math import itertools import sys # import sys.stdout.flush() use for interactive problems alpha = 'abcdefghijklmnopqrstuvwxyz' def solve(n,s): if s == '0': return 0 ones = s.count('1') zeros = s.count('0') return '1'*max(ones-1,1) +'0'*zeros pass t = 1#int(input()) ans = [] for _ in range(t): n = int(input()) s = input() #A,B,n = map(int, input().split()) #arr = list(input()) #strings = [str(x) for x in input().split()] #a = [int(x) for x in input().split()] #b = [int(x) for x in input().split()] #painters = [int(x) for x in input().split()] #ls = [int(x) for x in input().split()] # n = nk[0] # k = nk[1] # k = nmk[2] # arr = [int(x) for x in input().split()] # s1 = input() # s2 = input() # x = xy[0] # y = xy[1] # x = xy[0] # y = xy[1] # a = [int(x) for x in input().split()] # b = [int(x) for x in input().split()] # s = input() # grid = [] # for j in range(n): # arr = list(input()) # grid.append(arr) # options = [int(x) for x in input().split()] """cs = [] for j in range(nx1y1x2y2c[-1]): cs.append([int(x) for x in input().split()])""" """grid = [] for j in range(n): grid.append(list(input()))""" # s = list(input()) # start,end = map(int,input().split()) ans.append(solve(n,s)) for test in ans: print(test)
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. Output Specification: Print one string — the minimum correct string that you can obtain from the given one. Demo Input: ['4\n1001\n', '1\n1\n'] Demo Output: ['100\n', '1\n'] Note: In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
```python import bisect import math import itertools import sys # import sys.stdout.flush() use for interactive problems alpha = 'abcdefghijklmnopqrstuvwxyz' def solve(n,s): if s == '0': return 0 ones = s.count('1') zeros = s.count('0') return '1'*max(ones-1,1) +'0'*zeros pass t = 1#int(input()) ans = [] for _ in range(t): n = int(input()) s = input() #A,B,n = map(int, input().split()) #arr = list(input()) #strings = [str(x) for x in input().split()] #a = [int(x) for x in input().split()] #b = [int(x) for x in input().split()] #painters = [int(x) for x in input().split()] #ls = [int(x) for x in input().split()] # n = nk[0] # k = nk[1] # k = nmk[2] # arr = [int(x) for x in input().split()] # s1 = input() # s2 = input() # x = xy[0] # y = xy[1] # x = xy[0] # y = xy[1] # a = [int(x) for x in input().split()] # b = [int(x) for x in input().split()] # s = input() # grid = [] # for j in range(n): # arr = list(input()) # grid.append(arr) # options = [int(x) for x in input().split()] """cs = [] for j in range(nx1y1x2y2c[-1]): cs.append([int(x) for x in input().split()])""" """grid = [] for j in range(n): grid.append(list(input()))""" # s = list(input()) # start,end = map(int,input().split()) ans.append(solve(n,s)) for test in ans: print(test) ```
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, { "input": "24 54 37\n60 63 6\n1 84 26", "output": "110\n101\n011" }, { "input": "23 10 40\n15 6 40\n92 80 77", "output": "101\n100\n000" }, { "input": "62 74 80\n95 74 93\n2 47 95", "output": "010\n001\n110" }, { "input": "80 83 48\n26 0 66\n47 76 37", "output": "000\n000\n010" }, { "input": "32 15 65\n7 54 36\n5 51 3", "output": "111\n101\n001" }, { "input": "22 97 12\n71 8 24\n100 21 64", "output": "100\n001\n100" }, { "input": "46 37 13\n87 0 50\n90 8 55", "output": "111\n011\n000" }, { "input": "57 43 58\n20 82 83\n66 16 52", "output": "111\n010\n110" }, { "input": "45 56 93\n47 51 59\n18 51 63", "output": "101\n011\n100" }, { "input": "47 66 67\n14 1 37\n27 81 69", "output": "001\n001\n110" }, { "input": "26 69 69\n85 18 23\n14 22 74", "output": "110\n001\n010" }, { "input": "10 70 65\n94 27 25\n74 66 30", "output": "111\n010\n100" }, { "input": "97 1 74\n15 99 1\n88 68 86", "output": "001\n011\n000" }, { "input": "36 48 42\n45 41 66\n26 64 1", "output": "001\n111\n010" }, { "input": "52 81 97\n29 77 71\n66 11 2", "output": "100\n100\n111" }, { "input": "18 66 33\n19 49 49\n48 46 26", "output": "011\n100\n000" }, { "input": "68 79 52\n51 39 100\n29 14 26", "output": "110\n000\n111" }, { "input": "91 69 77\n91 26 64\n91 88 57", "output": "001\n011\n110" }, { "input": "16 69 64\n48 21 80\n81 51 51", "output": "010\n101\n111" }, { "input": "96 14 2\n100 18 12\n65 34 89", "output": "111\n010\n010" }, { "input": "93 95 90\n8 59 42\n53 13 19", "output": "100\n001\n111" }, { "input": "71 84 18\n100 19 67\n9 76 15", "output": "010\n010\n001" }, { "input": "38 93 85\n21 88 64\n4 96 25", "output": "111\n011\n000" }, { "input": "75 20 20\n60 5 78\n77 4 69", "output": "011\n001\n000" }, { "input": "65 70 96\n19 6 83\n33 37 82", "output": "100\n000\n011" }, { "input": "11 13 60\n17 13 46\n42 21 39", "output": "000\n011\n101" }, { "input": "0 0 0\n0 0 0\n0 0 0", "output": "111\n111\n111" }, { "input": "0 0 0\n0 1 0\n0 0 0", "output": "101\n000\n101" }, { "input": "0 0 0\n0 0 0\n0 0 1", "output": "111\n110\n100" } ]
1,679,945,260
2,147,483,647
Python 3
OK
TESTS
33
46
0
ans = [[1,1,1],[1,1,1],[1,1,1]] grid = [] def solve(a): if a == 1: return 0 else: return 1 for i in range(3): a = list(map(int,input().split())) grid.append(a) if grid[0][0] % 2 != 0: ans[0][0] = solve(ans[0][0]) ans[1][0] = solve(ans[1][0]) ans[0][1] = solve(ans[0][1]) if grid[0][1] % 2 != 0: ans[0][1] = solve(ans[0][1]) ans[0][0] = solve(ans[0][0]) ans[0][2] = solve(ans[0][2]) ans[1][1] = solve(ans[1][1]) if grid[0][2] % 2 != 0: ans[0][2] = solve(ans[0][2]) ans[0][1] = solve(ans[0][1]) ans[1][2] = solve(ans[1][2]) if grid[1][0] % 2 != 0: ans[1][0] = solve(ans[1][0]) ans[0][0] = solve(ans[0][0]) ans[1][1] = solve(ans[1][1]) ans[2][0] = solve(ans[2][0]) if grid[1][1] % 2 != 0: ans[1][1] = solve(ans[1][1]) ans[0][1] = solve(ans[0][1]) ans[1][0] = solve(ans[1][0]) ans[1][2] = solve(ans[1][2]) ans[2][1] = solve(ans[2][1]) if grid[1][2] % 2 != 0: ans[1][2] = solve(ans[1][2]) ans[0][2] = solve(ans[0][2]) ans[1][1] = solve(ans[1][1]) ans[2][2] = solve(ans[2][2]) if grid[2][0] % 2 != 0: ans[2][0] = solve(ans[2][0]) ans[1][0] = solve(ans[1][0]) ans[2][1] = solve(ans[2][1]) if grid[2][1] % 2 != 0: ans[2][1] = solve(ans[2][1]) ans[2][0] = solve(ans[2][0]) ans[1][1] = solve(ans[1][1]) ans[2][2] = solve(ans[2][2]) if grid[2][2] % 2 != 0: ans[2][2] = solve(ans[2][2]) ans[1][2] = solve(ans[1][2]) ans[2][1] = solve(ans[2][1]) for i in range(3): temp = '' for j in range(3): temp += str(ans[i][j]) print(temp)
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. Input Specification: The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. Output Specification: Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". Demo Input: ['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n'] Demo Output: ['001\n010\n100\n', '010\n011\n100\n'] Note: none
```python ans = [[1,1,1],[1,1,1],[1,1,1]] grid = [] def solve(a): if a == 1: return 0 else: return 1 for i in range(3): a = list(map(int,input().split())) grid.append(a) if grid[0][0] % 2 != 0: ans[0][0] = solve(ans[0][0]) ans[1][0] = solve(ans[1][0]) ans[0][1] = solve(ans[0][1]) if grid[0][1] % 2 != 0: ans[0][1] = solve(ans[0][1]) ans[0][0] = solve(ans[0][0]) ans[0][2] = solve(ans[0][2]) ans[1][1] = solve(ans[1][1]) if grid[0][2] % 2 != 0: ans[0][2] = solve(ans[0][2]) ans[0][1] = solve(ans[0][1]) ans[1][2] = solve(ans[1][2]) if grid[1][0] % 2 != 0: ans[1][0] = solve(ans[1][0]) ans[0][0] = solve(ans[0][0]) ans[1][1] = solve(ans[1][1]) ans[2][0] = solve(ans[2][0]) if grid[1][1] % 2 != 0: ans[1][1] = solve(ans[1][1]) ans[0][1] = solve(ans[0][1]) ans[1][0] = solve(ans[1][0]) ans[1][2] = solve(ans[1][2]) ans[2][1] = solve(ans[2][1]) if grid[1][2] % 2 != 0: ans[1][2] = solve(ans[1][2]) ans[0][2] = solve(ans[0][2]) ans[1][1] = solve(ans[1][1]) ans[2][2] = solve(ans[2][2]) if grid[2][0] % 2 != 0: ans[2][0] = solve(ans[2][0]) ans[1][0] = solve(ans[1][0]) ans[2][1] = solve(ans[2][1]) if grid[2][1] % 2 != 0: ans[2][1] = solve(ans[2][1]) ans[2][0] = solve(ans[2][0]) ans[1][1] = solve(ans[1][1]) ans[2][2] = solve(ans[2][2]) if grid[2][2] % 2 != 0: ans[2][2] = solve(ans[2][2]) ans[1][2] = solve(ans[1][2]) ans[2][1] = solve(ans[2][1]) for i in range(3): temp = '' for j in range(3): temp += str(ans[i][j]) print(temp) ```
3
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "YES" }, { "input": "48\nthereisasyetinsufficientdataforameaningfulanswer", "output": "NO" }, { "input": "30\nToBeOrNotToBeThatIsTheQuestion", "output": "NO" }, { "input": "30\njackdawslovemybigsphinxofquarz", "output": "NO" }, { "input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "output": "YES" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "NO" }, { "input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "output": "YES" }, { "input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "output": "YES" }, { "input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "output": "YES" }, { "input": "25\nnxYTzLFwzNolAumjgcAboyxAj", "output": "NO" }, { "input": "26\npRWdodGdxUESvcScPGbUoooZsC", "output": "NO" }, { "input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "output": "NO" }, { "input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "output": "YES" }, { "input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "output": "NO" }, { "input": "26\nvCUFRKElZOnjmXGylWQaHDiPst", "output": "NO" }, { "input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "output": "NO" }, { "input": "26\npGiFluRteQwkaVoPszJyNBChxM", "output": "NO" }, { "input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "output": "NO" }, { "input": "26\nLndjgvAEuICHKxPwqYztosrmBN", "output": "NO" }, { "input": "26\nMdaXJrCipnOZLykfqHWEStevbU", "output": "NO" }, { "input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "output": "NO" }, { "input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "output": "NO" }, { "input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "output": "NO" }, { "input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "output": "NO" }, { "input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "output": "NO" }, { "input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "output": "NO" }, { "input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "output": "NO" }, { "input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "output": "NO" }, { "input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "output": "NO" }, { "input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "output": "NO" }, { "input": "26\nDqspXZJTuONYieKgaHLMBwfVSC", "output": "NO" }, { "input": "26\necOyUkqNljFHRVXtIpWabGMLDz", "output": "NO" }, { "input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "output": "NO" }, { "input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "output": "NO" }, { "input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "output": "NO" }, { "input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "output": "NO" }, { "input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "output": "NO" }, { "input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "output": "NO" }, { "input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "output": "NO" }, { "input": "26\nmnbvcxxlkjhgfdsapoiuytrewq", "output": "NO" }, { "input": "26\naAbcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "output": "NO" }, { "input": "25\nabcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "26\nabcdefhijklmnopqrstVxyzABC", "output": "NO" }, { "input": "25\nqwertyuiopasdfghjklxcvbnm", "output": "NO" }, { "input": "34\nTheQuickBrownFoxJumpsOverTheLayDog", "output": "NO" }, { "input": "26\nabcdefghigklmnopqrstuvwxyz", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxyA", "output": "NO" }, { "input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "output": "NO" }, { "input": "25\nbcdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "output": "NO" }, { "input": "26\nabcdefghiklmnopqrstvxyzABC", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxzZ", "output": "NO" }, { "input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY", "output": "NO" } ]
1,695,465,406
2,147,483,647
Python 3
OK
TESTS
59
46
0
n = int(input()) sentence = input().lower() print('NO' if n<26 or len(set(sentence))<26 else 'YES')
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python n = int(input()) sentence = input().lower() print('NO' if n<26 or len(set(sentence))<26 else 'YES') ```
3
121
A
Lucky Sum
PROGRAMMING
1,100
[ "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2 7\n", "7 7\n" ]
[ "33\n", "7\n" ]
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
500
[ { "input": "2 7", "output": "33" }, { "input": "7 7", "output": "7" }, { "input": "1 9", "output": "125" }, { "input": "4 7", "output": "25" }, { "input": "12 47", "output": "1593" }, { "input": "6 77", "output": "4012" }, { "input": "1 100", "output": "14247" }, { "input": "1000000000 1000000000", "output": "4444444444" }, { "input": "77 77", "output": "77" }, { "input": "69 788", "output": "452195" }, { "input": "474 747", "output": "202794" }, { "input": "4 77777", "output": "4070145675" }, { "input": "1 1000000", "output": "1394675359387" }, { "input": "47 744447", "output": "381286992761" }, { "input": "47444 1000000000", "output": "1394672348253941136" }, { "input": "48 854888", "output": "749733199853" }, { "input": "854444 985555", "output": "582719941728" }, { "input": "774744 774747", "output": "3098985" }, { "input": "654 987654", "output": "1339803940266" }, { "input": "477777 1000000000", "output": "1394672167300009765" }, { "input": "77777 777777777", "output": "407018021649898097" }, { "input": "963 85555574", "output": "7526978888069560" }, { "input": "47 7444", "output": "38125896" }, { "input": "1 1000000000", "output": "1394672350065645019" }, { "input": "474 999888555", "output": "1394177038954402791" }, { "input": "777 1000000000", "output": "1394672350065239125" }, { "input": "7 777777774", "output": "407018023386632646" }, { "input": "369 852", "output": "606732" }, { "input": "47 47", "output": "47" }, { "input": "747 748", "output": "1521" }, { "input": "77777440 77777444", "output": "388887220" }, { "input": "987545885 999875584", "output": "54798666661186800" }, { "input": "2 777777776", "output": "407018024942188226" }, { "input": "1 1", "output": "4" }, { "input": "1 2", "output": "8" }, { "input": "999999999 1000000000", "output": "8888888888" }, { "input": "777777777 1000000000", "output": "987654325123456789" }, { "input": "777777778 1000000000", "output": "987654324345679012" }, { "input": "5 6", "output": "14" }, { "input": "49 49", "output": "74" }, { "input": "6 6", "output": "7" }, { "input": "3 4", "output": "8" } ]
1,625,557,603
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
l,r=map(int,input().split()) if (4-l)>=0: d=((4-l)+1)*4 c=(r-4)*7 print(d+c) else: print((r-l+1)*7)
Title: Lucky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. Input Specification: The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. Output Specification: In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['2 7\n', '7 7\n'] Demo Output: ['33\n', '7\n'] Note: In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
```python l,r=map(int,input().split()) if (4-l)>=0: d=((4-l)+1)*4 c=(r-4)*7 print(d+c) else: print((r-l+1)*7) ```
0
250
C
Movie Critics
PROGRAMMING
1,600
[ "greedy" ]
null
null
A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*. On the *i*-th day the festival will show a movie of genre *a**i*. We know that a movie of each of *k* genres occurs in the festival programme at least once. In other words, each integer from 1 to *k* occurs in the sequence *a*1,<=*a*2,<=...,<=*a**n* at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all *n* movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the *k* genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre *x* (1<=≤<=*x*<=≤<=*k*), that the total number of after-movie stresses (after all movies of genre *x* are excluded) were minimum.
The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=105), where *n* is the number of movies and *k* is the number of genres. The second line of the input contains a sequence of *n* positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*k*), where *a**i* is the genre of the *i*-th movie. It is guaranteed that each number from 1 to *k* occurs at least once in this sequence.
Print a single number — the number of the genre (from 1 to *k*) of the excluded films. If there are multiple answers, print the genre with the minimum number.
[ "10 3\n1 1 2 3 2 3 3 1 1 3\n", "7 3\n3 1 3 2 3 1 2\n" ]
[ "3", "1" ]
In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
1,500
[ { "input": "10 3\n1 1 2 3 2 3 3 1 1 3", "output": "3" }, { "input": "7 3\n3 1 3 2 3 1 2", "output": "1" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "10 2\n1 2 2 1 1 2 1 1 2 2", "output": "1" }, { "input": "10 10\n5 7 8 2 4 10 1 3 9 6", "output": "1" }, { "input": "100 10\n6 2 8 1 7 1 2 9 2 6 10 4 2 8 7 5 2 9 5 2 3 2 8 3 7 2 4 3 1 8 8 5 7 10 2 1 8 4 1 4 9 4 2 1 9 3 7 2 4 8 4 3 10 3 9 5 7 7 1 2 10 7 7 8 9 7 1 7 4 8 9 4 1 10 2 4 2 10 9 6 10 5 1 4 2 1 3 1 6 9 10 1 8 9 1 9 1 1 7 6", "output": "1" }, { "input": "74 10\n10 5 4 7 1 9 3 5 10 7 1 4 8 8 4 1 3 9 3 3 10 6 10 4 2 8 9 7 3 2 5 3 6 7 10 4 4 7 8 2 3 10 5 10 5 10 7 9 9 6 1 10 8 9 7 8 9 10 3 6 10 9 9 5 10 6 4 3 5 3 6 8 9 3", "output": "10" }, { "input": "113 3\n1 3 2 2 1 3 1 2 2 2 3 1 1 3 1 3 3 1 2 2 1 3 2 3 3 1 3 1 1 3 3 1 2 3 3 1 3 3 2 3 3 1 1 1 1 2 3 2 2 3 3 2 3 1 3 2 1 3 2 1 1 2 2 2 2 2 1 1 3 3 2 1 1 3 2 2 1 3 1 1 1 3 3 2 1 2 2 3 3 1 3 1 2 2 1 2 2 3 3 2 3 1 3 1 1 2 3 2 3 2 3 1 3", "output": "3" }, { "input": "129 37\n15 22 28 15 30 16 11 20 4 26 14 37 29 17 15 15 14 18 1 9 16 22 13 32 5 18 25 11 6 33 33 22 17 9 1 5 27 27 37 4 6 1 3 18 11 33 6 17 2 24 23 1 1 37 35 21 21 17 18 6 31 17 29 18 10 10 30 31 8 3 25 20 34 11 12 12 24 13 5 27 20 31 28 3 36 2 4 13 14 9 33 25 4 26 36 6 2 7 15 9 20 33 24 33 28 12 23 1 28 12 29 3 35 33 26 15 3 19 1 23 23 32 2 27 11 7 36 34 36", "output": "1" }, { "input": "100 13\n1 1 9 10 6 1 12 13 9 5 3 7 3 5 2 2 10 1 3 8 9 4 4 4 2 10 12 11 1 5 7 13 4 12 5 9 3 13 5 10 7 2 1 7 2 2 4 10 3 10 6 11 13 1 4 3 8 8 9 8 13 4 4 3 7 12 5 5 8 13 1 9 8 12 12 10 4 7 7 12 1 4 3 4 9 6 4 13 10 12 10 9 8 13 13 5 6 9 7 13", "output": "3" }, { "input": "100 12\n9 12 3 3 1 3 12 12 7 9 6 5 8 12 10 7 8 3 4 8 5 9 9 10 9 7 4 5 10 7 4 1 11 6 5 9 1 2 9 9 1 10 6 8 9 10 7 9 10 3 6 4 9 12 11 10 4 4 2 12 11 8 4 9 12 6 4 7 5 1 5 2 7 4 10 2 5 6 4 2 5 8 6 9 6 4 8 6 2 11 4 12 3 1 1 11 1 6 1 10", "output": "9" } ]
1,670,235,638
2,147,483,647
PyPy 3-64
OK
TESTS
44
248
14,233,600
import sys input = sys.stdin.readline from itertools import groupby n, k = map(int, input().split()) d = [list(j)[0] for i, j in groupby(map(int, input().split()))] q = [0]*(k+1) for i in range(len(d)): if i not in [0, len(d)-1] and d[i-1] == d[i+1]: q[d[i]] += 1 q[d[i]] += 1 print(max(1, q.index(max(q))))
Title: Movie Critics Time Limit: None seconds Memory Limit: None megabytes Problem Description: A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*. On the *i*-th day the festival will show a movie of genre *a**i*. We know that a movie of each of *k* genres occurs in the festival programme at least once. In other words, each integer from 1 to *k* occurs in the sequence *a*1,<=*a*2,<=...,<=*a**n* at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all *n* movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the *k* genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre *x* (1<=≤<=*x*<=≤<=*k*), that the total number of after-movie stresses (after all movies of genre *x* are excluded) were minimum. Input Specification: The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=105), where *n* is the number of movies and *k* is the number of genres. The second line of the input contains a sequence of *n* positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*k*), where *a**i* is the genre of the *i*-th movie. It is guaranteed that each number from 1 to *k* occurs at least once in this sequence. Output Specification: Print a single number — the number of the genre (from 1 to *k*) of the excluded films. If there are multiple answers, print the genre with the minimum number. Demo Input: ['10 3\n1 1 2 3 2 3 3 1 1 3\n', '7 3\n3 1 3 2 3 1 2\n'] Demo Output: ['3', '1'] Note: In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
```python import sys input = sys.stdin.readline from itertools import groupby n, k = map(int, input().split()) d = [list(j)[0] for i, j in groupby(map(int, input().split()))] q = [0]*(k+1) for i in range(len(d)): if i not in [0, len(d)-1] and d[i-1] == d[i+1]: q[d[i]] += 1 q[d[i]] += 1 print(max(1, q.index(max(q)))) ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "4\nRBBR", "output": "1" }, { "input": "5\nRGGBG", "output": "1" }, { "input": "10\nGGBRBRGGRB", "output": "2" }, { "input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "output": "18" }, { "input": "15\nBRRBRGGBBRRRRGR", "output": "6" }, { "input": "20\nRRGBBRBRGRGBBGGRGRRR", "output": "6" }, { "input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "output": "6" }, { "input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "output": "9" }, { "input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB", "output": "14" }, { "input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG", "output": "20" }, { "input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG", "output": "11" }, { "input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG", "output": "17" }, { "input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB", "output": "16" }, { "input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG", "output": "19" }, { "input": "10\nGRRBRBRBGR", "output": "1" }, { "input": "10\nBRBGBGRRBR", "output": "1" }, { "input": "20\nGBGBGGRRRRGRBBGRGRGR", "output": "5" }, { "input": "20\nRRGGRBBGBBRBGRRBRRBG", "output": "6" }, { "input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB", "output": "8" }, { "input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB", "output": "11" }, { "input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB", "output": "9" }, { "input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG", "output": "13" }, { "input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG", "output": "13" }, { "input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB", "output": "12" }, { "input": "2\nBB", "output": "1" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "49" }, { "input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "47" }, { "input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR", "output": "43" } ]
1,696,733,130
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
n, t = list(map(int, input().split())) s = list(input()) count = 0 for k in range(0,t): for i in range(0,n): if(s[i]=='B' and s[i+1]=='G'): temp = s[i] s[i]= s[i+1] s[i+1] = temp count += 1 print(('').join(s))
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python n, t = list(map(int, input().split())) s = list(input()) count = 0 for k in range(0,t): for i in range(0,n): if(s[i]=='B' and s[i+1]=='G'): temp = s[i] s[i]= s[i+1] s[i+1] = temp count += 1 print(('').join(s)) ```
-1
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" }, { "input": "9", "output": "12870" }, { "input": "10", "output": "48620" }, { "input": "8", "output": "3432" } ]
1,677,043,199
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
z=[1,1,1,1,1] n=int(input()) f=[] for i in range(1,n): z=[z[0],z[0]+z[1],z[0]+z[1]+z[2],z[0]+z[1]+z[2]+z[3],z[0]+z[1]+z[2]+z[4]+z[3]] print(max(z))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. Input Specification: The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. Output Specification: Print a single line containing a positive integer *m* — the maximum value in the table. Demo Input: ['1\n', '5\n'] Demo Output: ['1', '70'] Note: In the second test the rows of the table look as follows:
```python z=[1,1,1,1,1] n=int(input()) f=[] for i in range(1,n): z=[z[0],z[0]+z[1],z[0]+z[1]+z[2],z[0]+z[1]+z[2]+z[3],z[0]+z[1]+z[2]+z[4]+z[3]] print(max(z)) ```
0
0
none
none
none
0
[ "none" ]
null
null
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to). Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language. Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match. Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}.
The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters.
On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order.
[ "abacabaca\n", "abaca\n" ]
[ "3\naca\nba\nca\n", "0\n" ]
The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
0
[ { "input": "abacabaca", "output": "3\naca\nba\nca" }, { "input": "abaca", "output": "0" }, { "input": "gzqgchv", "output": "1\nhv" }, { "input": "iosdwvzerqfi", "output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer" }, { "input": "oawtxikrpvfuzugjweki", "output": "25\neki\nfu\nfuz\ngj\ngjw\nik\nikr\njw\njwe\nki\nkr\nkrp\npv\npvf\nrp\nrpv\nug\nugj\nuz\nuzu\nvf\nvfu\nwe\nzu\nzug" }, { "input": "abcdexyzzzz", "output": "5\nxyz\nyz\nyzz\nzz\nzzz" }, { "input": "affviytdmexpwfqplpyrlniprbdphrcwlboacoqec", "output": "67\nac\naco\nbd\nbdp\nbo\nboa\nco\ncoq\ncw\ncwl\ndm\ndme\ndp\ndph\nec\nex\nexp\nfq\nfqp\nhr\nhrc\nip\nipr\nlb\nlbo\nln\nlni\nlp\nlpy\nme\nmex\nni\nnip\noa\noac\noq\nph\nphr\npl\nplp\npr\nprb\npw\npwf\npy\npyr\nqec\nqp\nqpl\nrb\nrbd\nrc\nrcw\nrl\nrln\ntd\ntdm\nwf\nwfq\nwl\nwlb\nxp\nxpw\nyr\nyrl\nyt\nytd" }, { "input": "lmnxtobrknqjvnzwadpccrlvisxyqbxxmghvl", "output": "59\nad\nadp\nbr\nbrk\nbx\nbxx\ncc\nccr\ncr\ncrl\ndp\ndpc\ngh\nhvl\nis\nisx\njv\njvn\nkn\nknq\nlv\nlvi\nmg\nmgh\nnq\nnqj\nnz\nnzw\nob\nobr\npc\npcc\nqb\nqbx\nqj\nqjv\nrk\nrkn\nrl\nrlv\nsx\nsxy\nvi\nvis\nvl\nvn\nvnz\nwa\nwad\nxm\nxmg\nxx\nxxm\nxy\nxyq\nyq\nyqb\nzw\nzwa" }, { "input": "tbdbdpkluawodlrwldjgplbiylrhuywkhafbkiuoppzsjxwbaqqiwagprqtoauowtaexrhbmctcxwpmplkyjnpwukzwqrqpv", "output": "170\nae\naex\naf\nafb\nag\nagp\naq\naqq\nau\nauo\naw\nawo\nba\nbaq\nbi\nbiy\nbk\nbki\nbm\nbmc\nct\nctc\ncx\ncxw\ndj\ndjg\ndl\ndlr\nex\nexr\nfb\nfbk\ngp\ngpl\ngpr\nha\nhaf\nhb\nhbm\nhu\nhuy\niu\niuo\niw\niwa\niy\niyl\njg\njgp\njn\njnp\njx\njxw\nkh\nkha\nki\nkiu\nkl\nklu\nky\nkyj\nkz\nkzw\nlb\nlbi\nld\nldj\nlk\nlky\nlr\nlrh\nlrw\nlu\nlua\nmc\nmct\nmp\nmpl\nnp\nnpw\noa\noau\nod\nodl\nop\nopp\now\nowt\npk\npkl\npl\nplb\nplk\npm\npmp\npp\nppz\npr\nprq\npv\npw\npwu\npz\npzs\nqi\nqiw\nqpv\nqq\nqqi\nqr\nqrq\nqt\nq..." }, { "input": "caqmjjtwmqxytcsawfufvlofqcqdwnyvywvbbhmpzqwqqxieptiaguwvqdrdftccsglgfezrzhstjcxdknftpyslyqdmkwdolwbusyrgyndqllgesktvgarpfkiglxgtcfepclqhgfbfmkymsszrtynlxbosmrvntsqwccdtahkpnelwiqn", "output": "323\nag\nagu\nah\nahk\nar\narp\naw\nawf\nbb\nbbh\nbf\nbfm\nbh\nbhm\nbo\nbos\nbu\nbus\ncc\nccd\nccs\ncd\ncdt\ncf\ncfe\ncl\nclq\ncq\ncqd\ncs\ncsa\ncsg\ncx\ncxd\ndf\ndft\ndk\ndkn\ndm\ndmk\ndo\ndol\ndq\ndql\ndr\ndrd\ndt\ndta\ndw\ndwn\nel\nelw\nep\nepc\nept\nes\nesk\nez\nezr\nfb\nfbf\nfe\nfep\nfez\nfk\nfki\nfm\nfmk\nfq\nfqc\nft\nftc\nftp\nfu\nfuf\nfv\nfvl\nga\ngar\nge\nges\ngf\ngfb\ngfe\ngl\nglg\nglx\ngt\ngtc\ngu\nguw\ngy\ngyn\nhg\nhgf\nhk\nhkp\nhm\nhmp\nhs\nhst\nia\niag\nie\niep\nig\nigl\niqn\njc\njcx\njt\njtw..." }, { "input": "prntaxhysjfcfmrjngdsitlguahtpnwgbaxptubgpwcfxqehrulbxfcjssgocqncscduvyvarvwxzvmjoatnqfsvsilubexmwugedtzavyamqjqtkxzuslielibjnvkpvyrbndehsqcaqzcrmomqqwskwcypgqoawxdutnxmeivnfpzwvxiyscbfnloqjhjacsfnkfmbhgzpujrqdbaemjsqphokkiplblbflvadcyykcqrdohfasstobwrobslaofbasylwiizrpozvhtwyxtzl", "output": "505\nac\nacs\nad\nadc\nae\naem\nah\naht\nam\namq\nao\naof\naq\naqz\nar\narv\nas\nass\nasy\nat\natn\nav\navy\naw\nawx\nax\naxp\nba\nbae\nbas\nbax\nbe\nbex\nbf\nbfl\nbfn\nbg\nbgp\nbh\nbhg\nbj\nbjn\nbl\nblb\nbn\nbnd\nbs\nbsl\nbw\nbwr\nbx\nbxf\nca\ncaq\ncb\ncbf\ncd\ncdu\ncf\ncfm\ncfx\ncj\ncjs\ncq\ncqn\ncqr\ncr\ncrm\ncs\ncsc\ncsf\ncy\ncyp\ncyy\ndb\ndba\ndc\ndcy\nde\ndeh\ndo\ndoh\nds\ndsi\ndt\ndtz\ndu\ndut\nduv\ned\nedt\neh\nehr\nehs\nei\neiv\nel\neli\nem\nemj\nex\nexm\nfa\nfas\nfb\nfba\nfc\nfcf\nfcj\nfl\nflv\nf..." }, { "input": "gvtgnjyfvnuhagulgmjlqzpvxsygmikofsnvkuplnkxeibnicygpvfvtebppadpdnrxjodxdhxqceaulbfxogwrigstsjudhkgwkhseuwngbppisuzvhzzxxbaggfngmevksbrntpprxvcczlalutdzhwmzbalkqmykmodacjrmwhwugyhwlrbnqxsznldmaxpndwmovcolowxhj", "output": "375\nac\nacj\nad\nadp\nag\nagg\nagu\nal\nalk\nalu\nau\naul\nax\naxp\nba\nbag\nbal\nbf\nbfx\nbn\nbni\nbnq\nbp\nbpp\nbr\nbrn\ncc\nccz\nce\ncea\ncj\ncjr\nco\ncol\ncy\ncyg\ncz\nczl\nda\ndac\ndh\ndhk\ndhx\ndm\ndma\ndn\ndnr\ndp\ndpd\ndw\ndwm\ndx\ndxd\ndz\ndzh\nea\neau\neb\nebp\nei\neib\neu\neuw\nev\nevk\nfn\nfng\nfs\nfsn\nfv\nfvn\nfvt\nfx\nfxo\ngb\ngbp\ngf\ngfn\ngg\nggf\ngm\ngme\ngmi\ngmj\ngp\ngpv\ngs\ngst\ngu\ngul\ngw\ngwk\ngwr\ngy\ngyh\nha\nhag\nhj\nhk\nhkg\nhs\nhse\nhw\nhwl\nhwm\nhwu\nhx\nhxq\nhz\nhzz\nib\nib..." }, { "input": "topqexoicgzjmssuxnswdhpwbsqwfhhziwqibjgeepcvouhjezlomobgireaxaceppoxfxvkwlvgwtjoiplihbpsdhczddwfvcbxqqmqtveaunshmobdlkmmfyajjlkhxnvfmibtbbqswrhcfwytrccgtnlztkddrevkfovunuxtzhhhnorecyfgmlqcwjfjtqegxagfiuqtpjpqlwiefofpatxuqxvikyynncsueynmigieototnbcwxavlbgeqao", "output": "462\nac\nace\nag\nagf\naj\najj\nao\nat\natx\nau\naun\nav\navl\nax\naxa\nbb\nbbq\nbc\nbcw\nbd\nbdl\nbg\nbge\nbgi\nbj\nbjg\nbp\nbps\nbq\nbqs\nbs\nbsq\nbt\nbtb\nbx\nbxq\ncb\ncbx\ncc\nccg\nce\ncep\ncf\ncfw\ncg\ncgt\ncgz\ncs\ncsu\ncv\ncvo\ncw\ncwj\ncwx\ncy\ncyf\ncz\nczd\ndd\nddr\nddw\ndh\ndhc\ndhp\ndl\ndlk\ndr\ndre\ndw\ndwf\nea\neau\neax\nec\necy\nee\neep\nef\nefo\neg\negx\neo\neot\nep\nepc\nepp\neq\nev\nevk\ney\neyn\nez\nezl\nfg\nfgm\nfh\nfhh\nfi\nfiu\nfj\nfjt\nfm\nfmi\nfo\nfof\nfov\nfp\nfpa\nfv\nfvc\nfw\nfwy\n..." }, { "input": "lcrjhbybgamwetyrppxmvvxiyufdkcotwhmptefkqxjhrknjdponulsynpkgszhbkeinpnjdonjfwzbsaweqwlsvuijauwezfydktfljxgclpxpknhygdqyiapvzudyyqomgnsrdhhxhsrdfrwnxdolkmwmw", "output": "276\nam\namw\nap\napv\nau\nauw\naw\nawe\nbg\nbga\nbk\nbke\nbs\nbsa\nby\nbyb\ncl\nclp\nco\ncot\ndf\ndfr\ndh\ndhh\ndk\ndkc\ndkt\ndo\ndol\ndon\ndp\ndpo\ndq\ndqy\ndy\ndyy\nef\nefk\nei\nein\neq\neqw\net\nety\nez\nezf\nfd\nfdk\nfk\nfkq\nfl\nflj\nfr\nfrw\nfw\nfwz\nfy\nfyd\nga\ngam\ngc\ngcl\ngd\ngdq\ngn\ngns\ngs\ngsz\nhb\nhbk\nhh\nhhx\nhm\nhmp\nhr\nhrk\nhs\nhsr\nhx\nhxh\nhy\nhyg\nia\niap\nij\nija\nin\ninp\niy\niyu\nja\njau\njd\njdo\njdp\njf\njfw\njh\njhr\njx\njxg\nkc\nkco\nke\nkei\nkg\nkgs\nkm\nkmw\nkn\nknh\nknj\n..." }, { "input": "hzobjysjhbebobkoror", "output": "20\nbe\nbeb\nbko\nbo\nbob\neb\nebo\nhb\nhbe\njh\njhb\nko\nkor\nob\nor\nror\nsj\nsjh\nys\nysj" }, { "input": "safgmgpzljarfswowdxqhuhypxcmiddyvehjtnlflzknznrukdsbatxoytzxkqngopeipbythhbhfkvlcdxwqrxumbtbgiosjnbeorkzsrfarqofsrcwsfpyheaszjpkjysrcxbzebkxzovdchhososo", "output": "274\nar\narf\narq\nas\nasz\nat\natx\nba\nbat\nbe\nbeo\nbg\nbgi\nbh\nbhf\nbk\nbkx\nbt\nbtb\nby\nbyt\nbz\nbze\ncd\ncdx\nch\nchh\ncm\ncmi\ncw\ncws\ncx\ncxb\ndc\ndch\ndd\nddy\nds\ndsb\ndx\ndxq\ndxw\ndy\ndyv\nea\neas\neb\nebk\neh\nehj\nei\neip\neo\neor\nfa\nfar\nfk\nfkv\nfl\nflz\nfp\nfpy\nfs\nfsr\nfsw\ngi\ngio\ngo\ngop\ngp\ngpz\nhb\nhbh\nhe\nhea\nhf\nhfk\nhh\nhhb\nhj\nhjt\nhos\nhu\nhuh\nhy\nhyp\nid\nidd\nio\nios\nip\nipb\nja\njar\njn\njnb\njp\njpk\njt\njtn\njy\njys\nkd\nkds\nkj\nkjy\nkn\nknz\nkq\nkqn\nkv\nkvl\n..." }, { "input": "glaoyryxrgsysy", "output": "10\ngs\ngsy\nrgs\nry\nryx\nsy\nxr\nysy\nyx\nyxr" }, { "input": "aaaaaxyxxxx", "output": "5\nxx\nxxx\nxyx\nyx\nyxx" }, { "input": "aaaaax", "output": "0" }, { "input": "aaaaaxx", "output": "1\nxx" }, { "input": "aaaaaaa", "output": "1\naa" }, { "input": "aaaaaxxx", "output": "2\nxx\nxxx" }, { "input": "aaaaayxx", "output": "2\nxx\nyxx" }, { "input": "aaaaaxyz", "output": "2\nxyz\nyz" }, { "input": "aaaaaxyxy", "output": "2\nxy\nyxy" }, { "input": "aaaxyyxyy", "output": "3\nxyy\nyx\nyy" }, { "input": "aaaaaxxxxxx", "output": "2\nxx\nxxx" }, { "input": "aaaaaxxxxx", "output": "2\nxx\nxxx" }, { "input": "aaaaaxyzxyxy", "output": "5\nxy\nyxy\nyzx\nzx\nzxy" }, { "input": "aaaaadddgggg", "output": "6\ndd\nddg\ndg\ndgg\ngg\nggg" }, { "input": "abcdeabzzzzzzzz", "output": "5\nab\nabz\nbz\nzz\nzzz" }, { "input": "bbbbbccaaaaaa", "output": "4\naa\naaa\nca\ncca" }, { "input": "xxxxxababc", "output": "5\nab\naba\nabc\nba\nbc" }, { "input": "dddddaabbbbbb", "output": "4\naab\nab\nbb\nbbb" }, { "input": "xxxxxababe", "output": "5\nab\naba\nabe\nba\nbe" }, { "input": "aaaaababaaaaaaaaaaaa", "output": "6\naa\naaa\nab\nba\nbaa\nbab" } ]
1,520,335,371
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
41
93
8,806,400
# http://codeforces.com/contest/667/problem/C import sys sys.setrecursionlimit(10001) s = input() ans = set() checked = set() def dp(i): if i in checked: return checked.add(i) """ (aa)(bb)で後ろのbbをaddすると (abb)(bb)でbbをaddできないので前のカタマリをaddする """ # 2文字 if i > 6 and s[i - 2:i] != s[i:i + 2]: ans.add(s[i - 2:i]) dp(i - 2) # 3文字 if i > 7 and s[i - 3:i] != s[i:i + 3]: ans.add(s[i - 3:i]) dp(i - 3) dp(len(s)) print(len(ans)) for x in sorted(list(ans)): print(x)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to). Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language. Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match. Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}. Input Specification: The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. Output Specification: On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order. Demo Input: ['abacabaca\n', 'abaca\n'] Demo Output: ['3\naca\nba\nca\n', '0\n'] Note: The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
```python # http://codeforces.com/contest/667/problem/C import sys sys.setrecursionlimit(10001) s = input() ans = set() checked = set() def dp(i): if i in checked: return checked.add(i) """ (aa)(bb)で後ろのbbをaddすると (abb)(bb)でbbをaddできないので前のカタマリをaddする """ # 2文字 if i > 6 and s[i - 2:i] != s[i:i + 2]: ans.add(s[i - 2:i]) dp(i - 2) # 3文字 if i > 7 and s[i - 3:i] != s[i:i + 3]: ans.add(s[i - 3:i]) dp(i - 3) dp(len(s)) print(len(ans)) for x in sorted(list(ans)): print(x) ```
0
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "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 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
1,696,623,226
2,147,483,647
Python 3
OK
TESTS
31
92
0
n = int(input()) p = input() l = p.split(' ') l = [int(s) for s in l] vol = sum(l)/n print ('%.12f' %vol)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python n = int(input()) p = input() l = p.split(' ') l = [int(s) for s in l] vol = sum(l)/n print ('%.12f' %vol) ```
3
977
B
Two-gram
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $s$ = "BBAABBBA" the answer is two-gram "BB", which contained in $s$ three times. In other words, find any most frequent two-gram. Note that occurrences of the two-gram can overlap with each other.
The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters.
Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times.
[ "7\nABACABA\n", "5\nZZZAA\n" ]
[ "AB\n", "ZZ\n" ]
In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
0
[ { "input": "7\nABACABA", "output": "AB" }, { "input": "5\nZZZAA", "output": "ZZ" }, { "input": "26\nQWERTYUIOPASDFGHJKLZXCVBNM", "output": "AS" }, { "input": "2\nQA", "output": "QA" }, { "input": "2\nWW", "output": "WW" }, { "input": "11\nGGRRAATTZZZ", "output": "ZZ" }, { "input": "50\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA", "output": "NQ" }, { "input": "100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC", "output": "IB" }, { "input": "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AA" }, { "input": "10\nSQSQSQSQTG", "output": "SQ" }, { "input": "5\nAZAZA", "output": "AZ" }, { "input": "15\nMIRZOYANOVECLOX", "output": "AN" }, { "input": "9\nEGORLETOV", "output": "EG" }, { "input": "8\nPUTINVOR", "output": "IN" }, { "input": "7\nKADUROV", "output": "AD" }, { "input": "6\nAZAZAZ", "output": "AZ" }, { "input": "3\nLOL", "output": "LO" }, { "input": "3\nKEK", "output": "EK" }, { "input": "5\nFUFEL", "output": "EL" }, { "input": "9\nMIKEPIDOR", "output": "DO" }, { "input": "9\nAAAAAAAAA", "output": "AA" }, { "input": "23\nAABBBAAACCCCCAAADDDDDDD", "output": "DD" } ]
1,698,680,810
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
62
0
print("Two-gram")
Title: Two-gram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $s$ = "BBAABBBA" the answer is two-gram "BB", which contained in $s$ three times. In other words, find any most frequent two-gram. Note that occurrences of the two-gram can overlap with each other. Input Specification: The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters. Output Specification: Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times. Demo Input: ['7\nABACABA\n', '5\nZZZAA\n'] Demo Output: ['AB\n', 'ZZ\n'] Note: In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
```python print("Two-gram") ```
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input": "2\n100 100", "output": "2" }, { "input": "3\n100 100 100", "output": "3" }, { "input": "11\n1 2 3 4 5 6 5 4 3 2 1", "output": "11" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "61" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1", "output": "81" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1", "output": "85" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 100 7 6 5 4 3 2 1", "output": "61" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 100 8 7 6 1 4 3 2 1", "output": "96" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 100 10 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 100 11 10 9 8 7 6 5 4 3 2 1", "output": "55" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 100 12 11 10 9 8 7 6 5 4 3 2 1", "output": "59" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 100 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "86" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "83" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "74" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "52" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1", "output": "98" }, { "input": "10\n1 4 4 4 4 4 1 2 4 3", "output": "7" } ]
1,630,270,443
2,147,483,647
Python 3
OK
TESTS
80
530
6,963,200
# بسم الله الرحمن الرحيم def main(): n = int(input()) heights = [int(i) for i in input().split()] max = 0 maximal = 0 for watered in range(n): max = 1 next = watered + 1 while next < n: if heights[next] <= heights[next-1]: max += 1 next += 1 else: break prev = watered - 1 while prev >= 0: if heights[prev] <= heights[prev+1]: max += 1 prev -= 1 else: break if max > maximal: maximal = max print(maximal) if __name__=='__main__': main()
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. Output Specification: Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. Demo Input: ['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n'] Demo Output: ['1\n', '3\n', '6\n'] Note: none
```python # بسم الله الرحمن الرحيم def main(): n = int(input()) heights = [int(i) for i in input().split()] max = 0 maximal = 0 for watered in range(n): max = 1 next = watered + 1 while next < n: if heights[next] <= heights[next-1]: max += 1 next += 1 else: break prev = watered - 1 while prev >= 0: if heights[prev] <= heights[prev+1]: max += 1 prev -= 1 else: break if max > maximal: maximal = max print(maximal) if __name__=='__main__': main() ```
3.85453
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { "input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "output": "6" }, { "input": "4 2\n194041605 706221269 69909135 257655784", "output": "3" }, { "input": "4 2\n9581849 67346651 530497 272158241", "output": "4" }, { "input": "3 47\n378261451 163985731 230342101", "output": "3" }, { "input": "2 3\n247776868 480572137", "output": "1" }, { "input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796", "output": "7" }, { "input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085", "output": "40" }, { "input": "1 8\n55521105", "output": "1" }, { "input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843", "output": "44" }, { "input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601", "output": "22" }, { "input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105", "output": "20" }, { "input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629", "output": "44" }, { "input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191", "output": "8" }, { "input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529", "output": "38" }, { "input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547", "output": "18" }, { "input": "1 1\n44", "output": "0" }, { "input": "1 1\n4", "output": "1" }, { "input": "10 3\n444 447 774 777 7777 4447 4 7 7 4", "output": "8" } ]
1,662,302,336
2,147,483,647
Python 3
OK
TESTS
34
92
0
n,k=map(int,input().split()) l=list(map(int,input().split()))[:n] l1=[] for i in l: i=str(i) p=i.count('4') q=i.count('7') l1.append(p+q) c=0 for i in l1: if i<=k: c+=1 print(c)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['3 4\n1 2 4\n', '3 2\n447 44 77\n'] Demo Output: ['3\n', '2\n'] Note: In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
```python n,k=map(int,input().split()) l=list(map(int,input().split()))[:n] l1=[] for i in l: i=str(i) p=i.count('4') q=i.count('7') l1.append(p+q) c=0 for i in l1: if i<=k: c+=1 print(c) ```
3
630
H
Benches
PROGRAMMING
1,400
[ "combinatorics", "math" ]
null
null
The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections. The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench. Help the park administration count the number of ways to place the benches.
The only line of the input contains one integer *n* (5<=≤<=*n*<=≤<=100) — the number of east to west paths and north to south paths.
Output one integer — the number of ways to place the benches.
[ "5\n" ]
[ "120" ]
none
0
[ { "input": "5", "output": "120" }, { "input": "6", "output": "4320" }, { "input": "7", "output": "52920" }, { "input": "15", "output": "1082161080" }, { "input": "17", "output": "4594961280" }, { "input": "72", "output": "23491596420472320" }, { "input": "83", "output": "101159538130177920" }, { "input": "95", "output": "402852449038723320" }, { "input": "99", "output": "613867215317368320" }, { "input": "100", "output": "680185280130048000" } ]
1,694,632,450
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
171
13,312,000
from decimal import Decimal n = int(input()) res = n * n for num in range(n - 1, n - 5, -1): res *= num * num print(res / 120)
Title: Benches Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections. The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench. Help the park administration count the number of ways to place the benches. Input Specification: The only line of the input contains one integer *n* (5<=≤<=*n*<=≤<=100) — the number of east to west paths and north to south paths. Output Specification: Output one integer — the number of ways to place the benches. Demo Input: ['5\n'] Demo Output: ['120'] Note: none
```python from decimal import Decimal n = int(input()) res = n * n for num in range(n - 1, n - 5, -1): res *= num * num print(res / 120) ```
0
0
none
none
none
0
[ "none" ]
null
null
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis. Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct. Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task. Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7. Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct.
Print a single integer — the required sum modulo 109<=+<=7.
[ "2\n4 7\n", "3\n4 3 1\n" ]
[ "3\n", "9\n" ]
There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3. There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
0
[ { "input": "2\n4 7", "output": "3" }, { "input": "3\n4 3 1", "output": "9" }, { "input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95", "output": "83396599" }, { "input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73", "output": "68059140" }, { "input": "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97", "output": "92743989" }, { "input": "1\n78091781", "output": "0" }, { "input": "2\n1000000000 1", "output": "999999999" }, { "input": "3\n999999998 999999999 999999992", "output": "21" }, { "input": "3\n465343471 465343474 465343473", "output": "9" }, { "input": "10\n10 3 6 2 1 9 8 4 5 7", "output": "7181" }, { "input": "10\n756734546 756734524 756734550 756734529 756734553 756734538 756734541 756734536 756734579 756734537", "output": "36489" }, { "input": "10\n877105545 939360757 849826701 845946140 803128820 926787996 967305000 904694971 921301848 971203310", "output": "861364152" }, { "input": "5\n4 7 13 17 18", "output": "270" }, { "input": "5\n20 17 13 7 2", "output": "330" }, { "input": "5\n3 17 2 5 4", "output": "237" }, { "input": "5\n999999980 999999985 999999986 999999990 999999992", "output": "210" }, { "input": "5\n1000000000 999999988 999999982 999999981 999999980", "output": "342" }, { "input": "5\n999999984 999999997 999999994 999999991 999999982", "output": "285" }, { "input": "1\n2", "output": "0" }, { "input": "5\n9 10 7 4 5", "output": "114" } ]
1,689,182,236
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
35,123,200
#O(n^2) MOD = 10**9+7 import sys n=int(sys.stdin.readline()) a=list(map(int,sys.stdin.readline().split())) a.sort() res=0 for i in range(n): for j in range(i+1,n): diff = a[j]-a[i] dist = j-i-1 res+=(diff)*(2**(dist)) res%=MOD res%=MOD print(res)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis. Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct. Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task. Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7. Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct. Output Specification: Print a single integer — the required sum modulo 109<=+<=7. Demo Input: ['2\n4 7\n', '3\n4 3 1\n'] Demo Output: ['3\n', '9\n'] Note: There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3. There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
```python #O(n^2) MOD = 10**9+7 import sys n=int(sys.stdin.readline()) a=list(map(int,sys.stdin.readline().split())) a.sort() res=0 for i in range(n): for j in range(i+1,n): diff = a[j]-a[i] dist = j-i-1 res+=(diff)*(2**(dist)) res%=MOD res%=MOD print(res) ```
0
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "output": "0" }, { "input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "output": "-1" }, { "input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "output": "1" }, { "input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "output": "1" }, { "input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "output": "1" }, { "input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "output": "-1" }, { "input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "output": "1" }, { "input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "output": "1" }, { "input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "output": "1" }, { "input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "output": "-1" }, { "input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "output": "-1" }, { "input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "output": "-1" }, { "input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "output": "-1" }, { "input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "output": "-1" }, { "input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "output": "-1" }, { "input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "output": "-1" }, { "input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "output": "1" }, { "input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "output": "-1" }, { "input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "output": "-1" }, { "input": "UG\nak", "output": "1" }, { "input": "JZR\nVae", "output": "-1" }, { "input": "a\nZ", "output": "-1" }, { "input": "rk\nkv", "output": "1" }, { "input": "RvuT\nbJzE", "output": "1" }, { "input": "PPS\nydq", "output": "-1" }, { "input": "q\nq", "output": "0" }, { "input": "peOw\nIgSJ", "output": "1" }, { "input": "PyK\noKN", "output": "1" }, { "input": "O\ni", "output": "1" }, { "input": "NmGY\npDlP", "output": "-1" }, { "input": "nG\nZf", "output": "-1" }, { "input": "m\na", "output": "1" }, { "input": "MWyB\nWZEV", "output": "-1" }, { "input": "Gre\nfxc", "output": "1" }, { "input": "Ooq\nwap", "output": "-1" }, { "input": "XId\nlbB", "output": "1" }, { "input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "output": "0" }, { "input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "output": "0" }, { "input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "output": "0" }, { "input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "output": "0" }, { "input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "output": "0" }, { "input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "output": "0" }, { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "output": "0" }, { "input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "output": "0" }, { "input": "abac\nadaa", "output": "-1" }, { "input": "Bbc\nabc", "output": "1" }, { "input": "aaaba\naaaab", "output": "1" } ]
1,695,457,685
2,147,483,647
Python 3
OK
TESTS
53
92
0
i = input a = i().lower() b = i().lower() print((a>b)-(a<b))
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Specification: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output Specification: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Demo Input: ['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
```python i = input a = i().lower() b = i().lower() print((a>b)-(a<b)) ```
3.977
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,693,910,099
2,147,483,647
Python 3
OK
TESTS
44
92
0
# Read input s = input() # Initialize variables to keep track of consecutive players consecutive_zeros = 0 consecutive_ones = 0 # Iterate through the string for player in s: if player == '0': consecutive_zeros += 1 consecutive_ones = 0 # Reset the count for consecutive ones else: consecutive_ones += 1 consecutive_zeros = 0 # Reset the count for consecutive zeros # Check if there are 7 or more consecutive players from the same team if consecutive_zeros >= 7 or consecutive_ones >= 7: print("YES") break else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python # Read input s = input() # Initialize variables to keep track of consecutive players consecutive_zeros = 0 consecutive_ones = 0 # Iterate through the string for player in s: if player == '0': consecutive_zeros += 1 consecutive_ones = 0 # Reset the count for consecutive ones else: consecutive_ones += 1 consecutive_zeros = 0 # Reset the count for consecutive zeros # Check if there are 7 or more consecutive players from the same team if consecutive_zeros >= 7 or consecutive_ones >= 7: print("YES") break else: print("NO") ```
3.977
697
A
Pineapple Incident
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time.
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
[ "3 10 4\n", "3 10 3\n", "3 8 51\n", "3 8 52\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
500
[ { "input": "3 10 4", "output": "NO" }, { "input": "3 10 3", "output": "YES" }, { "input": "3 8 51", "output": "YES" }, { "input": "3 8 52", "output": "YES" }, { "input": "456947336 740144 45", "output": "NO" }, { "input": "33 232603 599417964", "output": "YES" }, { "input": "4363010 696782227 701145238", "output": "YES" }, { "input": "9295078 2 6", "output": "NO" }, { "input": "76079 281367 119938421", "output": "YES" }, { "input": "93647 7 451664565", "output": "YES" }, { "input": "5 18553 10908", "output": "NO" }, { "input": "6 52 30", "output": "NO" }, { "input": "6431 855039 352662", "output": "NO" }, { "input": "749399100 103031711 761562532", "output": "NO" }, { "input": "21 65767 55245", "output": "NO" }, { "input": "4796601 66897 4860613", "output": "NO" }, { "input": "8 6728951 860676", "output": "NO" }, { "input": "914016 6 914019", "output": "NO" }, { "input": "60686899 78474 60704617", "output": "NO" }, { "input": "3 743604 201724", "output": "NO" }, { "input": "571128 973448796 10", "output": "NO" }, { "input": "688051712 67 51", "output": "NO" }, { "input": "74619 213344 6432326", "output": "NO" }, { "input": "6947541 698167 6", "output": "NO" }, { "input": "83 6 6772861", "output": "NO" }, { "input": "251132 67561 135026988", "output": "NO" }, { "input": "8897216 734348516 743245732", "output": "YES" }, { "input": "50 64536 153660266", "output": "YES" }, { "input": "876884 55420 971613604", "output": "YES" }, { "input": "0 6906451 366041903", "output": "YES" }, { "input": "11750 8 446010134", "output": "YES" }, { "input": "582692707 66997 925047377", "output": "YES" }, { "input": "11 957526890 957526901", "output": "YES" }, { "input": "556888 514614196 515171084", "output": "YES" }, { "input": "6 328006 584834704", "output": "YES" }, { "input": "4567998 4 204966403", "output": "YES" }, { "input": "60 317278 109460971", "output": "YES" }, { "input": "906385 342131991 685170368", "output": "YES" }, { "input": "1 38 902410512", "output": "YES" }, { "input": "29318 787017 587931018", "output": "YES" }, { "input": "351416375 243431 368213115", "output": "YES" }, { "input": "54 197366062 197366117", "output": "YES" }, { "input": "586389 79039 850729874", "output": "YES" }, { "input": "723634470 2814619 940360134", "output": "YES" }, { "input": "0 2 0", "output": "YES" }, { "input": "0 2 1", "output": "NO" }, { "input": "0 2 2", "output": "YES" }, { "input": "0 2 3", "output": "YES" }, { "input": "0 2 1000000000", "output": "YES" }, { "input": "0 10 23", "output": "NO" }, { "input": "0 2 999999999", "output": "YES" }, { "input": "10 5 11", "output": "NO" }, { "input": "1 2 1000000000", "output": "YES" }, { "input": "1 10 20", "output": "NO" }, { "input": "1 2 999999937", "output": "YES" }, { "input": "10 3 5", "output": "NO" }, { "input": "3 2 5", "output": "YES" }, { "input": "0 4 0", "output": "YES" }, { "input": "0 215 403", "output": "NO" }, { "input": "5 2 10", "output": "YES" }, { "input": "0 2 900000000", "output": "YES" }, { "input": "0 79 4000", "output": "NO" }, { "input": "5 1000 1000", "output": "NO" }, { "input": "1 5 103", "output": "NO" }, { "input": "5 2 6", "output": "NO" }, { "input": "120 2 1000000000", "output": "YES" }, { "input": "2 2 1000000000", "output": "YES" }, { "input": "5 5 13", "output": "NO" }, { "input": "10 5 15", "output": "YES" }, { "input": "11 2 0", "output": "NO" }, { "input": "3 8 53", "output": "NO" }, { "input": "2 2 4", "output": "YES" }, { "input": "4 4 0", "output": "NO" }, { "input": "1 2 3", "output": "YES" }, { "input": "5 3 9", "output": "YES" }, { "input": "5 6 19", "output": "NO" }, { "input": "3 10 125", "output": "NO" }, { "input": "5 3 8", "output": "YES" }, { "input": "6 3 9", "output": "YES" }, { "input": "0 3 5", "output": "NO" }, { "input": "5 3 300000035", "output": "YES" }, { "input": "5 2 7", "output": "YES" }, { "input": "1 5 6", "output": "YES" }, { "input": "4 2 6", "output": "YES" }, { "input": "0 3 999999998", "output": "NO" }, { "input": "0 10001 0", "output": "YES" }, { "input": "6 5 3", "output": "NO" }, { "input": "1 5 1000000000", "output": "NO" }, { "input": "1 3 6", "output": "NO" }, { "input": "3 3 1000000000", "output": "YES" }, { "input": "3 3 4", "output": "NO" }, { "input": "3 3 5", "output": "NO" }, { "input": "3 3 0", "output": "NO" }, { "input": "1 2 4", "output": "YES" }, { "input": "5 5 10", "output": "YES" } ]
1,629,364,402
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
6,656,000
a,b,c=map(int,input().split()) if ((c-a)%b==0 or (c-a)%b==0) and c!=a+1: print('YES') else: print('NO')
Title: Pineapple Incident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time. Input Specification: The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. Output Specification: Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. Demo Input: ['3 10 4\n', '3 10 3\n', '3 8 51\n', '3 8 52\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n', 'YES\n'] Note: In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
```python a,b,c=map(int,input().split()) if ((c-a)%b==0 or (c-a)%b==0) and c!=a+1: print('YES') else: print('NO') ```
0
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=&lt;<=*r**i*), that *s**i*<==<=*s**i*<=+<=1. Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*).
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3", "output": "0\n0\n1\n1\n0" }, { "input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5", "output": "2\n1\n1\n1\n1\n1\n1" }, { "input": "#..#\n1\n1 4", "output": "1" }, { "input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4", "output": "2\n2\n3\n2\n1\n4\n0" }, { "input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3", "output": "0\n0\n0\n0\n0\n0\n0" }, { "input": "###..#...#\n2\n2 4\n1 2", "output": "1\n1" }, { "input": "..\n1\n1 2", "output": "1" }, { "input": "##\n1\n1 2", "output": "1" }, { "input": ".#\n1\n1 2", "output": "0" }, { "input": "#.\n1\n1 2", "output": "0" }, { "input": "...\n2\n1 2\n1 2", "output": "1\n1" } ]
1,699,345,068
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
3,072,000
s=list(input()) check=[0 for _ in range(len(s)-1)] for _ in range(len(s)-1): if s[_]==s[_+1]: check[_]=1 for i in range(int(input())): l,r=map(int,input().split()) print(sum(check[l-1:r-1]))
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=&lt;<=*r**i*), that *s**i*<==<=*s**i*<=+<=1. Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. Input Specification: The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the answers to the queries in the order in which they are given in the input. Demo Input: ['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n'] Demo Output: ['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n'] Note: none
```python s=list(input()) check=[0 for _ in range(len(s)-1)] for _ in range(len(s)-1): if s[_]==s[_+1]: check[_]=1 for i in range(int(input())): l,r=map(int,input().split()) print(sum(check[l-1:r-1])) ```
0
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" }, { "input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.", "output": "80" }, { "input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C", "output": "144" }, { "input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC", "output": "190" }, { "input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..", "output": "228" }, { "input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..", "output": "2103" }, { "input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC", "output": "2071" }, { "input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.", "output": "1160" }, { "input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C", "output": "789" }, { "input": "1\n.", "output": "0" }, { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C", "output": "529" }, { "input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C", "output": "874" }, { "input": "2\nCC\nCC", "output": "4" }, { "input": "3\nC..\nC..\nC..", "output": "3" } ]
1,473,677,834
2,147,483,647
Python 3
OK
TESTS
48
62
0
import math size = int(input()) matrix = [] def ncr(x): if x>=2: y = math.factorial(x) y = y/((math.factorial(x-2))*2) return y else: return 0 for i in range(0,size): array = list(str(input())) matrix.append(array) rows = 0 cols = 0 for i in range(0,size): buffer = 0 for j in range(0,size): if matrix[i][j] == 'C': buffer += 1 y = ncr(buffer) rows += y for i in range(0,size): buffer = 0 for j in range(0,size): if matrix[j][i] == 'C': buffer += 1 y = ncr(buffer) cols += y print(int(cols)+int(rows))
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input Specification: In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Specification: Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Demo Input: ['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n'] Demo Output: ['4\n', '9\n'] Note: If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
```python import math size = int(input()) matrix = [] def ncr(x): if x>=2: y = math.factorial(x) y = y/((math.factorial(x-2))*2) return y else: return 0 for i in range(0,size): array = list(str(input())) matrix.append(array) rows = 0 cols = 0 for i in range(0,size): buffer = 0 for j in range(0,size): if matrix[i][j] == 'C': buffer += 1 y = ncr(buffer) rows += y for i in range(0,size): buffer = 0 for j in range(0,size): if matrix[j][i] == 'C': buffer += 1 y = ncr(buffer) cols += y print(int(cols)+int(rows)) ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,653,491,713
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
y=0 l=[] n,m=map(int,input().split()) x=list(map(int,input().split())) for i in range x: if i<0: l.append(i) for j in range(m): y+=l[j] print(y*-1)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python y=0 l=[] n,m=map(int,input().split()) x=list(map(int,input().split())) for i in range x: if i<0: l.append(i) for j in range(m): y+=l[j] print(y*-1) ```
-1
998
A
Balloons
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: - Do not rip the packets (both Grigory and Andrew should get unbroken packets); - Distribute all packets (every packet should be given to someone); - Give both Grigory and Andrew at least one packet; - To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions.
The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons. The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet.
If it's impossible to divide the balloons satisfying the conditions above, print $-1$. Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them.
[ "3\n1 2 1\n", "2\n5 5\n", "1\n10\n" ]
[ "2\n1 2\n", "-1\n", "-1\n" ]
In the first test Grigory gets $3$ balloons in total while Andrey gets $1$. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all.
500
[ { "input": "3\n1 2 1", "output": "1\n1" }, { "input": "2\n5 5", "output": "-1" }, { "input": "1\n10", "output": "-1" }, { "input": "1\n1", "output": "-1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1\n1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 9", "output": "1\n1" }, { "input": "10\n26 723 970 13 422 968 875 329 234 983", "output": "1\n4" }, { "input": "3\n3 2 1", "output": "1\n3" }, { "input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "1\n1" }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1\n1" }, { "input": "2\n9 6", "output": "1\n2" }, { "input": "2\n89 7", "output": "1\n2" }, { "input": "2\n101 807", "output": "1\n1" }, { "input": "5\n8 7 4 8 3", "output": "1\n5" }, { "input": "5\n55 62 70 100 90", "output": "1\n1" }, { "input": "5\n850 840 521 42 169", "output": "1\n4" }, { "input": "6\n7 1 4 1 6 1", "output": "1\n2" }, { "input": "6\n36 80 38 88 79 69", "output": "1\n1" }, { "input": "6\n108 318 583 10 344 396", "output": "1\n4" }, { "input": "9\n10 9 10 10 8 3 5 10 2", "output": "1\n9" }, { "input": "9\n90 31 28 63 57 57 27 62 42", "output": "1\n7" }, { "input": "9\n665 646 152 829 190 64 555 536 321", "output": "1\n6" }, { "input": "10\n99 62 10 47 53 9 83 33 15 24", "output": "1\n6" }, { "input": "4\n600 200 100 300", "output": "1\n3" }, { "input": "2\n4 5", "output": "1\n1" }, { "input": "2\n5 12", "output": "1\n1" }, { "input": "2\n1 2", "output": "1\n1" }, { "input": "3\n1 1 2", "output": "1\n1" }, { "input": "2\n3 2", "output": "1\n2" }, { "input": "3\n1 4 5", "output": "1\n1" }, { "input": "4\n5 5 5 5", "output": "1\n1" }, { "input": "1\n5", "output": "-1" }, { "input": "3\n5 5 5", "output": "1\n1" }, { "input": "5\n5 5 5 5 5", "output": "1\n1" }, { "input": "4\n2 7 10 1", "output": "1\n4" }, { "input": "3\n1 1 1", "output": "1\n1" }, { "input": "4\n8 4 2 2", "output": "1\n3" }, { "input": "2\n3 4", "output": "1\n1" }, { "input": "4\n1 1 3 1", "output": "1\n1" }, { "input": "7\n1 2 3 4 5 6 7", "output": "1\n1" }, { "input": "2\n18 19", "output": "1\n1" }, { "input": "2\n17 18", "output": "1\n1" }, { "input": "2\n1 3", "output": "1\n1" }, { "input": "4\n5 5 4 4", "output": "1\n3" }, { "input": "2\n10 11", "output": "1\n1" }, { "input": "2\n10 20", "output": "1\n1" }, { "input": "2\n2 1", "output": "1\n2" }, { "input": "4\n2 3 2 3", "output": "1\n1" }, { "input": "2\n5 6", "output": "1\n1" } ]
1,530,472,442
842
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(raw_input()) a = map(int,raw_input().split()) if n == 1 or n == 2 and a[0] == a[1]: print -1 else: print 1 print 1+ a.index(min(a))
Title: Balloons Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: - Do not rip the packets (both Grigory and Andrew should get unbroken packets); - Distribute all packets (every packet should be given to someone); - Give both Grigory and Andrew at least one packet; - To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input Specification: The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons. The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet. Output Specification: If it's impossible to divide the balloons satisfying the conditions above, print $-1$. Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Demo Input: ['3\n1 2 1\n', '2\n5 5\n', '1\n10\n'] Demo Output: ['2\n1 2\n', '-1\n', '-1\n'] Note: In the first test Grigory gets $3$ balloons in total while Andrey gets $1$. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all.
```python n = int(raw_input()) a = map(int,raw_input().split()) if n == 1 or n == 2 and a[0] == a[1]: print -1 else: print 1 print 1+ a.index(min(a)) ```
-1
757
B
Bash's Big Day
PROGRAMMING
1,400
[ "greedy", "math", "number theory" ]
null
null
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of *k*<=&gt;<=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition). Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take? Note: A Pokemon cannot fight with itself.
The input consists of two lines. The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab. The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon.
Print single integer — the maximum number of Pokemons Bash can take.
[ "3\n2 3 4\n", "5\n2 3 4 6 7\n" ]
[ "2\n", "3\n" ]
*gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>}. In the first sample, we can take Pokemons with strengths {2, 4} since *gcd*(2, 4) = 2. In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with *gcd* ≠ 1.
1,000
[ { "input": "3\n2 3 4", "output": "2" }, { "input": "5\n2 3 4 6 7", "output": "3" }, { "input": "3\n5 6 4", "output": "2" }, { "input": "8\n41 74 4 27 85 39 100 36", "output": "4" }, { "input": "6\n89 20 86 81 62 23", "output": "3" }, { "input": "71\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10", "output": "38" }, { "input": "95\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50", "output": "48" }, { "input": "44\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684", "output": "19" }, { "input": "35\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557", "output": "20" }, { "input": "1\n1", "output": "1" }, { "input": "10\n10 7 9 8 3 3 10 7 3 3", "output": "5" }, { "input": "9\n10 10 6 10 9 1 8 3 5", "output": "5" }, { "input": "7\n9 4 2 3 3 9 8", "output": "4" }, { "input": "1\n4", "output": "1" }, { "input": "6\n1623 45906 37856 34727 27156 12598", "output": "4" }, { "input": "30\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566", "output": "15" }, { "input": "23\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16", "output": "22" }, { "input": "46\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33", "output": "27" }, { "input": "43\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34", "output": "21" }, { "input": "25\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107", "output": "1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "2\n3 6", "output": "2" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "5\n3 3 3 3 3", "output": "5" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "2\n541 541", "output": "2" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n99989 99989", "output": "2" }, { "input": "3\n3 9 27", "output": "3" }, { "input": "2\n1009 1009", "output": "2" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "6\n2 10 20 5 15 25", "output": "5" }, { "input": "3\n3 3 6", "output": "3" }, { "input": "3\n457 457 457", "output": "3" }, { "input": "2\n34 17", "output": "2" }, { "input": "3\n12 24 3", "output": "3" }, { "input": "10\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991", "output": "10" }, { "input": "2\n1009 2018", "output": "2" }, { "input": "3\n3 3 3", "output": "3" }, { "input": "7\n6 9 12 15 21 27 33", "output": "7" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n557 557", "output": "2" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "5\n2 2 101 101 101", "output": "3" }, { "input": "2\n122 3721", "output": "2" }, { "input": "2\n49201 98402", "output": "2" }, { "input": "2\n88258 44129", "output": "2" }, { "input": "2\n7919 47514", "output": "2" }, { "input": "5\n1 2 1 1 1", "output": "1" }, { "input": "2\n2 2", "output": "2" }, { "input": "5\n1 1 1 1 2", "output": "1" }, { "input": "3\n10007 20014 30021", "output": "3" }, { "input": "4\n10 10 5 5", "output": "4" }, { "input": "2\n6 9", "output": "2" }, { "input": "3\n6 12 9", "output": "3" }, { "input": "2\n14 7", "output": "2" }, { "input": "2\n199 199", "output": "2" }, { "input": "3\n49999 49999 99998", "output": "3" }, { "input": "5\n1009 1009 1009 1009 1009", "output": "5" }, { "input": "3\n17 17 17", "output": "3" }, { "input": "2\n503 1509", "output": "2" }, { "input": "3\n49999 99998 99998", "output": "3" }, { "input": "2\n28657 28657", "output": "2" }, { "input": "3\n121 22 33", "output": "3" }, { "input": "2\n10079 20158", "output": "2" }, { "input": "2\n6 15", "output": "2" }, { "input": "4\n6 6 6 3", "output": "4" }, { "input": "2\n991 1982", "output": "2" }, { "input": "3\n20362 30543 50905", "output": "3" }, { "input": "2\n443 886", "output": "2" }, { "input": "4\n3 7 7 21", "output": "3" }, { "input": "3\n3 6 9", "output": "3" }, { "input": "2\n217 31", "output": "2" }, { "input": "6\n10 10 10 5 5 5", "output": "6" }, { "input": "4\n49441 25225 9081 4036", "output": "4" }, { "input": "2\n4 9", "output": "1" }, { "input": "2\n18 27", "output": "2" }, { "input": "2\n13 26", "output": "2" }, { "input": "4\n6 6 6 15", "output": "4" } ]
1,689,335,489
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689335488.91616")# 1689335488.9162052
Title: Bash's Big Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of *k*<=&gt;<=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition). Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take? Note: A Pokemon cannot fight with itself. Input Specification: The input consists of two lines. The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab. The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon. Output Specification: Print single integer — the maximum number of Pokemons Bash can take. Demo Input: ['3\n2 3 4\n', '5\n2 3 4 6 7\n'] Demo Output: ['2\n', '3\n'] Note: *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>}. In the first sample, we can take Pokemons with strengths {2, 4} since *gcd*(2, 4) = 2. In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with *gcd* ≠ 1.
```python print("_RANDOM_GUESS_1689335488.91616")# 1689335488.9162052 ```
0
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "output": "YES" }, { "input": "1\n999993399999", "output": "NO" }, { "input": "9\n111 121 131 111 121 131 111 121 131", "output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO" }, { "input": "1\n1", "output": "NO" }, { "input": "1\n10", "output": "NO" }, { "input": "1\n976197352729", "output": "NO" }, { "input": "1\n1000000000000", "output": "NO" }, { "input": "1\n9", "output": "YES" }, { "input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n223092870 6469693230 200560490130", "output": "NO\nNO\nNO" }, { "input": "2\n81 25", "output": "NO\nYES" }, { "input": "1\n16", "output": "NO" }, { "input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "1\n225", "output": "NO" }, { "input": "1\n1521", "output": "NO" }, { "input": "1\n81", "output": "NO" } ]
1,696,921,533
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
def check(number): x = int(number**0.5) if x*x != number: return False for i in range(2, int(x**0.5)+1): if x % i == 0: return False return True n = int(input()) nums = [int(x) for x in input().split()] for num in nums: print('YES' if check(num) else 'NO')
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. Input Specification: The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. Output Specification: Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. Demo Input: ['3\n4 5 6\n'] Demo Output: ['YES\nNO\nNO\n'] Note: The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
```python def check(number): x = int(number**0.5) if x*x != number: return False for i in range(2, int(x**0.5)+1): if x % i == 0: return False return True n = int(input()) nums = [int(x) for x in input().split()] for num in nums: print('YES' if check(num) else 'NO') ```
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,665,749,150
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
s = input() x = [*s] i = 0 isUpper = 0 isLower = 0 while i < len(x): if x[i].isupper() == True: isUpper += 1 else: isLower += 1 i += 1 if s == "HoUse": print("house") else: if isUpper == isLower: print(s.lower()) else: print(s.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 s = input() x = [*s] i = 0 isUpper = 0 isLower = 0 while i < len(x): if x[i].isupper() == True: isUpper += 1 else: isLower += 1 i += 1 if s == "HoUse": print("house") else: if isUpper == isLower: print(s.lower()) else: print(s.upper()) ```
0
637
A
Voting for Photos
PROGRAMMING
1,000
[ "*special", "constructive algorithms", "implementation" ]
null
null
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first. Help guys determine the winner photo by the records of likes.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like.
Print the identifier of the photo which won the elections.
[ "5\n1 3 2 2 1\n", "9\n100 200 300 200 100 300 300 100 200\n" ]
[ "2\n", "300\n" ]
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). Thus, the winner is the photo with identifier 2, as it got: - more likes than the photo with id 3; - as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
500
[ { "input": "5\n1 3 2 2 1", "output": "2" }, { "input": "9\n100 200 300 200 100 300 300 100 200", "output": "300" }, { "input": "1\n5", "output": "5" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "5\n1 3 4 2 2", "output": "2" }, { "input": "10\n2 1 2 3 1 5 8 7 4 8", "output": "2" }, { "input": "7\n1 1 2 2 2 3 3", "output": "2" }, { "input": "12\n2 3 1 2 3 3 3 2 1 1 2 1", "output": "3" }, { "input": "15\n7 6 8 4 9 8 7 3 4 6 7 5 4 2 8", "output": "7" }, { "input": "15\n100 200 300 500 300 400 600 300 100 200 400 300 600 200 100", "output": "300" }, { "input": "10\n677171 677171 677171 677171 672280 677171 677171 672280 672280 677171", "output": "677171" }, { "input": "15\n137419 137419 531977 438949 137419 438949 438949 137419 438949 531977 531977 531977 438949 438949 438949", "output": "438949" }, { "input": "20\n474463 517819 640039 640039 640039 640039 474463 474463 474463 640039 640039 474463 474463 425567 474463 517819 640039 474463 517819 517819", "output": "474463" }, { "input": "40\n119631 119631 772776 119631 658661 119631 108862 524470 125132 700668 69196 844949 154577 108862 108862 108862 597344 940938 989698 108862 154577 69196 125132 687080 940938 125132 69196 69196 125132 566152 953083 406319 380068 119631 154577 125132 413984 69196 154577 154577", "output": "108862" }, { "input": "5\n1 1 1000000 1000000 1000000", "output": "1000000" }, { "input": "5\n1000000 1 1 1000000 1", "output": "1" }, { "input": "10\n1 1 1000000 1000000 1000000 1 1000000 1 1 1000000", "output": "1" }, { "input": "8\n1000000 1000000 1 1 1 1000000 1000000 1", "output": "1000000" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1000000 1", "output": "1000000" }, { "input": "2\n1 1000000", "output": "1" }, { "input": "2\n1000000 1000000", "output": "1000000" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "4\n1 1000000 1000000 1", "output": "1000000" } ]
1,657,813,886
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
31
102,400
from collections import Counter n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) counts = Counter(a) candidates = [] likes = 0 for key, value in counts.items(): if value is max(counts.values()): candidates.append(key) likes = value candidates_dictionary = {} if len(candidates) == 1: print(candidates[0]) else: for candidate in candidates: for i in range(likes - 1): a.remove(candidate) candidates_dictionary[candidate] = a.index(candidate) for candidate, last_liked in candidates_dictionary.items(): if last_liked == min(candidates_dictionary.values()): print(candidate)
Title: Voting for Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first. Help guys determine the winner photo by the records of likes. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. Output Specification: Print the identifier of the photo which won the elections. Demo Input: ['5\n1 3 2 2 1\n', '9\n100 200 300 200 100 300 300 100 200\n'] Demo Output: ['2\n', '300\n'] Note: In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). Thus, the winner is the photo with identifier 2, as it got: - more likes than the photo with id 3; - as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
```python from collections import Counter n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) counts = Counter(a) candidates = [] likes = 0 for key, value in counts.items(): if value is max(counts.values()): candidates.append(key) likes = value candidates_dictionary = {} if len(candidates) == 1: print(candidates[0]) else: for candidate in candidates: for i in range(likes - 1): a.remove(candidate) candidates_dictionary[candidate] = a.index(candidate) for candidate, last_liked in candidates_dictionary.items(): if last_liked == min(candidates_dictionary.values()): print(candidate) ```
0
424
A
Squats
PROGRAMMING
900
[ "implementation" ]
null
null
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
[ "4\nxxXx\n", "2\nXX\n", "6\nxXXxXx\n" ]
[ "1\nXxXx\n", "1\nxX\n", "0\nxXXxXx\n" ]
none
500
[ { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "2\nXX", "output": "1\nxX" }, { "input": "6\nxXXxXx", "output": "0\nxXXxXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "22\nXXxXXxxXxXxXXXXXXXXXxx", "output": "4\nxxxxxxxXxXxXXXXXXXXXxx" }, { "input": "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx", "output": "0\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx" }, { "input": "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX", "output": "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX" }, { "input": "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX", "output": "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX" }, { "input": "200\nxxXXxxXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX", "output": "4\nXXXXXXXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX" }, { "input": "198\nxXxxXxxXxxXXxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx", "output": "5\nxxxxxxxxxxxxxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx" }, { "input": "200\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "198\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "99\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "200\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "output": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, { "input": "198\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "output": "99\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, { "input": "2\nxx", "output": "1\nXx" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "2\nxX", "output": "0\nxX" }, { "input": "4\nXXXX", "output": "2\nxxXX" }, { "input": "4\nxxxx", "output": "2\nXXxx" }, { "input": "4\nxxXX", "output": "0\nxxXX" }, { "input": "4\nXXxx", "output": "0\nXXxx" }, { "input": "4\nxXxx", "output": "1\nXXxx" }, { "input": "4\nXxxx", "output": "1\nXXxx" }, { "input": "4\nxxxX", "output": "1\nXxxX" }, { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "4\nXXXx", "output": "1\nxXXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "4\nXxXX", "output": "1\nxxXX" }, { "input": "4\nXXxX", "output": "1\nxXxX" }, { "input": "4\nXxXx", "output": "0\nXxXx" }, { "input": "6\nxXXxXX", "output": "1\nxxXxXX" } ]
1,567,926,884
2,147,483,647
Python 3
OK
TESTS
32
109
0
def Squats(n, seq): cntX = seq.count('X') cntx = seq.count('x') diffCnt = cntx-cntX if diffCnt<0: result = seq.replace('X','x',abs(int(n/2) - cntX)) return abs(int(n/2) - cntX) , result elif diffCnt>0: result = seq.replace('x','X',abs(int(n/2) - cntX)) return abs(int(n/2) - cntX), result else: return 0, seq n = int(input()) seq = input() res = Squats(n, seq) print(res[0]) print(res[1])
Title: Squats Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. Output Specification: In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Demo Input: ['4\nxxXx\n', '2\nXX\n', '6\nxXXxXx\n'] Demo Output: ['1\nXxXx\n', '1\nxX\n', '0\nxXXxXx\n'] Note: none
```python def Squats(n, seq): cntX = seq.count('X') cntx = seq.count('x') diffCnt = cntx-cntX if diffCnt<0: result = seq.replace('X','x',abs(int(n/2) - cntX)) return abs(int(n/2) - cntX) , result elif diffCnt>0: result = seq.replace('x','X',abs(int(n/2) - cntX)) return abs(int(n/2) - cntX), result else: return 0, seq n = int(input()) seq = input() res = Squats(n, seq) print(res[0]) print(res[1]) ```
3
450
B
Jzzhu and Sequences
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7).
[ "2 3\n3\n", "0 -1\n2\n" ]
[ "1\n", "1000000006\n" ]
In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6).
1,000
[ { "input": "2 3\n3", "output": "1" }, { "input": "0 -1\n2", "output": "1000000006" }, { "input": "-9 -11\n12345", "output": "1000000005" }, { "input": "0 0\n1000000000", "output": "0" }, { "input": "-1000000000 1000000000\n2000000000", "output": "1000000000" }, { "input": "-12345678 12345678\n1912345678", "output": "12345678" }, { "input": "728374857 678374857\n1928374839", "output": "950000007" }, { "input": "278374837 992837483\n1000000000", "output": "721625170" }, { "input": "-693849384 502938493\n982838498", "output": "502938493" }, { "input": "-783928374 983738273\n992837483", "output": "16261734" }, { "input": "-872837483 -682738473\n999999999", "output": "190099010" }, { "input": "-892837483 -998273847\n999283948", "output": "892837483" }, { "input": "-283938494 738473848\n1999999999", "output": "716061513" }, { "input": "-278374857 819283838\n1", "output": "721625150" }, { "input": "-1000000000 123456789\n1", "output": "7" }, { "input": "-529529529 -524524524\n2", "output": "475475483" }, { "input": "1 2\n2000000000", "output": "2" }, { "input": "-1 -2\n2000000000", "output": "1000000005" }, { "input": "1 2\n1999999999", "output": "1" }, { "input": "1 2\n1999999998", "output": "1000000006" }, { "input": "1 2\n1999999997", "output": "1000000005" }, { "input": "1 2\n1999999996", "output": "1000000006" }, { "input": "69975122 366233206\n1189460676", "output": "703741923" }, { "input": "812229413 904420051\n806905621", "output": "812229413" }, { "input": "872099024 962697902\n1505821695", "output": "90598878" }, { "input": "887387283 909670917\n754835014", "output": "112612724" }, { "input": "37759824 131342932\n854621399", "output": "868657075" }, { "input": "-246822123 800496170\n626323615", "output": "753177884" }, { "input": "-861439463 974126967\n349411083", "output": "835566423" }, { "input": "-69811049 258093841\n1412447", "output": "741906166" }, { "input": "844509330 -887335829\n123329059", "output": "844509330" }, { "input": "83712471 -876177148\n1213284777", "output": "40110388" }, { "input": "598730524 -718984219\n1282749880", "output": "401269483" }, { "input": "-474244697 -745885656\n1517883612", "output": "271640959" }, { "input": "-502583588 -894906953\n1154189557", "output": "497416419" }, { "input": "-636523651 -873305815\n154879215", "output": "763217843" }, { "input": "721765550 594845720\n78862386", "output": "126919830" }, { "input": "364141461 158854993\n1337196589", "output": "364141461" }, { "input": "878985260 677031952\n394707801", "output": "798046699" }, { "input": "439527072 -24854079\n1129147002", "output": "464381151" }, { "input": "840435009 -612103127\n565968986", "output": "387896880" }, { "input": "875035447 -826471373\n561914518", "output": "124964560" }, { "input": "-342526698 305357084\n70776744", "output": "352116225" }, { "input": "-903244186 899202229\n1527859274", "output": "899202229" }, { "input": "-839482546 815166320\n1127472130", "output": "839482546" }, { "input": "-976992569 -958313041\n1686580818", "output": "981320479" }, { "input": "-497338894 -51069176\n737081851", "output": "502661113" }, { "input": "-697962643 -143148799\n1287886520", "output": "856851208" }, { "input": "-982572938 -482658433\n1259858332", "output": "982572938" }, { "input": "123123 78817\n2000000000", "output": "78817" }, { "input": "1000000000 -1000000000\n3", "output": "14" }, { "input": "-1000000000 1000000000\n6", "output": "14" }, { "input": "2 3\n6", "output": "1000000006" }, { "input": "0 -1\n6", "output": "1" }, { "input": "500000000 -1000000000\n600000003", "output": "500000014" }, { "input": "-1000000000 1000000000\n3", "output": "999999993" }, { "input": "1 3\n6", "output": "1000000005" }, { "input": "1 2\n12", "output": "1000000006" }, { "input": "7 -1000000000\n3", "output": "0" }, { "input": "-999999997 999999997\n6", "output": "20" }, { "input": "3 4\n6", "output": "1000000006" }, { "input": "-1 2\n6", "output": "1000000004" }, { "input": "2 3\n12", "output": "1000000006" }, { "input": "4 18\n6", "output": "999999993" }, { "input": "1 2\n6", "output": "1000000006" }, { "input": "1000000000 -1000000000\n6", "output": "999999993" }, { "input": "999999999 -999999999\n3", "output": "16" }, { "input": "-1 0\n1", "output": "1000000006" }, { "input": "1000000000 -1000000000\n9", "output": "14" }, { "input": "999999999 -1000000000\n12", "output": "999999992" }, { "input": "1000000000 -7\n3", "output": "0" }, { "input": "-5 5\n6", "output": "999999997" }, { "input": "5 9\n6", "output": "1000000003" }, { "input": "-15 -10\n1", "output": "999999992" } ]
1,652,108,030
2,147,483,647
Python 3
OK
TESTS
74
46
0
x , y = map(int, input().split()) a = [x,y,y-x,-x,-y,x-y] n = int(input()) if n<=6: print(a[n-1]%1000000007) else: print(a[(n%6)-1] % 1000000007)
Title: Jzzhu and Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). Input Specification: The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). Output Specification: Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). Demo Input: ['2 3\n3\n', '0 -1\n2\n'] Demo Output: ['1\n', '1000000006\n'] Note: In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6).
```python x , y = map(int, input().split()) a = [x,y,y-x,-x,-y,x-y] n = int(input()) if n<=6: print(a[n-1]%1000000007) else: print(a[(n%6)-1] % 1000000007) ```
3
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "output": "4" }, { "input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "output": "3" } ]
1,695,716,326
2,147,483,647
Python 3
OK
TESTS
25
92
0
#2300012142 林烨 for i in range(5): k=input().split() if '1' in k: print(abs(k.index('1')-2)+abs(i-2)) break
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python #2300012142 林烨 for i in range(5): k=input().split() if '1' in k: print(abs(k.index('1')-2)+abs(i-2)) break ```
3
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
1,546,443,356
2,147,483,647
Python 3
OK
TESTS
13
216
0
n = int(input()) a = [0, 0] b = [0, 0] for _ in range(n): t, x, y = map(int, input().split()) if t == 1: a[0] += x a[1] += y else: b[0] += x b[1] += y if a[0] >= a[1]: print('LIVE') else: print('DEAD') if b[0] >= b[1]: print('LIVE') else: print('DEAD')
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python n = int(input()) a = [0, 0] b = [0, 0] for _ in range(n): t, x, y = map(int, input().split()) if t == 1: a[0] += x a[1] += y else: b[0] += x b[1] += y if a[0] >= a[1]: print('LIVE') else: print('DEAD') if b[0] >= b[1]: print('LIVE') else: print('DEAD') ```
3
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "Still Rozdil" }, { "input": "4\n1000000000 100000000 1000000 1000000", "output": "Still Rozdil" }, { "input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6", "output": "Still Rozdil" }, { "input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7", "output": "8" }, { "input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11", "output": "Still Rozdil" }, { "input": "47\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 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "32" }, { "input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63", "output": "19" }, { "input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622", "output": "68" }, { "input": "5\n5 5 2 3 1", "output": "5" }, { "input": "1\n1000000000", "output": "1" }, { "input": "3\n7 7 4", "output": "3" }, { "input": "3\n2 2 1", "output": "3" }, { "input": "3\n4 4 3", "output": "3" }, { "input": "2\n10000001 10000002", "output": "1" }, { "input": "4\n3 3 2 1", "output": "4" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "2\n1000000000 100000000", "output": "2" }, { "input": "1\n99999999", "output": "1" }, { "input": "3\n5 5 3", "output": "3" }, { "input": "3\n7 7 5", "output": "3" }, { "input": "3\n3 3 1", "output": "3" }, { "input": "4\n10 10 10 1", "output": "4" } ]
1,659,372,141
2,147,483,647
Python 3
OK
TESTS
45
278
11,878,400
n=int(input()) l=input().split(" ") l=[int(x) for x in l] square_dict = {n: 1 for n in l} s={} minNum=min(l) for i in l: # for j in range(len(l[i])): if i in s: key=i s[key]=s.setdefault(key, 0) + 1 else: key=i s[key]=s.setdefault(key, 1) k=minNum if(s.get(k)>1): print("Still Rozdil") else: print(l.index(minNum)+1)
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. Output Specification: Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). Demo Input: ['2\n7 4\n', '7\n7 4 47 100 4 9 12\n'] Demo Output: ['2\n', 'Still Rozdil\n'] Note: In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
```python n=int(input()) l=input().split(" ") l=[int(x) for x in l] square_dict = {n: 1 for n in l} s={} minNum=min(l) for i in l: # for j in range(len(l[i])): if i in s: key=i s[key]=s.setdefault(key, 0) + 1 else: key=i s[key]=s.setdefault(key, 1) k=minNum if(s.get(k)>1): print("Still Rozdil") else: print(l.index(minNum)+1) ```
3
925
D
Aztec Catacombs
PROGRAMMING
2,600
[ "constructive algorithms" ]
null
null
Indiana Jones found ancient Aztec catacombs containing a golden idol. The catacombs consists of $n$ caves. Each pair of caves is connected with a two-way corridor that can be opened or closed. The entrance to the catacombs is in the cave $1$, the idol and the exit are in the cave $n$. When Indiana goes from a cave $x$ to a cave $y$ using an open corridor, all corridors connected to the cave $x$ change their state: all open corridors become closed, all closed corridors become open. Indiana wants to go from cave $1$ to cave $n$ going through as small number of corridors as possible. Help him find the optimal path, or determine that it is impossible to get out of catacombs.
The first line contains two integers $n$ and $m$ ($2 \leq n \leq 3\cdot 10^5$, $0 \leq m \leq 3 \cdot 10^5$) — the number of caves and the number of open corridors at the initial moment. The next $m$ lines describe the open corridors. The $i$-th of these lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) — the caves connected by the $i$-th open corridor. It is guaranteed that each unordered pair of caves is presented at most once.
If there is a path to exit, in the first line print a single integer $k$ — the minimum number of corridors Indians should pass through ($1 \leq k \leq 10^6$). In the second line print $k+1$ integers $x_0, \ldots, x_k$ — the number of caves in the order Indiana should visit them. The sequence $x_0, \ldots, x_k$ should satisfy the following: - $x_0 = 1$, $x_k = n$;- for each $i$ from $1$ to $k$ the corridor from $x_{i - 1}$ to $x_i$ should be open at the moment Indiana walks along this corridor. If there is no path, print a single integer $-1$. We can show that if there is a path, there is a path consisting of no more than $10^6$ corridors.
[ "4 4\n1 2\n2 3\n1 3\n3 4\n", "4 2\n1 2\n2 3\n" ]
[ "2\n1 3 4 \n", "4\n1 2 3 1 4 \n" ]
none
2,000
[]
1,689,635,687
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689635687.2415705")# 1689635687.241588
Title: Aztec Catacombs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Indiana Jones found ancient Aztec catacombs containing a golden idol. The catacombs consists of $n$ caves. Each pair of caves is connected with a two-way corridor that can be opened or closed. The entrance to the catacombs is in the cave $1$, the idol and the exit are in the cave $n$. When Indiana goes from a cave $x$ to a cave $y$ using an open corridor, all corridors connected to the cave $x$ change their state: all open corridors become closed, all closed corridors become open. Indiana wants to go from cave $1$ to cave $n$ going through as small number of corridors as possible. Help him find the optimal path, or determine that it is impossible to get out of catacombs. Input Specification: The first line contains two integers $n$ and $m$ ($2 \leq n \leq 3\cdot 10^5$, $0 \leq m \leq 3 \cdot 10^5$) — the number of caves and the number of open corridors at the initial moment. The next $m$ lines describe the open corridors. The $i$-th of these lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) — the caves connected by the $i$-th open corridor. It is guaranteed that each unordered pair of caves is presented at most once. Output Specification: If there is a path to exit, in the first line print a single integer $k$ — the minimum number of corridors Indians should pass through ($1 \leq k \leq 10^6$). In the second line print $k+1$ integers $x_0, \ldots, x_k$ — the number of caves in the order Indiana should visit them. The sequence $x_0, \ldots, x_k$ should satisfy the following: - $x_0 = 1$, $x_k = n$;- for each $i$ from $1$ to $k$ the corridor from $x_{i - 1}$ to $x_i$ should be open at the moment Indiana walks along this corridor. If there is no path, print a single integer $-1$. We can show that if there is a path, there is a path consisting of no more than $10^6$ corridors. Demo Input: ['4 4\n1 2\n2 3\n1 3\n3 4\n', '4 2\n1 2\n2 3\n'] Demo Output: ['2\n1 3 4 \n', '4\n1 2 3 1 4 \n'] Note: none
```python print("_RANDOM_GUESS_1689635687.2415705")# 1689635687.241588 ```
0
859
B
Lazy Security Guard
PROGRAMMING
1,000
[ "brute force", "geometry", "math" ]
null
null
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.
Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route.
Print the minimum perimeter that can be achieved.
[ "4\n", "11\n", "22\n" ]
[ "8\n", "14\n", "20\n" ]
Here are some possible shapes for the examples: <img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/>
750
[ { "input": "4", "output": "8" }, { "input": "11", "output": "14" }, { "input": "22", "output": "20" }, { "input": "3", "output": "8" }, { "input": "1024", "output": "128" }, { "input": "101", "output": "42" }, { "input": "30", "output": "22" }, { "input": "1000000", "output": "4000" }, { "input": "1", "output": "4" }, { "input": "2", "output": "6" }, { "input": "5", "output": "10" }, { "input": "6", "output": "10" }, { "input": "7", "output": "12" }, { "input": "8", "output": "12" }, { "input": "9", "output": "12" }, { "input": "10", "output": "14" }, { "input": "999000", "output": "3998" }, { "input": "999001", "output": "4000" }, { "input": "999999", "output": "4000" }, { "input": "933206", "output": "3866" }, { "input": "718351", "output": "3392" }, { "input": "607443", "output": "3118" }, { "input": "347887", "output": "2360" }, { "input": "246206", "output": "1986" }, { "input": "151375", "output": "1558" }, { "input": "12639", "output": "450" }, { "input": "3751", "output": "246" }, { "input": "3607", "output": "242" }, { "input": "124", "output": "46" }, { "input": "64", "output": "32" }, { "input": "31", "output": "24" }, { "input": "23", "output": "20" }, { "input": "15", "output": "16" }, { "input": "19", "output": "18" }, { "input": "59637", "output": "978" } ]
1,647,084,115
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
if __name__ == '__main__': n = int(input()) i = 0 while i**2 < n: i += 1 t = i - 1 j = 1 while t*j < n: j += 1 print(2*(t + j))
Title: Lazy Security Guard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite. Input Specification: Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route. Output Specification: Print the minimum perimeter that can be achieved. Demo Input: ['4\n', '11\n', '22\n'] Demo Output: ['8\n', '14\n', '20\n'] Note: Here are some possible shapes for the examples: <img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python if __name__ == '__main__': n = int(input()) i = 0 while i**2 < n: i += 1 t = i - 1 j = 1 while t*j < n: j += 1 print(2*(t + j)) ```
0
35
A
Shell Game
PROGRAMMING
1,000
[ "implementation" ]
A. Shell Game
2
64
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too?
The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3.
In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.
[ "1\n1 2\n2 1\n2 1\n", "1\n2 1\n3 1\n1 3\n" ]
[ "2\n", "2\n" ]
none
500
[ { "input": "1\n1 2\n2 1\n2 1", "output": "2" }, { "input": "1\n2 1\n3 1\n1 3", "output": "2" }, { "input": "3\n3 1\n2 1\n1 2", "output": "1" }, { "input": "1\n1 3\n1 2\n2 3", "output": "2" }, { "input": "3\n3 2\n3 1\n3 1", "output": "2" }, { "input": "1\n2 1\n1 3\n1 3", "output": "2" }, { "input": "3\n3 1\n2 3\n3 2", "output": "1" }, { "input": "2\n1 3\n1 2\n2 1", "output": "2" }, { "input": "1\n1 3\n3 2\n1 2", "output": "1" }, { "input": "1\n1 3\n1 3\n2 3", "output": "1" }, { "input": "2\n1 2\n2 3\n2 1", "output": "2" }, { "input": "3\n1 3\n3 2\n2 1", "output": "2" }, { "input": "1\n1 2\n2 1\n2 3", "output": "1" }, { "input": "1\n2 3\n1 3\n1 2", "output": "3" }, { "input": "2\n3 1\n3 2\n2 3", "output": "2" }, { "input": "2\n1 3\n3 1\n3 1", "output": "2" }, { "input": "1\n3 2\n1 3\n3 1", "output": "1" }, { "input": "3\n1 3\n1 2\n1 3", "output": "2" }, { "input": "1\n3 2\n3 1\n1 2", "output": "3" }, { "input": "2\n2 3\n1 3\n1 3", "output": "3" } ]
1,673,804,012
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
122
2,764,800
a = input() for i in range(3): k = input().split() if a in k: del k[k.index(a)] a = k[0] print(a)
Title: Shell Game Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? Input Specification: The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. Output Specification: In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. Demo Input: ['1\n1 2\n2 1\n2 1\n', '1\n2 1\n3 1\n1 3\n'] Demo Output: ['2\n', '2\n'] Note: none
```python a = input() for i in range(3): k = input().split() if a in k: del k[k.index(a)] a = k[0] print(a) ```
-1
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,690,200,384
2,147,483,647
Python 3
OK
TESTS
35
46
0
a = list(map(int,input().split())) b = list(map(int,input().split())) for i in range(len(b)): b[i] += a[1] c = 0 for i in b: if i <= 5: c+=1 print(c//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python a = list(map(int,input().split())) b = list(map(int,input().split())) for i in range(len(b)): b[i] += a[1] c = 0 for i in b: if i <= 5: c+=1 print(c//3) ```
3
194
B
Square
PROGRAMMING
1,200
[ "math" ]
null
null
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (*n*<=+<=1) meters, he draws a cross (see picture for clarifications). John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?
The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases. The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample.
For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n4 8 100\n" ]
[ "17\n33\n401\n" ]
none
1,000
[ { "input": "3\n4 8 100", "output": "17\n33\n401" }, { "input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13", "output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27" }, { "input": "3\n13 17 21", "output": "27\n35\n43" } ]
1,422,845,862
162
Python 3
WRONG_ANSWER
TESTS
1
92
0
i = int(input()) x = list(map(int, input().split(' '))) for i in x: print(4*i+1)
Title: Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (*n*<=+<=1) meters, he draws a cross (see picture for clarifications). John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw? Input Specification: The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases. The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. Output Specification: For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\n4 8 100\n'] Demo Output: ['17\n33\n401\n'] Note: none
```python i = int(input()) x = list(map(int, input().split(' '))) for i in x: print(4*i+1) ```
0
219
D
Choosing Capital for Treeland
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed. Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*.
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
[ "3\n2 1\n2 3\n", "4\n1 4\n2 4\n3 4\n" ]
[ "0\n2 \n", "2\n1 2 3 \n" ]
none
2,000
[ { "input": "3\n2 1\n2 3", "output": "0\n2 " }, { "input": "4\n1 4\n2 4\n3 4", "output": "2\n1 2 3 " }, { "input": "2\n1 2", "output": "0\n1 " }, { "input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7", "output": "3\n4 6 8 " }, { "input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "output": "3\n9 " }, { "input": "10\n9 3\n3 8\n4 3\n3 5\n7 8\n10 3\n2 3\n6 2\n3 1", "output": "4\n6 " }, { "input": "10\n5 4\n6 5\n10 1\n2 5\n9 8\n1 3\n7 10\n2 3\n5 9", "output": "2\n7 " }, { "input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "output": "3\n9 " }, { "input": "11\n3 10\n4 7\n11 7\n8 2\n6 9\n9 3\n5 9\n1 3\n3 8\n7 3", "output": "5\n4 5 6 11 " }, { "input": "12\n10 7\n6 10\n8 10\n4 12\n10 4\n3 12\n1 2\n2 7\n4 5\n11 5\n11 9", "output": "5\n1 6 8 " }, { "input": "13\n7 13\n5 4\n5 1\n11 12\n8 3\n13 4\n10 7\n11 5\n8 13\n2 8\n10 6\n4 9", "output": "4\n2 10 " }, { "input": "14\n13 10\n5 14\n9 4\n8 12\n10 1\n5 2\n3 6\n11 2\n13 2\n13 7\n8 2\n4 5\n1 3", "output": "3\n9 " }, { "input": "15\n15 6\n2 15\n14 15\n15 12\n1 2\n10 15\n7 4\n13 7\n11 2\n5 2\n7 2\n3 2\n7 8\n9 15", "output": "7\n13 " } ]
1,667,975,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
60
0
n = int(input()) cities = [0]*n inv_cities = [0]*n for _ in range(n-1): c1, c2 = list(map(int, input().split())) cities[c1-1] += 1 inv_cities[c2-1] += 1 for i in range(n): inv_cities[i] += (n-cities[i]-1-inv_cities[i]) capital = min(inv_cities) print(capital) for i in range(n): if(inv_cities[i] == capital): print(i+1, end=" ")
Title: Choosing Capital for Treeland Time Limit: None seconds Memory Limit: None megabytes Problem Description: The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed. Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country. Input Specification: The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*. Output Specification: In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order. Demo Input: ['3\n2 1\n2 3\n', '4\n1 4\n2 4\n3 4\n'] Demo Output: ['0\n2 \n', '2\n1 2 3 \n'] Note: none
```python n = int(input()) cities = [0]*n inv_cities = [0]*n for _ in range(n-1): c1, c2 = list(map(int, input().split())) cities[c1-1] += 1 inv_cities[c2-1] += 1 for i in range(n): inv_cities[i] += (n-cities[i]-1-inv_cities[i]) capital = min(inv_cities) print(capital) for i in range(n): if(inv_cities[i] == capital): print(i+1, end=" ") ```
0
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,582,511,307
2,147,483,647
PyPy 3
OK
TESTS
37
436
9,216,000
def main(): s=input() found=0 l=len(s) for i in range(l): if (s[i]=='0' or i==l-1) and not found: found=1 continue print(s[i],end='') if __name__=='__main__': main()
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python def main(): s=input() found=0 l=len(s) for i in range(l): if (s[i]=='0' or i==l-1) and not found: found=1 continue print(s[i],end='') if __name__=='__main__': main() ```
3
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,688,998,514
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
a=int(input()) b=list(map(int,input().split())) for i in range(a): if b[0:i]>b[i:a]: print(len(b[0:i])) exit()
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 a=int(input()) b=list(map(int,input().split())) for i in range(a): if b[0:i]>b[i:a]: print(len(b[0:i])) exit() ```
0
681
A
A Good Contest
PROGRAMMING
800
[ "implementation" ]
null
null
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
500
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155", "output": "NO" }, { "input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968", "output": "NO" }, { "input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290", "output": "NO" }, { "input": "1\na 2400 2401", "output": "YES" }, { "input": "1\nfucker 4000 4000", "output": "NO" }, { "input": "1\nJora 2400 2401", "output": "YES" }, { "input": "1\nACA 2400 2420", "output": "YES" }, { "input": "1\nAca 2400 2420", "output": "YES" }, { "input": "1\nSub_d 2401 2402", "output": "YES" }, { "input": "2\nHack 2400 2401\nDum 1243 555", "output": "YES" }, { "input": "1\nXXX 2400 2500", "output": "YES" }, { "input": "1\nfucker 2400 2401", "output": "YES" }, { "input": "1\nX 2400 2500", "output": "YES" }, { "input": "1\nvineet 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2500", "output": "YES" }, { "input": "1\naaaaa 2400 2401", "output": "YES" }, { "input": "1\nhoge 2400 2401", "output": "YES" }, { "input": "1\nInfinity 2400 2468", "output": "YES" }, { "input": "1\nBurunduk1 2400 2401", "output": "YES" }, { "input": "1\nFuck 2400 2401", "output": "YES" }, { "input": "1\nfuck 2400 2401", "output": "YES" }, { "input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "YES" }, { "input": "1\nalex 2400 2401", "output": "YES" }, { "input": "1\nA 2400 2401", "output": "YES" }, { "input": "1\na 2400 2455", "output": "YES" }, { "input": "1\nlol 2400 2401", "output": "YES" }, { "input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214", "output": "YES" }, { "input": "1\naaaaaa 2400 2401", "output": "YES" }, { "input": "1\nBurunduk1 2400 2500", "output": "YES" }, { "input": "1\nds 2400 2410", "output": "YES" }, { "input": "1\nas 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2401", "output": "YES" }, { "input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537", "output": "YES" }, { "input": "1\ncaonima 2400 2401", "output": "YES" }, { "input": "1\narr 2400 2500", "output": "YES" }, { "input": "1\nx 2400 2401", "output": "YES" }, { "input": "1\narrr 2400 2500", "output": "YES" }, { "input": "1\nabc 2400 2405", "output": "YES" }, { "input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nBurunduk1 2400 2537", "output": "YES" }, { "input": "1\nHELLO 2400 2401", "output": "YES" }, { "input": "1\neatmore 2400 2500", "output": "YES" }, { "input": "1\nb 2400 2401", "output": "YES" }, { "input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nApplejack 2400 2410", "output": "YES" }, { "input": "1\nabacaba 2400 2451", "output": "YES" }, { "input": "1\nrekt_n00b 2500 2600", "output": "YES" } ]
1,550,856,957
2,147,483,647
Python 3
OK
TESTS
60
124
0
n = int(input()) flag = False for i in range(n): name, before, after = map(str, input().split()) if flag is False: if int(before) >= 2400 and int(after) > int(before): flag = True continue print('YES' if flag is True else 'NO')
Title: A Good Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct. Output Specification: Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. Demo Input: ['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n'] Demo Output: ['YES', 'NO'] Note: In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
```python n = int(input()) flag = False for i in range(n): name, before, after = map(str, input().split()) if flag is False: if int(before) >= 2400 and int(after) > int(before): flag = True continue print('YES' if flag is True else 'NO') ```
3
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,451,301,631
2,147,483,647
Python 3
OK
TESTS
25
122
307,200
from math import ceil a=input().split() b=input().split() c=0 for i in range (1,int(a[0])): if int(b[i])<=int(b[i-1]): d=ceil((int(b[i-1])-int(b[i])+1)/int(a[1])) c+=d b[i]=int(b[i])+int(a[1])*d 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 from math import ceil a=input().split() b=input().split() c=0 for i in range (1,int(a[0])): if int(b[i])<=int(b[i-1]): d=ceil((int(b[i-1])-int(b[i])+1)/int(a[1])) c+=d b[i]=int(b[i])+int(a[1])*d print(c) ```
3.936711
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,691,696,221
2,147,483,647
Python 3
OK
TESTS
69
46
0
intGamess = int(input()) mishkWins = 0 chrWins = 0 for i in range(intGamess): currResult = input().split(" ") mishkResult = int(currResult[0]) chrResult = int(currResult[1]) if(mishkResult > chrResult): mishkWins += 1 elif(chrResult > mishkResult): chrWins += 1 if(mishkWins > chrWins): print("Mishka") elif(chrWins > mishkWins): 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 intGamess = int(input()) mishkWins = 0 chrWins = 0 for i in range(intGamess): currResult = input().split(" ") mishkResult = int(currResult[0]) chrResult = int(currResult[1]) if(mishkResult > chrResult): mishkWins += 1 elif(chrResult > mishkResult): chrWins += 1 if(mishkWins > chrWins): print("Mishka") elif(chrWins > mishkWins): print("Chris") else: print("Friendship is magic!^^") ```
3
0
none
none
none
0
[ "none" ]
null
null
Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего брата.
В первой строке входных данных следуют два различных целых числа *a* и *b* (1<=≤<=*a*,<=*b*<=≤<=3, *a*<=≠<=*b*) — номера братьев, которые пришли на встречу вовремя. Номера даны в произвольном порядке.
Выведите единственное целое число — номер брата, который опоздал на встречу.
[ "3 1\n" ]
[ "2\n" ]
none
0
[ { "input": "3 1", "output": "2" }, { "input": "2 1", "output": "3" }, { "input": "2 3", "output": "1" }, { "input": "1 2", "output": "3" }, { "input": "1 3", "output": "2" }, { "input": "3 2", "output": "1" } ]
1,458,573,642
4,842
Python 3
OK
TESTS
6
62
4,812,800
print(*{'1','2','3'}.difference(set(input().split())))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего брата. Input Specification: В первой строке входных данных следуют два различных целых числа *a* и *b* (1<=≤<=*a*,<=*b*<=≤<=3, *a*<=≠<=*b*) — номера братьев, которые пришли на встречу вовремя. Номера даны в произвольном порядке. Output Specification: Выведите единственное целое число — номер брата, который опоздал на встречу. Demo Input: ['3 1\n'] Demo Output: ['2\n'] Note: none
```python print(*{'1','2','3'}.difference(set(input().split()))) ```
3
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.
The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { "input": "750 1000 54 103", "output": "Tie" }, { "input": "2000 1250 176 130", "output": "Tie" }, { "input": "1250 1750 145 179", "output": "Tie" }, { "input": "2000 2000 176 179", "output": "Tie" }, { "input": "1500 1500 148 148", "output": "Tie" }, { "input": "2750 1750 134 147", "output": "Misha" }, { "input": "3250 250 175 173", "output": "Misha" }, { "input": "500 500 170 176", "output": "Misha" }, { "input": "250 1000 179 178", "output": "Vasya" }, { "input": "3250 1000 160 138", "output": "Misha" }, { "input": "3000 2000 162 118", "output": "Tie" }, { "input": "1500 1250 180 160", "output": "Tie" }, { "input": "1250 2500 100 176", "output": "Tie" }, { "input": "3500 3500 177 178", "output": "Tie" }, { "input": "3000 3250 16 34", "output": "Tie" }, { "input": "1750 3000 137 49", "output": "Vasya" }, { "input": "500 1500 179 71", "output": "Vasya" }, { "input": "1250 2000 101 180", "output": "Misha" }, { "input": "250 750 180 176", "output": "Vasya" }, { "input": "2250 2250 163 145", "output": "Vasya" }, { "input": "3000 3000 176 78", "output": "Vasya" }, { "input": "250 3500 8 178", "output": "Vasya" }, { "input": "1750 1250 179 180", "output": "Misha" }, { "input": "2750 1750 13 164", "output": "Misha" }, { "input": "1750 2250 178 53", "output": "Vasya" }, { "input": "2500 2750 73 179", "output": "Misha" }, { "input": "1000 3500 178 175", "output": "Vasya" }, { "input": "1000 500 7 162", "output": "Misha" }, { "input": "1000 250 175 48", "output": "Misha" }, { "input": "1750 500 166 177", "output": "Misha" }, { "input": "250 250 0 0", "output": "Tie" }, { "input": "250 3500 0 0", "output": "Vasya" }, { "input": "250 3500 0 180", "output": "Vasya" }, { "input": "3500 3500 180 180", "output": "Tie" }, { "input": "3500 250 0 180", "output": "Misha" } ]
1,518,750,462
2,147,483,647
Python 3
OK
TESTS
40
62
5,632,000
# python 3 a, b, c, d = list(map(int, input().split())) Misha = max(3*a/10, a-a/250*c) Vasya = max(3*b/10, b-b/250*d) if Misha > Vasya: print("Misha") elif Misha < Vasya: print("Vasya") else: print("Tie")
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth. Input Specification: The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). Output Specification: Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points. Demo Input: ['500 1000 20 30\n', '1000 1000 1 1\n', '1500 1000 176 177\n'] Demo Output: ['Vasya\n', 'Tie\n', 'Misha\n'] Note: none
```python # python 3 a, b, c, d = list(map(int, input().split())) Misha = max(3*a/10, a-a/250*c) Vasya = max(3*b/10, b-b/250*d) if Misha > Vasya: print("Misha") elif Misha < Vasya: print("Vasya") else: print("Tie") ```
3
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
1,690,090,612
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
109
0
n=int(input()) x={} for i in range(n): s=input() if s not in x: x[s]=i else: x[s]+=i x=sorted(x.items(), key=lambda i: i[1], reverse=True) for i in x: print(i[0])
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. Output Specification: Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. Demo Input: ['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n'] Demo Output: ['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n'] Note: In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
```python n=int(input()) x={} for i in range(n): s=input() if s not in x: x[s]=i else: x[s]+=i x=sorted(x.items(), key=lambda i: i[1], reverse=True) for i in x: print(i[0]) ```
0
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1 " }, { "input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 " }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 \n39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "2\n2 1", "output": "2 \n1 " } ]
1,660,958,871
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
14,028,800
def solve(h, v): gd=[0]*(h+1) tmp=h ans="" for i in v: gd[i]=1 while tmp>0 and gd[tmp]==1: ans+=str(tmp) + " " tmp-=1 ans+="\n" return ans h=int(input()) v=list(map(int,input().split())) print(solve(h,v))
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Output Specification: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Demo Input: ['3\n3 1 2\n', '5\n4 5 1 2 3\n'] Demo Output: ['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n'] Note: In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
```python def solve(h, v): gd=[0]*(h+1) tmp=h ans="" for i in v: gd[i]=1 while tmp>0 and gd[tmp]==1: ans+=str(tmp) + " " tmp-=1 ans+="\n" return ans h=int(input()) v=list(map(int,input().split())) print(solve(h,v)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly *k* of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability. Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes. Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible.
The first line contains two integers *n* and *k* (3<=≤<=*n*<=≤<=2·105, 2<=≤<=*k*<=≤<=*n*<=-<=1) — the total number of nodes and the number of exit-nodes. Note that it is always possible to build at least one network with *n* nodes and *k* exit-nodes within the given constraints.
In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next *n*<=-<=1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to *n*. Exit-nodes can have any ids. If there are multiple answers, print any of them.
[ "3 2\n", "5 3\n" ]
[ "2\n1 2\n2 3\n", "3\n1 2\n2 3\n3 4\n3 5\n" ]
In the first example the only network is shown on the left picture. In the second example one of optimal networks is shown on the right picture. Exit-nodes are highlighted.
0
[ { "input": "3 2", "output": "2\n1 2\n2 3" }, { "input": "5 3", "output": "3\n1 2\n2 3\n3 4\n3 5" }, { "input": "4 2", "output": "3\n1 2\n2 3\n3 4" }, { "input": "4 3", "output": "2\n1 2\n2 3\n2 4" }, { "input": "5 2", "output": "4\n1 2\n2 3\n3 4\n4 5" }, { "input": "5 4", "output": "2\n1 2\n2 3\n2 4\n2 5" }, { "input": "6 2", "output": "5\n1 2\n2 3\n3 4\n4 5\n5 6" }, { "input": "6 3", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6" }, { "input": "6 4", "output": "3\n1 2\n2 3\n3 4\n3 5\n3 6" }, { "input": "6 5", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6" }, { "input": "1000 245", "output": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n6 12\n12 13\n13 14\n14 15\n15 16\n6 17\n17 18\n18 19\n19 20\n20 21\n6 22\n22 23\n23 24\n24 25\n25 26\n6 27\n27 28\n28 29\n29 30\n30 31\n6 32\n32 33\n33 34\n34 35\n35 36\n6 37\n37 38\n38 39\n39 40\n40 41\n6 42\n42 43\n43 44\n44 45\n45 46\n6 47\n47 48\n48 49\n49 50\n50 51\n6 52\n52 53\n53 54\n54 55\n55 56\n6 57\n57 58\n58 59\n59 60\n60 61\n6 62\n62 63\n63 64\n64 65\n65 66\n6 67\n67 68\n68 69\n69 70\n70 71\n6 72\n72 73\n73 74\n74 75\n75 76\n6 77\n77 78\n..." }, { "input": "1000 999", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "1024 23", "output": "90\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "200000 1014", "output": "396\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..." }, { "input": "100003 16", "output": "12502\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 ..." }, { "input": "7 2", "output": "6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7" }, { "input": "7 3", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7" }, { "input": "7 4", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n3 7" }, { "input": "7 5", "output": "3\n1 2\n2 3\n3 4\n3 5\n3 6\n3 7" }, { "input": "7 6", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7" }, { "input": "100 2", "output": "99\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "100 5", "output": "40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n21 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n21 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "100 59", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "100 98", "output": "3\n1 2\n2 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n3 25\n3 26\n3 27\n3 28\n3 29\n3 30\n3 31\n3 32\n3 33\n3 34\n3 35\n3 36\n3 37\n3 38\n3 39\n3 40\n3 41\n3 42\n3 43\n3 44\n3 45\n3 46\n3 47\n3 48\n3 49\n3 50\n3 51\n3 52\n3 53\n3 54\n3 55\n3 56\n3 57\n3 58\n3 59\n3 60\n3 61\n3 62\n3 63\n3 64\n3 65\n3 66\n3 67\n3 68\n3 69\n3 70\n3 71\n3 72\n3 73\n3 74\n3 75\n3 76\n3 77\n3 78\n3 79\n3 80\n3 81\n3 82\n3 83\n3 84\n3 85\n3 86\n3 87\n..." }, { "input": "100 99", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "1000 2", "output": "999\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..." }, { "input": "1000 5", "output": "400\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..." }, { "input": "1000 670", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "1000 998", "output": "3\n1 2\n2 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n3 25\n3 26\n3 27\n3 28\n3 29\n3 30\n3 31\n3 32\n3 33\n3 34\n3 35\n3 36\n3 37\n3 38\n3 39\n3 40\n3 41\n3 42\n3 43\n3 44\n3 45\n3 46\n3 47\n3 48\n3 49\n3 50\n3 51\n3 52\n3 53\n3 54\n3 55\n3 56\n3 57\n3 58\n3 59\n3 60\n3 61\n3 62\n3 63\n3 64\n3 65\n3 66\n3 67\n3 68\n3 69\n3 70\n3 71\n3 72\n3 73\n3 74\n3 75\n3 76\n3 77\n3 78\n3 79\n3 80\n3 81\n3 82\n3 83\n3 84\n3 85\n3 86\n3 87\n..." }, { "input": "100000 2", "output": "99999\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 ..." }, { "input": "100000 4", "output": "50000\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 ..." }, { "input": "100000 101", "output": "1982\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 7..." }, { "input": "100000 30005", "output": "8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n5 10\n10 11\n11 12\n12 13\n5 14\n14 15\n15 16\n16 17\n5 18\n18 19\n19 20\n20 21\n5 22\n22 23\n23 24\n24 25\n5 26\n26 27\n27 28\n28 29\n5 30\n30 31\n31 32\n32 33\n5 34\n34 35\n35 36\n36 37\n5 38\n38 39\n39 40\n40 41\n5 42\n42 43\n43 44\n44 45\n5 46\n46 47\n47 48\n48 49\n5 50\n50 51\n51 52\n52 53\n5 54\n54 55\n55 56\n56 57\n5 58\n58 59\n59 60\n60 61\n5 62\n62 63\n63 64\n64 65\n5 66\n66 67\n67 68\n68 69\n5 70\n70 71\n71 72\n72 73\n5 74\n74 75\n75 76\n76 77\n5 78\n78 ..." }, { "input": "100000 76541", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "100000 99998", "output": "3\n1 2\n2 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n3 25\n3 26\n3 27\n3 28\n3 29\n3 30\n3 31\n3 32\n3 33\n3 34\n3 35\n3 36\n3 37\n3 38\n3 39\n3 40\n3 41\n3 42\n3 43\n3 44\n3 45\n3 46\n3 47\n3 48\n3 49\n3 50\n3 51\n3 52\n3 53\n3 54\n3 55\n3 56\n3 57\n3 58\n3 59\n3 60\n3 61\n3 62\n3 63\n3 64\n3 65\n3 66\n3 67\n3 68\n3 69\n3 70\n3 71\n3 72\n3 73\n3 74\n3 75\n3 76\n3 77\n3 78\n3 79\n3 80\n3 81\n3 82\n3 83\n3 84\n3 85\n3 86\n3 87\n..." }, { "input": "100000 99999", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "200000 2", "output": "199999\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75..." }, { "input": "200000 5", "output": "80000\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 ..." }, { "input": "200000 211", "output": "1896\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 7..." }, { "input": "200000 100002", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "200000 145321", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "200000 199998", "output": "3\n1 2\n2 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n3 25\n3 26\n3 27\n3 28\n3 29\n3 30\n3 31\n3 32\n3 33\n3 34\n3 35\n3 36\n3 37\n3 38\n3 39\n3 40\n3 41\n3 42\n3 43\n3 44\n3 45\n3 46\n3 47\n3 48\n3 49\n3 50\n3 51\n3 52\n3 53\n3 54\n3 55\n3 56\n3 57\n3 58\n3 59\n3 60\n3 61\n3 62\n3 63\n3 64\n3 65\n3 66\n3 67\n3 68\n3 69\n3 70\n3 71\n3 72\n3 73\n3 74\n3 75\n3 76\n3 77\n3 78\n3 79\n3 80\n3 81\n3 82\n3 83\n3 84\n3 85\n3 86\n3 87\n..." }, { "input": "200000 199999", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "1024 2", "output": "1023\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 7..." }, { "input": "1024 16", "output": "128\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..." }, { "input": "1024 512", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "1024 511", "output": "5\n1 2\n2 3\n3 4\n4 5\n5 6\n4 7\n7 8\n4 9\n9 10\n4 11\n11 12\n4 13\n13 14\n4 15\n15 16\n4 17\n17 18\n4 19\n19 20\n4 21\n21 22\n4 23\n23 24\n4 25\n25 26\n4 27\n27 28\n4 29\n29 30\n4 31\n31 32\n4 33\n33 34\n4 35\n35 36\n4 37\n37 38\n4 39\n39 40\n4 41\n41 42\n4 43\n43 44\n4 45\n45 46\n4 47\n47 48\n4 49\n49 50\n4 51\n51 52\n4 53\n53 54\n4 55\n55 56\n4 57\n57 58\n4 59\n59 60\n4 61\n61 62\n4 63\n63 64\n4 65\n65 66\n4 67\n67 68\n4 69\n69 70\n4 71\n71 72\n4 73\n73 74\n4 75\n75 76\n4 77\n77 78\n4 79\n79 80\n4 81\n8..." }, { "input": "1024 513", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "1024 1023", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "1013 2", "output": "1012\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 7..." }, { "input": "1013 16", "output": "128\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..." }, { "input": "1013 23", "output": "88\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "1013 507", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "1013 508", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "1013 1012", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "100003 2", "output": "100002\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75..." }, { "input": "100003 23", "output": "8696\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 7..." }, { "input": "100003 19683", "output": "12\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n7 14\n14 15\n15 16\n16 17\n17 18\n18 19\n7 20\n20 21\n21 22\n22 23\n23 24\n24 25\n7 26\n26 27\n27 28\n28 29\n29 30\n30 31\n7 32\n32 33\n33 34\n34 35\n35 36\n36 37\n7 38\n38 39\n39 40\n40 41\n41 42\n42 43\n7 44\n44 45\n45 46\n46 47\n47 48\n48 49\n7 50\n50 51\n51 52\n52 53\n53 54\n54 55\n7 56\n56 57\n57 58\n58 59\n59 60\n60 61\n7 62\n62 63\n63 64\n64 65\n65 66\n66 67\n7 68\n68 69\n69 70\n70 71\n71 72\n72 73\n7 74\n74 75\n75 76\n76 77\n77 ..." }, { "input": "100003 100002", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "100001 2", "output": "100000\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75..." }, { "input": "100001 16", "output": "12500\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 ..." }, { "input": "100001 23", "output": "8696\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 7..." }, { "input": "100001 9091", "output": "22\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n12 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n12 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n12 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n12 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n12 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..." }, { "input": "100001 19683", "output": "12\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n7 14\n14 15\n15 16\n16 17\n17 18\n18 19\n7 20\n20 21\n21 22\n22 23\n23 24\n24 25\n7 26\n26 27\n27 28\n28 29\n29 30\n30 31\n7 32\n32 33\n33 34\n34 35\n35 36\n36 37\n7 38\n38 39\n39 40\n40 41\n41 42\n42 43\n7 44\n44 45\n45 46\n46 47\n47 48\n48 49\n7 50\n50 51\n51 52\n52 53\n53 54\n54 55\n7 56\n56 57\n57 58\n58 59\n59 60\n60 61\n7 62\n62 63\n63 64\n64 65\n65 66\n66 67\n7 68\n68 69\n69 70\n70 71\n71 72\n72 73\n7 74\n74 75\n75 76\n76 77\n77 ..." }, { "input": "100001 50000", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "100001 50001", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n8 9\n3 10\n10 11\n3 12\n12 13\n3 14\n14 15\n3 16\n16 17\n3 18\n18 19\n3 20\n20 21\n3 22\n22 23\n3 24\n24 25\n3 26\n26 27\n3 28\n28 29\n3 30\n30 31\n3 32\n32 33\n3 34\n34 35\n3 36\n36 37\n3 38\n38 39\n3 40\n40 41\n3 42\n42 43\n3 44\n44 45\n3 46\n46 47\n3 48\n48 49\n3 50\n50 51\n3 52\n52 53\n3 54\n54 55\n3 56\n56 57\n3 58\n58 59\n3 60\n60 61\n3 62\n62 63\n3 64\n64 65\n3 66\n66 67\n3 68\n68 69\n3 70\n70 71\n3 72\n72 73\n3 74\n74 75\n3 76\n76 77\n3 78\n78 79\n3 80\n80 81\n..." }, { "input": "100001 100000", "output": "2\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..." }, { "input": "10 6", "output": "4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n3 8\n3 9\n3 10" } ]
1,499,795,612
4,112
Python 3
RUNTIME_ERROR
PRETESTS
14
1,013
33,280,000
from sys import stdin, stdout def dfs(v, dist): visit[v] = 1 label = dist for u in vertices[v]: if not visit[u]: label = max(label, dfs(u, dist + 1)) return label n, k = map(int, stdin.readline().split()) challengers = [] ans = [] for i in range(2, k + 2): ans.append((1, i)) challengers.append(i) n = n - k - 1 v = k + 2 for i in range(n // k): update = [] for u in challengers: update.append(v) ans.append((u, v)) v += 1 challengers = update[:] for u in challengers[:n % k]: ans.append((u, v)) v += 1 visit = [0 for i in range(v)] vertices = [[] for i in range(v)] for a, b in ans: vertices[a].append(b) vertices[b].append(a) stdout.write(str(dfs(v - 1, 0)) + '\n') for a, b in ans: stdout.write(str(a) + ' ' + str(b) + '\n')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly *k* of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability. Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes. Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible. Input Specification: The first line contains two integers *n* and *k* (3<=≤<=*n*<=≤<=2·105, 2<=≤<=*k*<=≤<=*n*<=-<=1) — the total number of nodes and the number of exit-nodes. Note that it is always possible to build at least one network with *n* nodes and *k* exit-nodes within the given constraints. Output Specification: In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next *n*<=-<=1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to *n*. Exit-nodes can have any ids. If there are multiple answers, print any of them. Demo Input: ['3 2\n', '5 3\n'] Demo Output: ['2\n1 2\n2 3\n', '3\n1 2\n2 3\n3 4\n3 5\n'] Note: In the first example the only network is shown on the left picture. In the second example one of optimal networks is shown on the right picture. Exit-nodes are highlighted.
```python from sys import stdin, stdout def dfs(v, dist): visit[v] = 1 label = dist for u in vertices[v]: if not visit[u]: label = max(label, dfs(u, dist + 1)) return label n, k = map(int, stdin.readline().split()) challengers = [] ans = [] for i in range(2, k + 2): ans.append((1, i)) challengers.append(i) n = n - k - 1 v = k + 2 for i in range(n // k): update = [] for u in challengers: update.append(v) ans.append((u, v)) v += 1 challengers = update[:] for u in challengers[:n % k]: ans.append((u, v)) v += 1 visit = [0 for i in range(v)] vertices = [[] for i in range(v)] for a, b in ans: vertices[a].append(b) vertices[b].append(a) stdout.write(str(dfs(v - 1, 0)) + '\n') for a, b in ans: stdout.write(str(a) + ' ' + str(b) + '\n') ```
-1
559
A
Gerald's Hexagon
PROGRAMMING
1,600
[ "brute force", "geometry", "math" ]
null
null
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
[ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n" ]
[ "6\n", "13\n" ]
This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "1 1 1 1 1 1", "output": "6" }, { "input": "1 2 1 2 1 2", "output": "13" }, { "input": "2 4 5 3 3 6", "output": "83" }, { "input": "45 19 48 18 46 21", "output": "6099" }, { "input": "66 6 65 6 66 5", "output": "5832" }, { "input": "7 5 4 8 4 5", "output": "175" }, { "input": "3 2 1 4 1 2", "output": "25" }, { "input": "7 1 7 3 5 3", "output": "102" }, { "input": "9 2 9 3 8 3", "output": "174" }, { "input": "1 6 1 5 2 5", "output": "58" }, { "input": "41 64 48 61 44 68", "output": "17488" }, { "input": "1 59 2 59 1 60", "output": "3838" }, { "input": "30 36 36 32 34 38", "output": "7052" }, { "input": "50 40 46 38 52 34", "output": "11176" }, { "input": "4 60 4 60 4 60", "output": "4576" }, { "input": "718 466 729 470 714 481", "output": "2102808" }, { "input": "131 425 143 461 95 473", "output": "441966" }, { "input": "125 7 128 8 124 11", "output": "20215" }, { "input": "677 303 685 288 692 296", "output": "1365807" }, { "input": "1 577 7 576 2 582", "output": "342171" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "6000000" }, { "input": "1 1 1000 1 1 1000", "output": "4002" }, { "input": "1000 1000 1 1000 1000 1", "output": "2004000" }, { "input": "1000 1 1000 999 2 999", "output": "2003997" }, { "input": "1 1000 1 1 1000 1", "output": "4002" }, { "input": "888 888 888 887 889 887", "output": "4729487" } ]
1,578,073,580
2,147,483,647
PyPy 3
OK
TESTS
26
140
0
ar=list(map(int,input().split())) print((ar[0]+ar[1]+ar[2])**2-(ar[0])**2-ar[2]**2-ar[4]**2)
Title: Gerald's Hexagon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. Input Specification: The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. Output Specification: Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. Demo Input: ['1 1 1 1 1 1\n', '1 2 1 2 1 2\n'] Demo Output: ['6\n', '13\n'] Note: This is what Gerald's hexagon looks like in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's what it looks like in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python ar=list(map(int,input().split())) print((ar[0]+ar[1]+ar[2])**2-(ar[0])**2-ar[2]**2-ar[4]**2) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,640,350,092
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
str1 = input() str2 = input() res = "" j = 0 for i in str1: if i == str2[j]: res += '0' else: res += '1' print(res)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python str1 = input() str2 = input() res = "" j = 0 for i in str1: if i == str2[j]: res += '0' else: res += '1' print(res) ```
0
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding.
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Print one integer number — the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16", "output": "50" }, { "input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75", "output": "7" }, { "input": "8 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "3 8\n4 3 2", "output": "2" }, { "input": "3 8\n2 4 2", "output": "2" }, { "input": "3 6\n1 3 2", "output": "2" }, { "input": "3 6\n3 2 5", "output": "2" }, { "input": "3 8\n4 2 1", "output": "2" }, { "input": "5 6\n2 3 5 1 2", "output": "2" }, { "input": "2 6\n5 3", "output": "2" }, { "input": "4 12\n6 4 3 1", "output": "2" }, { "input": "3 18\n1 9 6", "output": "2" }, { "input": "3 9\n3 2 1", "output": "3" }, { "input": "3 6\n5 3 2", "output": "2" }, { "input": "2 10\n5 2", "output": "2" }, { "input": "2 18\n6 3", "output": "3" }, { "input": "4 12\n1 2 12 3", "output": "1" }, { "input": "3 7\n3 2 1", "output": "7" }, { "input": "3 6\n3 2 1", "output": "2" }, { "input": "5 10\n5 4 3 2 1", "output": "2" }, { "input": "5 16\n8 4 2 1 7", "output": "2" }, { "input": "6 7\n6 5 4 3 7 1", "output": "1" }, { "input": "2 6\n3 2", "output": "2" }, { "input": "2 4\n4 1", "output": "1" }, { "input": "6 8\n2 4 1 3 5 7", "output": "2" }, { "input": "6 8\n6 5 4 3 2 1", "output": "2" }, { "input": "6 15\n5 2 3 6 4 3", "output": "3" }, { "input": "4 8\n2 4 8 1", "output": "1" }, { "input": "2 5\n5 1", "output": "1" }, { "input": "4 18\n3 1 1 2", "output": "6" }, { "input": "2 1\n2 1", "output": "1" }, { "input": "3 10\n2 10 5", "output": "1" }, { "input": "5 12\n12 4 4 4 3", "output": "1" }, { "input": "3 6\n6 3 2", "output": "1" }, { "input": "2 2\n2 1", "output": "1" }, { "input": "3 18\n1 9 3", "output": "2" }, { "input": "3 8\n7 2 4", "output": "2" }, { "input": "2 100\n99 1", "output": "100" }, { "input": "4 12\n1 3 4 2", "output": "3" }, { "input": "3 6\n2 3 1", "output": "2" }, { "input": "4 6\n3 2 5 12", "output": "2" }, { "input": "4 97\n97 1 50 10", "output": "1" }, { "input": "3 12\n1 12 2", "output": "1" }, { "input": "4 12\n1 4 3 2", "output": "3" }, { "input": "1 1\n1", "output": "1" }, { "input": "3 19\n7 1 1", "output": "19" }, { "input": "5 12\n12 4 3 4 4", "output": "1" }, { "input": "3 8\n8 4 2", "output": "1" }, { "input": "3 3\n3 2 1", "output": "1" }, { "input": "5 6\n3 2 4 2 2", "output": "2" }, { "input": "2 16\n8 4", "output": "2" }, { "input": "3 6\n10 2 3", "output": "2" }, { "input": "5 3\n2 4 5 3 6", "output": "1" }, { "input": "11 99\n1 2 3 6 5 4 7 8 99 33 66", "output": "1" }, { "input": "3 12\n3 12 2", "output": "1" }, { "input": "5 25\n24 5 15 25 23", "output": "1" }, { "input": "2 4\n8 1", "output": "4" }, { "input": "4 100\n2 50 4 1", "output": "2" }, { "input": "3 28\n7 14 1", "output": "2" }, { "input": "4 8\n2 8 4 1", "output": "1" }, { "input": "4 6\n6 1 2 3", "output": "1" }, { "input": "2 12\n4 3", "output": "3" }, { "input": "4 12\n1 2 4 3", "output": "3" }, { "input": "5 12\n2 3 12 6 4", "output": "1" }, { "input": "4 4\n1 2 2 4", "output": "1" }, { "input": "3 6\n2 3 2", "output": "2" }, { "input": "4 21\n21 20 21 2", "output": "1" }, { "input": "3 8\n3 4 2", "output": "2" }, { "input": "1 25\n25", "output": "1" }, { "input": "99 12\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": "1" }, { "input": "98 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98", "output": "1" }, { "input": "79 12\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", "output": "1" }, { "input": "4 32\n1 1 1 1", "output": "32" }, { "input": "1 100\n1", "output": "100" }, { "input": "2 100\n7 1", "output": "100" }, { "input": "7 24\n1 3 6 4 5 2 7", "output": "4" }, { "input": "6 87\n1 2 8 4 5 7", "output": "87" }, { "input": "1 88\n1", "output": "88" }, { "input": "1 89\n1", "output": "89" } ]
1,675,869,716
2,147,483,647
PyPy 3
OK
TESTS
83
78
0
# LUOGU_RID: 101738100 n, k, *a = map(int, open(0).read().split()) print(min(k // x for x in a if k % x == 0))
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input Specification: The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Specification: Print one integer number — the minimum number of hours required to water the garden. Demo Input: ['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n'] Demo Output: ['2\n', '7\n'] Note: In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
```python # LUOGU_RID: 101738100 n, k, *a = map(int, open(0).read().split()) print(min(k // x for x in a if k % x == 0)) ```
3
347
B
Fixed Points
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points. You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
[ "5\n0 1 3 4 2\n" ]
[ "3\n" ]
none
1,000
[ { "input": "5\n0 1 3 4 2", "output": "3" }, { "input": "10\n6 9 4 7 8 2 3 5 0 1", "output": "2" }, { "input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67", "output": "3" }, { "input": "3\n0 1 2", "output": "3" }, { "input": "3\n2 1 0", "output": "3" }, { "input": "3\n1 2 0", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "5\n0 1 2 3 4", "output": "5" }, { "input": "4\n0 1 2 3", "output": "4" }, { "input": "7\n0 1 2 4 3 6 5", "output": "5" }, { "input": "6\n0 1 2 3 5 4", "output": "6" } ]
1,618,041,497
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
310
10,444,800
n = int(input()) arr = list(map(int, input().split())) c = 0 i = 0 while i < n: if arr[i] == i: c += 1 i += 1 j = 0 flag = False while j < n: temp = arr[j] if arr[temp] == j and temp != j: flag = True break j += 1 if flag == False: print(c+1) elif flag == True: print(c+2)
Title: Fixed Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points. You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. Output Specification: Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. Demo Input: ['5\n0 1 3 4 2\n'] Demo Output: ['3\n'] Note: none
```python n = int(input()) arr = list(map(int, input().split())) c = 0 i = 0 while i < n: if arr[i] == i: c += 1 i += 1 j = 0 flag = False while j < n: temp = arr[j] if arr[temp] == j and temp != j: flag = True break j += 1 if flag == False: print(c+1) elif flag == True: print(c+2) ```
0
39
G
Inverse Function
PROGRAMMING
2,400
[ "implementation" ]
G. Inverse Function
5
64
Petya wrote a programme on C++ that calculated a very interesting function *f*(*n*). Petya ran the program with a certain value of *n* and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of *n* the program was run. Help Petya, carry out the inverse function! Mostly, the program consists of a function in C++ with the following simplified syntax: - *function* ::= int f(int n) {*operatorSequence*}- *operatorSequence* ::= *operator* | *operator* *operatorSequence*- *operator* ::= return *arithmExpr*; | if (*logicalExpr*) return *arithmExpr*;- *logicalExpr* ::= *arithmExpr*<=&gt;<=*arithmExpr* | *arithmExpr*<=&lt;<=*arithmExpr* | *arithmExpr* == *arithmExpr*- *arithmExpr* ::= *sum*- *sum* ::= *product* | *sum*<=+<=*product* | *sum*<=-<=*product*- *product* ::= *multiplier* | *product*<=*<=*multiplier* | *product*<=/<=*multiplier*- *multiplier* ::= n | *number* | f(*arithmExpr*)- *number* ::= 0|1|2|... |32767 The whitespaces in a *operatorSequence* are optional. Thus, we have a function, in which body there are two kinds of operators. There is the operator "return *arithmExpr*;" that returns the value of the expression as the value of the function, and there is the conditional operator "if (*logicalExpr*) return *arithmExpr*;" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language — cycles, assignment operators, nested conditional operators etc, and other variables except the *n* parameter are used in the function. All the constants are integers in the interval [0..32767]. The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations "&gt;" (more), "&lt;" (less) and "==" (equals) also have standard meanings. Now you've got to pay close attention! The program is compiled with the help of 15-bit Berland C++ compiler invented by a Berland company BerSoft, that's why arithmetical operations are performed in a non-standard way. Addition, subtraction and multiplication are performed modulo 32768 (if the result of subtraction is negative, then 32768 is added to it until the number belongs to the interval [0..32767]). Division "/" is a usual integer division where the remainder is omitted. Examples of arithmetical operations: Guaranteed that for all values of *n* from 0 to 32767 the given function is performed correctly. That means that: 1. Division by 0 never occures. 2. When performing a function for the value *n*<==<=*N* recursive calls of the function *f* may occur only for the parameter value of 0,<=1,<=...,<=*N*<=-<=1. Consequently, the program never has an infinite recursion. 3. As the result of the sequence of the operators, the function always returns a value. We have to mention that due to all the limitations the value returned by the function *f* is independent from either global variables or the order of performing the calculations of arithmetical expressions as part of the logical one, or from anything else except the value of *n* parameter. That's why the *f* function can be regarded as a function in its mathematical sense, i.e. as a unique correspondence between any value of *n* from the interval [0..32767] and a value of *f*(*n*) from the same interval. Given the value of *f*(*n*), and you should find *n*. If the suitable *n* value is not unique, you should find the maximal one (from the interval [0..32767]).
The first line has an integer *f*(*n*) from the interval [0..32767]. The next lines have the description of the function *f*. In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed 100 bytes.
Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes).
[ "17\nint f(int n)\n{\nif (n &lt; 100) return 17;\nif (n &gt; 99) return 27;\n}\n", "13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}\n", "144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}" ]
[ "99\n", "13", "24588\n" ]
none
0
[ { "input": "17\nint f(int n)\n{\nif (n < 100) return 17;\nif (n > 99) return 27;\n}", "output": "99" }, { "input": "13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}", "output": "13" }, { "input": "144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}", "output": "24588" }, { "input": "32767\nint f(int n)\n{\nreturn n;\n}", "output": "32767" }, { "input": "27926\nint f(int n)\n{\nreturn n*n + 5*n/3 + 19 * 1423;\n}", "output": "29" }, { "input": "1\nint f(int n)\n{\nif (n == 0) return 153/12+5;\nreturn 32767/n;\n}", "output": "32767" }, { "input": "32\nint f(int n)\n{\nif (n == 0) return 1;\nreturn f(n - 1) * 7;\n}", "output": "-1" }, { "input": "1\nint f(int n)\n{\nif (n == 0) return 1;\nreturn f(n - 1) * 7;\n}", "output": "28672" }, { "input": "0\nint f(int n)\n{\nif (n < 2) return 1;\nreturn f(n - 1) + f(n - 2);\n}", "output": "24575" }, { "input": "32\nint f(int n)\n{\nif (n < 2) return 1;\nreturn f(n - 1) + f(n - 2);\n}", "output": "15959" }, { "input": "12351\nint f(int n)\n{\nif (n < 3) return n;\nreturn f(n - 1) * n + f(n - 2) + f(n - 3) / 5;\n}", "output": "26464" }, { "input": "0\nint f(int n){if (n < 1) return 0;return f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(0)))))))))))))))));}", "output": "32767" }, { "input": "0\nint f(int n){if (n < 1) return 1;if (n < 2) return 0;return f(f(f(f(f(f(f(f(f(f(n-1))))))))));}", "output": "32767" }, { "input": "1\nint f(int n){if (n < 1) return 1;if (n < 2) return 0;return f(f(f(f(f(f(f(f(f(f(n-1))))))))));}", "output": "32766" }, { "input": "14\nint f(int n)\n{\nif (n < 1) return 0;\nreturn f(n / 2) + 1;\n}", "output": "16383" }, { "input": "12\nint f(int n)\n{\nif (n < 1) return 0;\nreturn f(n / 2) + 1;\n}", "output": "4095" }, { "input": "100\nint f(int n){if (n < 3) return 1;return f(n-1)+f(n-2)+f(n-3);}", "output": "-1" }, { "input": "7113\nint f(int n)\n{\nif (n < 3) return n;\nreturn f(n - 1) * n + f(n - 2) + f(n - 3) / 5;\n}", "output": "31277" }, { "input": "7169\nint f(int n){if (n < 7) return 1; return f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)-f(n-6)-f(n-7);}", "output": "32258" }, { "input": "32657\nint f(int n){if (n < 7) return 1; return f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)-f(n-6)-f(n-7);}", "output": "32308" }, { "input": "5\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "output": "8" }, { "input": "2\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "output": "7" }, { "input": "1\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "output": "1" }, { "input": "7\nint f(int n){if (n < 2) return 1;if (n < 8) return 2;if (n > 8) return 7;if (n > 2) return 5;}", "output": "32767" }, { "input": "6\nint f(int n){if (n < 1025) return n*5+12/6-n/3*15-7;return f(n/2)-f(n-7)*f(n-7)-1024;}", "output": "-1" }, { "input": "32763\nint f(int n){if (n < 1025) return n*5+12/6-n/3*15-7;return f(n/2)-f(n-7)*f(n-7)-1024;}", "output": "1023" }, { "input": "280\nint f(int n){if (n < 1025) return n*5+12/6-n/3*15-7;return f(n/2)-f(n-7)*f(n-7)-1024;}", "output": "32746" }, { "input": "1\nint f(int n){return 1;return 2;return 3;return 4;return 5;return 6;return 7;return 8;return 9;}", "output": "32767" }, { "input": "2\nint f(int n){return 1;return 2;return 3;return 4;return 5;return 6;return 7;return 8;return 9;}", "output": "-1" }, { "input": "3647\nint f(int n){return 1*2*3+2*3*4-3*4*5-4*5*6+5*6*7+n*n*n-n/2/4/5+n+1/2+3*9*6-12+17/7*6+1-1;}", "output": "23117" }, { "input": "17463\nint f(int n){return 1*2*3+2*3*4-3*4*5-4*5*6+5*6*7+n*n*n-n/2/4/5+n+1/2+3*9*6-12+17/7*6+1-1;}", "output": "9167" }, { "input": "17\nint f(int n){if (n > 1000) return n/n;if (n > 100) return n/2;if (n > 10) return n; return 7;}", "output": "17" }, { "input": "55\nint f(int n)\n{\nif (n < 2) return 0;if (f(n-1) == f(n-2)) return f(n-2)+1;return f(n-1);\n}", "output": "111" }, { "input": "3\nint f(int n)\n{\nif (n > 5) return 8;\nif (n < 3) return 1;\nreturn f(12/n/n)+1;\n}", "output": "-1" }, { "input": "2\nint f(int n)\n{\nif (n > 5) return 8;\nif (n < 3) return 1;\nreturn f(12/n/n)+1;\n}", "output": "5" }, { "input": "354\nint f(int n)\n{\nif (n < 4) return 1;\nreturn f(n-1)*f(n-2)*f(n-3)*f(n-4)+n;\n}", "output": "19794" }, { "input": "9182\nint f(int n)\n{\nif (n < 4) return 1;\nreturn f(n-1)*f(n-2)*f(n-3)*f(n-4)+n;\n}", "output": "27142" }, { "input": "32767\nint f(int n)\n{\nif (n < 5) return 0-1;if (f(n/2)*f(n-1) < 0) return f(n+28);return 10;\n}", "output": "4" }, { "input": "57\nint f(int n)\n{\nif (n/2*2 == n) return 1;\nif (n/2*2 == n-1) return 0;\nreturn 57;\n}", "output": "-1" }, { "input": "1\nint f(int n)\n{\nif (n/2*2 == n) return 1;\nif (n/2*2 == n-1) return 0;\nreturn 57;\n}", "output": "32766" }, { "input": "15\nint f(int n){if (n > 1) return f(n-2)/f(n-1)+15;if (n == 0) return 0;if (n == 1) return 1;}", "output": "32767" } ]
1,622,575,725
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
840
9,523,200
import re, sys, functools def cut_modulo(x): y = x % 32768 if (y < 0): y += 32768 return y class berland_cpp_int: def __init__(self, x): self.value = cut_modulo(int(x)) def __add__(self, x): return berland_cpp_int(cut_modulo(self.value + x.value)) def __sub__(self, x): return berland_cpp_int(cut_modulo(self.value - x.value)) def __mul__(self, x): return berland_cpp_int(cut_modulo(self.value * x.value)) def __div__(self, x): return berland_cpp_int(cut_modulo(self.value // x.value)) def __and__(self, x): return berland_cpp_int(cut_modulo(self.value & x.value)) def __eq__(self, x): return self.value == x.value def __lt__(self, x): return self.value < x.value def __gt__(self, x): return self.value > x.value def __str__(self): return str(self.value) def __int__(self): return self.value def __hash__(self): return self.value def translate_program(source_code): s = source_code s = s.replace('\n', '') s = s.replace('{', '') s = s.replace('}', '') s = re.sub('([0-9]+)', 'berland_cpp_int(\\1)', s) s = s.replace('int f(int n)', \ '\[email protected]_cache(maxsize=None)\ndef f(n):\n\t') s = re.sub('return(.*?);', 'return berland_cpp_int(\\1);', s) s = s.replace(';', '\n\t') s = s.replace('return', ':return') s = re.sub('\t[ :]+', '\t', s) return s #file_input = sys.stdin.read().split('\n') file_input = sys.stdin.read().split('\n') nnn = int(file_input[0]) source = '\n'.join(file_input[1:]) compiled = translate_program(source) exec(compiled) vals = list(map(lambda x: f(berland_cpp_int(x)), range(32768))) vals = list(map(lambda x: x.value, vals)) ans = -1 for i in range(32768): if (vals[i] == nnn): ans = i print(ans)
Title: Inverse Function Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: Petya wrote a programme on C++ that calculated a very interesting function *f*(*n*). Petya ran the program with a certain value of *n* and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of *n* the program was run. Help Petya, carry out the inverse function! Mostly, the program consists of a function in C++ with the following simplified syntax: - *function* ::= int f(int n) {*operatorSequence*}- *operatorSequence* ::= *operator* | *operator* *operatorSequence*- *operator* ::= return *arithmExpr*; | if (*logicalExpr*) return *arithmExpr*;- *logicalExpr* ::= *arithmExpr*<=&gt;<=*arithmExpr* | *arithmExpr*<=&lt;<=*arithmExpr* | *arithmExpr* == *arithmExpr*- *arithmExpr* ::= *sum*- *sum* ::= *product* | *sum*<=+<=*product* | *sum*<=-<=*product*- *product* ::= *multiplier* | *product*<=*<=*multiplier* | *product*<=/<=*multiplier*- *multiplier* ::= n | *number* | f(*arithmExpr*)- *number* ::= 0|1|2|... |32767 The whitespaces in a *operatorSequence* are optional. Thus, we have a function, in which body there are two kinds of operators. There is the operator "return *arithmExpr*;" that returns the value of the expression as the value of the function, and there is the conditional operator "if (*logicalExpr*) return *arithmExpr*;" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language — cycles, assignment operators, nested conditional operators etc, and other variables except the *n* parameter are used in the function. All the constants are integers in the interval [0..32767]. The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations "&gt;" (more), "&lt;" (less) and "==" (equals) also have standard meanings. Now you've got to pay close attention! The program is compiled with the help of 15-bit Berland C++ compiler invented by a Berland company BerSoft, that's why arithmetical operations are performed in a non-standard way. Addition, subtraction and multiplication are performed modulo 32768 (if the result of subtraction is negative, then 32768 is added to it until the number belongs to the interval [0..32767]). Division "/" is a usual integer division where the remainder is omitted. Examples of arithmetical operations: Guaranteed that for all values of *n* from 0 to 32767 the given function is performed correctly. That means that: 1. Division by 0 never occures. 2. When performing a function for the value *n*<==<=*N* recursive calls of the function *f* may occur only for the parameter value of 0,<=1,<=...,<=*N*<=-<=1. Consequently, the program never has an infinite recursion. 3. As the result of the sequence of the operators, the function always returns a value. We have to mention that due to all the limitations the value returned by the function *f* is independent from either global variables or the order of performing the calculations of arithmetical expressions as part of the logical one, or from anything else except the value of *n* parameter. That's why the *f* function can be regarded as a function in its mathematical sense, i.e. as a unique correspondence between any value of *n* from the interval [0..32767] and a value of *f*(*n*) from the same interval. Given the value of *f*(*n*), and you should find *n*. If the suitable *n* value is not unique, you should find the maximal one (from the interval [0..32767]). Input Specification: The first line has an integer *f*(*n*) from the interval [0..32767]. The next lines have the description of the function *f*. In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed 100 bytes. Output Specification: Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes). Demo Input: ['17\nint f(int n)\n{\nif (n &lt; 100) return 17;\nif (n &gt; 99) return 27;\n}\n', '13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}\n', '144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}'] Demo Output: ['99\n', '13', '24588\n'] Note: none
```python import re, sys, functools def cut_modulo(x): y = x % 32768 if (y < 0): y += 32768 return y class berland_cpp_int: def __init__(self, x): self.value = cut_modulo(int(x)) def __add__(self, x): return berland_cpp_int(cut_modulo(self.value + x.value)) def __sub__(self, x): return berland_cpp_int(cut_modulo(self.value - x.value)) def __mul__(self, x): return berland_cpp_int(cut_modulo(self.value * x.value)) def __div__(self, x): return berland_cpp_int(cut_modulo(self.value // x.value)) def __and__(self, x): return berland_cpp_int(cut_modulo(self.value & x.value)) def __eq__(self, x): return self.value == x.value def __lt__(self, x): return self.value < x.value def __gt__(self, x): return self.value > x.value def __str__(self): return str(self.value) def __int__(self): return self.value def __hash__(self): return self.value def translate_program(source_code): s = source_code s = s.replace('\n', '') s = s.replace('{', '') s = s.replace('}', '') s = re.sub('([0-9]+)', 'berland_cpp_int(\\1)', s) s = s.replace('int f(int n)', \ '\[email protected]_cache(maxsize=None)\ndef f(n):\n\t') s = re.sub('return(.*?);', 'return berland_cpp_int(\\1);', s) s = s.replace(';', '\n\t') s = s.replace('return', ':return') s = re.sub('\t[ :]+', '\t', s) return s #file_input = sys.stdin.read().split('\n') file_input = sys.stdin.read().split('\n') nnn = int(file_input[0]) source = '\n'.join(file_input[1:]) compiled = translate_program(source) exec(compiled) vals = list(map(lambda x: f(berland_cpp_int(x)), range(32768))) vals = list(map(lambda x: x.value, vals)) ans = -1 for i in range(32768): if (vals[i] == nnn): ans = i print(ans) ```
-1
496
C
Removing Columns
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table   we obtain the table:   A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
The first line contains two integers  — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* small English letters each — the characters of the table.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
[ "1 10\ncodeforces\n", "4 4\ncase\ncare\ntest\ncode\n", "5 4\ncode\nforc\nesco\ndefo\nrces\n" ]
[ "0\n", "2\n", "4\n" ]
In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings *s* and *t* have equal length. Then, *s* is lexicographically larger than *t* if they are not equal and the character following the largest common prefix of *s* and *t* (the prefix may be empty) in *s* is alphabetically larger than the corresponding character of *t*.
1,750
[ { "input": "1 10\ncodeforces", "output": "0" }, { "input": "4 4\ncase\ncare\ntest\ncode", "output": "2" }, { "input": "5 4\ncode\nforc\nesco\ndefo\nrces", "output": "4" }, { "input": "2 2\nfb\nye", "output": "0" }, { "input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrzh", "output": "0" }, { "input": "10 10\nddorannorz\nmdrnzqvqgo\ngdtdjmlsuf\neoxbrntqdp\nhribwlslgo\newlqrontvk\nnxibmnawnh\nvxiwdjvdom\nhyhhewmzmp\niysgvzayst", "output": "1" }, { "input": "9 7\nygqartj\nlgwxlqv\nancjjpr\nwnnhkpx\ncnnhvty\nxsfrbqp\nxsolyne\nbsoojiq\nxstetjb", "output": "1" }, { "input": "4 50\nulkteempxafxafcvfwmwhsixwzgbmubcqqceevbbwijeerqbsj\neyqxsievaratndjoekltlqwppfgcukjwxdxexhejbfhzklppkk\npskatxpbjdbmjpwhussetytneohgzxgirluwnbraxtxmaupuid\neappatavdzktqlrjqttmwwroathnulubpjgsjazcycecwmxwvn", "output": "20" }, { "input": "5 50\nvlrkwhvbigkhihwqjpvmohdsszvndheqlmdsspkkxxiedobizr\nmhnzwdefqmttclfxocdmvvtdjtvqhmdllrtrrlnewuqowmtrmp\nrihlhxrqfhpcddslxepesvjqmlqgwyehvxjcsytevujfegeewh\nqrdyiymanvbdjomyruspreihahjhgkcixwowfzczundxqydldq\nkgnrbjlrmkuoiuzeiqwhnyjpuzfnsinqiamlnuzksrdnlvaxjd", "output": "50" }, { "input": "100 1\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "output": "0" }, { "input": "1 100\nteloaetuldspjqdlcktjlishwynmjjhlomvemhoyyplbltfwmrlnazbbjvyvwvoxjvvoadkznvxqubgwesoxrznvbdizjdzixecb", "output": "0" }, { "input": "4 100\ngdgmmejiigzsmlarrnfsypvlbutvoxazcigpcospgztqkowfhhbnnbxxrbmwbxwkvxlxzabjjjdtbebedukdelooqlxnadjwjpnp\ndmtsnsbsfdzqvydxcdcnkkfcbseicxhvclsligbhqlkccwujpirymoshkqcosbtlxdypsdqkqaolrqtiibymavcwmbfryttdckhw\njtdmpdljcpciuuoznvqqmafvoqychzfslmwqouuarxctunlzegxsucrwontjplkkxhgixgdbvnewphnatxnwqxqshcexpxlyjuwq\nvhdtvexkyhjmahejbhyfeaompjkdvxmbtdbmvrxrixhnkkjgyvfbxlviatbikfejnqhkrtafftmsgyznpsfxsnzaqdzhxridzilo", "output": "4" }, { "input": "5 2\nab\ndc\ngd\ngc\nhx", "output": "1" }, { "input": "2 1\nb\na", "output": "1" }, { "input": "4 3\nabd\nacc\nbdx\nbcy", "output": "2" }, { "input": "4 2\nad\nac\nbd\nbc", "output": "1" }, { "input": "3 3\naac\nabb\nbba", "output": "0" }, { "input": "3 3\nadc\nbdb\ncda", "output": "0" }, { "input": "4 3\nabz\ndby\ngbx\nhbw", "output": "0" }, { "input": "3 3\naac\nbab\ncaa", "output": "0" }, { "input": "5 6\naaaeaa\nababab\nacacac\nadadad\naeaeae", "output": "0" }, { "input": "3 2\naa\nbc\nba", "output": "1" }, { "input": "3 3\naaz\ndaa\nbaa", "output": "2" }, { "input": "3 3\nabc\nbbb\ncba", "output": "0" }, { "input": "2 3\naxc\nbxa", "output": "0" } ]
1,588,672,460
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
109
307,200
def solve(): n,m=map(int,input().split()) A=[list(input()) for i in range(n)] if(n==1): print(0) return count=0 j=0 while (j<len(A[0])): br=0 for i in range(n-1): if not (A[i][j]<=A[i+1][j]): br=1 break if (br): for i in range(n): del(A[i][j]) count+=1 else: j+=1 B=A[::] A.sort() if(B==A): print(count) return A=B[::] solve()
Title: Removing Columns Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table   we obtain the table:   A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input Specification: The first line contains two integers  — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* small English letters each — the characters of the table. Output Specification: Print a single number — the minimum number of columns that you need to remove in order to make the table good. Demo Input: ['1 10\ncodeforces\n', '4 4\ncase\ncare\ntest\ncode\n', '5 4\ncode\nforc\nesco\ndefo\nrces\n'] Demo Output: ['0\n', '2\n', '4\n'] Note: In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings *s* and *t* have equal length. Then, *s* is lexicographically larger than *t* if they are not equal and the character following the largest common prefix of *s* and *t* (the prefix may be empty) in *s* is alphabetically larger than the corresponding character of *t*.
```python def solve(): n,m=map(int,input().split()) A=[list(input()) for i in range(n)] if(n==1): print(0) return count=0 j=0 while (j<len(A[0])): br=0 for i in range(n-1): if not (A[i][j]<=A[i+1][j]): br=1 break if (br): for i in range(n): del(A[i][j]) count+=1 else: j+=1 B=A[::] A.sort() if(B==A): print(count) return A=B[::] solve() ```
0
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input": "5\n5 4 3 2 1", "output": "5 4 3 2 1" }, { "input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19" }, { "input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19" }, { "input": "10\n3 4 5 6 7 8 9 10 1 2", "output": "9 10 1 2 3 4 5 6 7 8" }, { "input": "8\n1 5 3 7 2 6 4 8", "output": "1 5 3 7 2 6 4 8" }, { "input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19" }, { "input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25" }, { "input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30" }, { "input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49" }, { "input": "12\n3 8 7 4 6 5 2 1 11 9 10 12", "output": "8 7 1 4 6 5 3 2 10 11 9 12" }, { "input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4" }, { "input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1" }, { "input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3" }, { "input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53" }, { "input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24" }, { "input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61" }, { "input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14" }, { "input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21" }, { "input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9" }, { "input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13" }, { "input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16" }, { "input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6" }, { "input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90" }, { "input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9" }, { "input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20" }, { "input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28" }, { "input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5" }, { "input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43" }, { "input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43" }, { "input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45" }, { "input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64" }, { "input": "12\n12 3 1 5 11 6 7 10 2 8 9 4", "output": "3 9 2 12 4 6 7 10 11 8 5 1" }, { "input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44" }, { "input": "8\n1 3 5 2 4 8 6 7", "output": "1 4 2 5 3 7 8 6" }, { "input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12" }, { "input": "10\n2 9 4 6 10 1 7 5 3 8", "output": "6 1 9 3 8 4 7 10 2 5" }, { "input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7" }, { "input": "10\n2 4 9 3 6 8 10 5 1 7", "output": "9 1 4 2 8 5 10 6 3 7" }, { "input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23" }, { "input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27" }, { "input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23" }, { "input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50" }, { "input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98" }, { "input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25" }, { "input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54" }, { "input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71" }, { "input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8" }, { "input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51" }, { "input": "7\n2 1 5 7 3 4 6", "output": "2 1 5 6 3 7 4" }, { "input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31" }, { "input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21" }, { "input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11" }, { "input": "9\n8 5 2 6 1 9 4 7 3", "output": "5 3 9 7 2 4 8 1 6" }, { "input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13" }, { "input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6" }, { "input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14" }, { "input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16" }, { "input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24" }, { "input": "9\n4 8 6 5 3 9 2 7 1", "output": "9 7 5 1 4 3 8 2 6" }, { "input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32" }, { "input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11" }, { "input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "output": "10 4 1 8 6 13 12 5 3 11 9 2 7" }, { "input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37" }, { "input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25" }, { "input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24" }, { "input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59" }, { "input": "6\n4 3 6 5 1 2", "output": "5 6 2 1 4 3" }, { "input": "9\n7 8 5 3 1 4 2 9 6", "output": "5 7 4 6 3 9 1 2 8" }, { "input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13" }, { "input": "1\n1", "output": "1" }, { "input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13" }, { "input": "2\n2 1", "output": "2 1" }, { "input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18" }, { "input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1" }, { "input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36" }, { "input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32" }, { "input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40" }, { "input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21" }, { "input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4" }, { "input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50" }, { "input": "10\n2 10 7 4 1 5 8 6 3 9", "output": "5 1 9 4 6 8 3 7 10 2" }, { "input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1" }, { "input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11" }, { "input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37" }, { "input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53" }, { "input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49" }, { "input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38" }, { "input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2" }, { "input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5" }, { "input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12" }, { "input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82" }, { "input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97" }, { "input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96" }, { "input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96" }, { "input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36" }, { "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": "100 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" } ]
1,693,820,957
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n = int(input()) t = [int(i) for i in range(n)] ans = [] for i in range(n): idx = t[i]-1 ans.append(t[idx]+1) print(*ans)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Specification: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Demo Input: ['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['4 1 2 3\n', '1 3 2\n', '1 2\n'] Note: none
```python n = int(input()) t = [int(i) for i in range(n)] ans = [] for i in range(n): idx = t[i]-1 ans.append(t[idx]+1) print(*ans) ```
0
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8", "output": "1 2 3 4 5 6 7 8 9 0" }, { "input": "1 1\n4\n4", "output": "4" }, { "input": "3 7\n6 3 4\n4 9 0 1 7 8 6", "output": "6 4" }, { "input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0", "output": "0" }, { "input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6", "output": "6 0 3 8 1" }, { "input": "8 2\n7 2 9 6 1 0 3 4\n6 3", "output": "6 3" }, { "input": "5 4\n7 0 1 4 9\n0 9 5 3", "output": "0 9" }, { "input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6", "output": "6" }, { "input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2", "output": "2 3" }, { "input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2", "output": "3 9 2 4" }, { "input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6", "output": "1 2 3 8 6 5" }, { "input": "8 2\n7 4 8 9 2 5 6 1\n6 4", "output": "4 6" }, { "input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3", "output": "0 3" }, { "input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8", "output": "2 8 1 3" }, { "input": "1 6\n3\n6 8 2 4 5 3", "output": "3" }, { "input": "1 8\n0\n9 2 4 8 1 5 0 7", "output": "0" }, { "input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4", "output": "7 9 4 1 0" }, { "input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1", "output": "0 1" }, { "input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2", "output": "2 9 6 1 4" }, { "input": "6 3\n8 3 9 2 7 6\n5 4 3", "output": "3" }, { "input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5", "output": "8 3 9 6" }, { "input": "1 2\n1\n1 0", "output": "1" }, { "input": "3 6\n1 2 3\n4 5 6 1 2 3", "output": "1 2 3" }, { "input": "1 2\n2\n1 2", "output": "2" }, { "input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9", "output": "9" } ]
1,529,298,987
1,887
Python 3
OK
TESTS
31
92
0
n,m=[int(x) for x in input().split()] num=[int(x) for x in input().split()] op=[int(x) for x in input().split()] fin=[] for x in num: if x in op: fin.append(str(x)) print(' '.join(fin))
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. Input Specification: The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. Output Specification: In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. Demo Input: ['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n'] Demo Output: ['7 1 2\n', '1 0\n'] Note: In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.
```python n,m=[int(x) for x in input().split()] num=[int(x) for x in input().split()] op=[int(x) for x in input().split()] fin=[] for x in num: if x in op: fin.append(str(x)) print(' '.join(fin)) ```
3
424
B
Megacity
PROGRAMMING
1,200
[ "binary search", "greedy", "implementation", "sortings" ]
null
null
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with *n* other locations, the *i*-th one has coordinates (*x**i*, *y**i*) with the population of *k**i* people. You can widen the city boundaries to a circle of radius *r*. In such case all locations inside the circle and on its border are included into the city. Your goal is to write a program that will determine the minimum radius *r*, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity.
The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=&lt;<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the number *k**i* of people in it (1<=≤<=*k**i*<=&lt;<=106). Each coordinate is an integer and doesn't exceed 104 in its absolute value. It is guaranteed that no two locations are at the same point and no location is at point (0; 0).
In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity. The answer is considered correct if the absolute or relative error don't exceed 10<=-<=6.
[ "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n", "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n", "2 1\n1 1 999997\n2 2 1\n" ]
[ "2.8284271\n", "1.4142136\n", "-1" ]
none
1,000
[ { "input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271" }, { "input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136" }, { "input": "2 1\n1 1 999997\n2 2 1", "output": "-1" }, { "input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10", "output": "4.2426407" }, { "input": "15 95473\n-9 6 199715\n0 -8 110607\n0 2 6621\n-3 -2 59894\n-10 -8 175440\n-2 0 25814\n10 -4 68131\n7 1 9971\n6 7 821\n6 5 20208\n6 2 68468\n0 7 37427\n1 -3 13337\n-10 7 113041\n-6 -2 44028", "output": "12.8062485" }, { "input": "20 93350\n13 -28 486\n26 -26 48487\n5 -23 143368\n-23 -25 10371\n-2 -7 75193\n0 -8 3\n-6 -11 5015\n-19 -18 315278\n28 -15 45801\n21 8 4590\n-4 -28 12926\n-16 17 9405\n-28 -23 222092\n1 -10 1857\n14 -28 35170\n-4 -22 22036\n-2 -10 1260\n-1 12 375745\n-19 -24 38845\n10 -25 9256", "output": "26.1725047" }, { "input": "30 505231\n-18 16 88130\n-10 16 15693\n16 -32 660\n-27 17 19042\n30 -37 6680\n36 19 299674\n-45 21 3300\n11 27 76\n-49 -34 28649\n-1 11 31401\n25 42 20858\n-40 6 455660\n-29 43 105001\n-38 10 6042\n19 -45 65551\n20 -9 148533\n-5 -24 393442\n-43 2 8577\n-39 18 97059\n12 28 39189\n35 23 28178\n40 -34 51687\n23 41 219028\n21 -44 927\n47 8 13206\n33 41 97342\n10 18 24895\n0 12 288\n0 -44 1065\n-25 43 44231", "output": "24.5153013" }, { "input": "2 500000\n936 1000 500000\n961 976 500000", "output": "1369.7065379" }, { "input": "10 764008\n959 32 23049\n-513 797 38979\n-603 -838 24916\n598 -430 25414\n-280 -624 18714\n330 891 21296\n-347 -68 27466\n650 -842 30125\n-314 889 35394\n275 969 5711", "output": "1063.7029661" }, { "input": "30 295830\n1 -4 24773\n4 3 26175\n-2 -3 14789\n2 -1 46618\n-2 -2 52997\n-3 0 517\n-2 0 18173\n-4 -3 54465\n2 4 63579\n4 -4 41821\n2 2 11018\n0 4 42856\n0 -1 51885\n-3 4 57137\n3 0 4688\n0 2 60137\n-4 4 33484\n-1 3 66196\n3 -1 53634\n0 -2 41630\n-2 1 54606\n2 -2 2978\n2 -3 23733\n1 -2 35248\n-3 -3 15124\n-2 -4 26518\n4 0 28151\n4 -1 18348\n3 3 16914\n-4 2 26013", "output": "4.4721360" }, { "input": "10 511500\n-5129 -3858 76954\n1296 1130 36126\n1219 6732 102003\n-8026 -178 4150\n-3261 1342 105429\n7965 -3013 62561\n5607 8963 53539\n-9044 -3999 16509\n1406 4103 115667\n-3716 2522 110626", "output": "6841.4753526" }, { "input": "20 39342\n2 0 36476\n-3 1 136925\n1 3 31234\n0 -3 23785\n-1 3 77700\n-3 -1 50490\n-1 -3 13965\n-3 2 121093\n3 0 118933\n-3 0 125552\n-3 3 54779\n-2 0 96250\n1 2 142643\n2 2 23848\n0 2 29845\n0 -2 80462\n-1 1 91852\n-1 2 26526\n0 -1 136272\n1 1 108999", "output": "3.0000000" }, { "input": "2 1\n1 0 1\n0 1 999999", "output": "1.0000000" }, { "input": "2 999997\n1 1 1\n1 2 1", "output": "-1" } ]
1,603,330,935
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
108
307,200
def solve(need): if need <= 0: print(0) return location = [] for _ in range(n): x, y, k = map(int, input().split()) location.append(((x**2 + y**2)**0.5, k)) location.sort() for r, population in location: if need > 0: need -= population else: break print("{:.7f}".format(r)) n, s = map(int, input().split()) need = 10**6 - s solve(need)
Title: Megacity Time Limit: None seconds Memory Limit: None megabytes Problem Description: The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with *n* other locations, the *i*-th one has coordinates (*x**i*, *y**i*) with the population of *k**i* people. You can widen the city boundaries to a circle of radius *r*. In such case all locations inside the circle and on its border are included into the city. Your goal is to write a program that will determine the minimum radius *r*, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity. Input Specification: The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=&lt;<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the number *k**i* of people in it (1<=≤<=*k**i*<=&lt;<=106). Each coordinate is an integer and doesn't exceed 104 in its absolute value. It is guaranteed that no two locations are at the same point and no location is at point (0; 0). Output Specification: In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity. The answer is considered correct if the absolute or relative error don't exceed 10<=-<=6. Demo Input: ['4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n', '4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n', '2 1\n1 1 999997\n2 2 1\n'] Demo Output: ['2.8284271\n', '1.4142136\n', '-1'] Note: none
```python def solve(need): if need <= 0: print(0) return location = [] for _ in range(n): x, y, k = map(int, input().split()) location.append(((x**2 + y**2)**0.5, k)) location.sort() for r, population in location: if need > 0: need -= population else: break print("{:.7f}".format(r)) n, s = map(int, input().split()) need = 10**6 - s solve(need) ```
0
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,567,407,357
2,147,483,647
PyPy 3
OK
TESTS
45
280
0
from math import gcd a,b,n=map(int,input().split()) x=n flag=1 for i in range(n): if i%2==0: g=gcd(a,x) if x>=g: flag=0 x=x-g else: break else: g=gcd(b,x) if x>=g: flag=1 x=x-g else: break print(flag)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python from math import gcd a,b,n=map(int,input().split()) x=n flag=1 for i in range(n): if i%2==0: g=gcd(a,x) if x>=g: flag=0 x=x-g else: break else: g=gcd(b,x) if x>=g: flag=1 x=x-g else: break print(flag) ```
3
117
B
Very Interesting Game
PROGRAMMING
1,800
[ "brute force", "number theory" ]
null
null
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and representing a number that does not exceed *b*. Here *a* and *b* are some given constants, *s*1 and *s*2 are chosen by the players. The strings are allowed to contain leading zeroes. If a number obtained by the concatenation (joining together) of strings *s*1 and *s*2 is divisible by *mod*, then the second player wins. Otherwise the first player wins. You are given numbers *a*, *b*, *mod*. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.
The first line contains three integers *a*, *b*, *mod* (0<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*mod*<=≤<=107).
If the first player wins, print "1" and the lexicographically minimum string *s*1 he has to write to win. If the second player wins, print the single number "2".
[ "1 10 7\n", "4 0 9\n" ]
[ "2\n", "1 000000001\n" ]
The lexical comparison of strings is performed by the &lt; operator in modern programming languages. String *x* is lexicographically less than string *y* if exists such *i* (1 ≤ *i* ≤ 9), that *x*<sub class="lower-index">*i*</sub> &lt; *y*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* &lt; *i*) *x*<sub class="lower-index">*j*</sub> = *y*<sub class="lower-index">*j*</sub>. These strings always have length 9.
1,000
[ { "input": "1 10 7", "output": "2" }, { "input": "4 0 9", "output": "1 000000001" }, { "input": "10 7 8", "output": "2" }, { "input": "6 4 10", "output": "2" }, { "input": "4 1 4", "output": "2" }, { "input": "4 7 9", "output": "1 000000001" }, { "input": "13 4 51", "output": "1 000000001" }, { "input": "0 0 1", "output": "2" }, { "input": "1 0 1", "output": "2" }, { "input": "2 1 3", "output": "1 000000001" }, { "input": "0 2 2", "output": "2" }, { "input": "2 3 1", "output": "2" }, { "input": "3 0 3", "output": "1 000000001" }, { "input": "1 1 2", "output": "2" }, { "input": "3 2 1", "output": "2" }, { "input": "0 3 3", "output": "2" }, { "input": "4 0 13", "output": "1 000000001" }, { "input": "1 2 13", "output": "2" }, { "input": "4 3 12", "output": "1 000000001" }, { "input": "1 2 11", "output": "2" }, { "input": "4 3 12", "output": "1 000000001" }, { "input": "815 216 182", "output": "2" }, { "input": "218 550 593", "output": "1 000000011" }, { "input": "116482865 344094604 3271060", "output": "2" }, { "input": "19749161 751031022 646204", "output": "2" }, { "input": "70499104 10483793 5504995", "output": "2" }, { "input": "1960930 562910 606828", "output": "1 000000011" }, { "input": "8270979 4785512 9669629", "output": "1 000000001" }, { "input": "9323791 4748006 5840080", "output": "1 000000005" }, { "input": "972037745 4602117 5090186", "output": "1 000000011" }, { "input": "585173560 4799128 5611727", "output": "1 000000036" }, { "input": "22033548 813958 4874712", "output": "1 000000001" }, { "input": "702034015 6007275 9777625", "output": "1 000000001" }, { "input": "218556 828183 7799410", "output": "1 000000001" }, { "input": "1167900 2709798 6800151", "output": "1 000000001" }, { "input": "7004769 3114686 4659684", "output": "1 000000002" }, { "input": "1000000000 1000000000 10000000", "output": "2" }, { "input": "3631 1628 367377", "output": "1 000000009" }, { "input": "3966 5002 273075", "output": "1 000000008" }, { "input": "2388 2896 73888", "output": "1 000000016" }, { "input": "0 0 1", "output": "2" }, { "input": "1 0 1", "output": "2" }, { "input": "0 1 1", "output": "2" }, { "input": "1 1 1", "output": "2" }, { "input": "1000000000 0 1", "output": "2" }, { "input": "0 1000000000 1", "output": "2" }, { "input": "1000000000 1000000000 1", "output": "2" }, { "input": "1000000000 0 10000000", "output": "2" }, { "input": "0 1000000000 10000000", "output": "2" }, { "input": "0 0 10000000", "output": "2" }, { "input": "0 999999999 10000000", "output": "2" }, { "input": "999999999 0 10000000", "output": "2" }, { "input": "999999999 999999999 10000000", "output": "2" }, { "input": "999999999 1000000000 10000000", "output": "2" }, { "input": "1000000000 999999999 10000000", "output": "2" }, { "input": "1000000000 10000 10000000", "output": "2" }, { "input": "1 1 1337", "output": "1 000000001" }, { "input": "576694 1234562 1234567", "output": "2" }, { "input": "12350 12000 12345", "output": "1 000000011" }, { "input": "576695 1234562 1234567", "output": "1 000576695" }, { "input": "0 0 11", "output": "2" }, { "input": "999999999 999999999 9009009", "output": "2" }, { "input": "1 0 7", "output": "1 000000001" }, { "input": "1 1 7", "output": "2" }, { "input": "1000000000 9999991 10000000", "output": "2" }, { "input": "9902593 9902584 9902593", "output": "1 002490619" }, { "input": "10000000 9999977 9999979", "output": "1 009909503" }, { "input": "1000000000 1000000000 9999999", "output": "2" }, { "input": "11 9 11", "output": "1 000000010" }, { "input": "0 7 13", "output": "2" }, { "input": "1 0 3", "output": "1 000000001" }, { "input": "100 2 3", "output": "2" }, { "input": "2 7 13", "output": "2" }, { "input": "1 0 9", "output": "1 000000001" }, { "input": "1000000000 9999995 10000000", "output": "2" }, { "input": "1000000000 25 30", "output": "2" }, { "input": "243 1001 1003", "output": "2" }, { "input": "9 9 11", "output": "2" }, { "input": "0 1 11", "output": "2" }, { "input": "4 4 7", "output": "2" }, { "input": "1000000000 1 10", "output": "2" }, { "input": "1 0 11", "output": "1 000000001" }, { "input": "0 0 11", "output": "2" }, { "input": "0 0 3", "output": "2" }, { "input": "10 12000 12345", "output": "2" }, { "input": "1000000000 0 2", "output": "2" }, { "input": "0 1 3", "output": "2" }, { "input": "3 1 7", "output": "1 000000002" }, { "input": "1000000000 2 1000000", "output": "2" }, { "input": "23 0 23", "output": "1 000000001" }, { "input": "123456789 1234561 1234567", "output": "1 000549636" }, { "input": "11 10 13", "output": "1 000000011" }, { "input": "138 11711 11829", "output": "2" }, { "input": "1000000000 100050 1000001", "output": "1 000000101" } ]
1,635,156,866
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
a,b,m=map(int,input().split()) k=s=(10**9)%m i=0 while k and i<a: i+=1 if k<m-b:exit(print(1, str(i).zfill(9))) k+=s if k>=m:k-=m print(2)
Title: Very Interesting Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and representing a number that does not exceed *b*. Here *a* and *b* are some given constants, *s*1 and *s*2 are chosen by the players. The strings are allowed to contain leading zeroes. If a number obtained by the concatenation (joining together) of strings *s*1 and *s*2 is divisible by *mod*, then the second player wins. Otherwise the first player wins. You are given numbers *a*, *b*, *mod*. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move. Input Specification: The first line contains three integers *a*, *b*, *mod* (0<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*mod*<=≤<=107). Output Specification: If the first player wins, print "1" and the lexicographically minimum string *s*1 he has to write to win. If the second player wins, print the single number "2". Demo Input: ['1 10 7\n', '4 0 9\n'] Demo Output: ['2\n', '1 000000001\n'] Note: The lexical comparison of strings is performed by the &lt; operator in modern programming languages. String *x* is lexicographically less than string *y* if exists such *i* (1 ≤ *i* ≤ 9), that *x*<sub class="lower-index">*i*</sub> &lt; *y*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* &lt; *i*) *x*<sub class="lower-index">*j*</sub> = *y*<sub class="lower-index">*j*</sub>. These strings always have length 9.
```python a,b,m=map(int,input().split()) k=s=(10**9)%m i=0 while k and i<a: i+=1 if k<m-b:exit(print(1, str(i).zfill(9))) k+=s if k>=m:k-=m print(2) ```
-1
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,698,798,831
2,147,483,647
Python 3
OK
TESTS
34
92
0
def main(): s = input() cnt = 0 for i in s: if i == '4' or i == '7': cnt += 1 if cnt == 4 or cnt == 7: print('YES') else: print('NO') if __name__ == '__main__': main()
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python def main(): s = input() cnt = 0 for i in s: if i == '4' or i == '7': cnt += 1 if cnt == 4 or cnt == 7: print('YES') else: print('NO') if __name__ == '__main__': main() ```
3.977
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,609,125,678
2,147,483,647
Python 3
OK
TESTS
21
108
0
d1,d2,d3=map(int,input().split()) print(min(d1+d2+d3,d1*2+d2*2,d1*2+d3*2,d2*2+d3*2))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python d1,d2,d3=map(int,input().split()) print(min(d1+d2+d3,d1*2+d2*2,d1*2+d3*2,d2*2+d3*2)) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,548,682,426
2,147,483,647
Python 3
OK
TESTS
43
218
0
'''input 105 106 ''' a = input() b = input() c = int(a) + int(b) a1 = int("".join(a.split('0'))) b1 = int("".join(b.split('0'))) c1 = int("".join(str(c).split('0'))) if c1 == a1 + b1: print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python '''input 105 106 ''' a = input() b = input() c = int(a) + int(b) a1 = int("".join(a.split('0'))) b1 = int("".join(b.split('0'))) c1 = int("".join(str(c).split('0'))) if c1 == a1 + b1: print("YES") else: print("NO") ```
3.9455
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
1,674,709,367
2,147,483,647
Python 3
OK
TESTS
60
1,965
20,070,400
l1, l2 = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ')] b = [int(x) for x in input().split(' ')] a = sorted(a) counts = [] for el in b: left = -1 right = len(a) while right-left > 1: middle = left + (right - left) // 2 if a[middle] > el: right = middle else: left = middle counts.append(str(left+1)) print(' '.join(counts))
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). Output Specification: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Demo Input: ['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n'] Demo Output: ['3 2 1 4\n', '4 2 4 2 5\n'] Note: none
```python l1, l2 = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ')] b = [int(x) for x in input().split(' ')] a = sorted(a) counts = [] for el in b: left = -1 right = len(a) while right-left > 1: middle = left + (right - left) // 2 if a[middle] > el: right = middle else: left = middle counts.append(str(left+1)) print(' '.join(counts)) ```
3
493
B
Vasya and Wrestling
PROGRAMMING
1,400
[ "implementation" ]
null
null
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points. The techniques are given in chronological order.
If the first wrestler wins, print string "first", otherwise print "second"
[ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n" ]
[ "second\n", "first\n", "second\n" ]
Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |*y*| and *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>, ... ,  *x*<sub class="lower-index">|*y*|</sub>  =  *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*  &lt;  |*x*|, *r*  &lt;  |*y*|), that *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>,  ... ,  *x*<sub class="lower-index">*r*</sub>  =  *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*  +  1</sub>  &gt;  *y*<sub class="lower-index">*r*  +  1</sub>. We use notation |*a*| to denote length of sequence *a*.
1,000
[ { "input": "5\n1\n2\n-3\n-4\n3", "output": "second" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "2\n4\n-4", "output": "second" }, { "input": "7\n1\n2\n-3\n4\n5\n-6\n7", "output": "first" }, { "input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14", "output": "second" }, { "input": "4\n16\n12\n19\n-98", "output": "second" }, { "input": "5\n-6\n-1\n-1\n5\n3", "output": "second" }, { "input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1", "output": "first" }, { "input": "1\n-534365", "output": "second" }, { "input": "1\n10253033", "output": "first" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8", "output": "second" }, { "input": "2\n1\n-1", "output": "second" }, { "input": "5\n1\n2\n3\n4\n5", "output": "first" }, { "input": "5\n-1\n-2\n-3\n-4\n-5", "output": "second" }, { "input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1", "output": "first" }, { "input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2", "output": "first" }, { "input": "6\n-1\n-2\n-3\n1\n2\n3", "output": "first" }, { "input": "3\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "4\n1000000000\n1000000000\n1000000000\n-1000000000", "output": "first" }, { "input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000", "output": "second" }, { "input": "4\n1\n-1000000000\n-1000000000\n-1000000000", "output": "second" }, { "input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000", "output": "first" }, { "input": "4\n-1\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "2\n-4\n4", "output": "first" }, { "input": "3\n-12\n3\n9", "output": "second" }, { "input": "3\n9\n1\n-10", "output": "second" }, { "input": "3\n1\n2\n-3", "output": "second" }, { "input": "4\n55\n5\n-5\n-55", "output": "first" }, { "input": "4\n5\n-1\n1\n-5", "output": "first" }, { "input": "2\n-5\n6", "output": "first" }, { "input": "4\n5\n-4\n3\n-40", "output": "second" }, { "input": "4\n1000000000\n1000000000\n1000000000\n-5", "output": "first" }, { "input": "6\n3\n2\n1\n-3\n-1\n-2", "output": "first" }, { "input": "5\n4\n1\n1\n-3\n-3", "output": "first" }, { "input": "5\n208\n-52\n-52\n-52\n-52", "output": "first" }, { "input": "3\n-100\n-200\n300", "output": "first" }, { "input": "3\n400\n-200\n-200", "output": "first" }, { "input": "3\n208\n-207\n-1", "output": "first" }, { "input": "3\n98888887\n98888888\n-197777775", "output": "second" } ]
1,495,443,263
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = input() aList = [] count =0 fcount =0 scount =0 first = 0 second = 0 while( count < n): inp=input() aList.append(inp) if(0<inp): first += abs(inp);fcount +=1 if(0>inp): second += abs(inp);scount +=1 count+=1 print "first", first print "second",second print aList[-1] if (first > second): print "first" elif(first < second): print "second" elif (first == second): if (fcount < scount): print "first" elif (fcount > scount): print "second" elif (fcount == scount): if(aList[-1]>0): print "first" else: print "second"
Title: Vasya and Wrestling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. Input Specification: The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points. The techniques are given in chronological order. Output Specification: If the first wrestler wins, print string "first", otherwise print "second" Demo Input: ['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n'] Demo Output: ['second\n', 'first\n', 'second\n'] Note: Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |*y*| and *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>, ... ,  *x*<sub class="lower-index">|*y*|</sub>  =  *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*  &lt;  |*x*|, *r*  &lt;  |*y*|), that *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>,  ... ,  *x*<sub class="lower-index">*r*</sub>  =  *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*  +  1</sub>  &gt;  *y*<sub class="lower-index">*r*  +  1</sub>. We use notation |*a*| to denote length of sequence *a*.
```python n = input() aList = [] count =0 fcount =0 scount =0 first = 0 second = 0 while( count < n): inp=input() aList.append(inp) if(0<inp): first += abs(inp);fcount +=1 if(0>inp): second += abs(inp);scount +=1 count+=1 print "first", first print "second",second print aList[-1] if (first > second): print "first" elif(first < second): print "second" elif (first == second): if (fcount < scount): print "first" elif (fcount > scount): print "second" elif (fcount == scount): if(aList[-1]>0): print "first" else: print "second" ```
-1
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,666,953,651
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
0
s = input() a = s.count('A') q = s.count('Q') print(a * (q - 1))
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python s = input() a = s.count('A') q = s.count('Q') print(a * (q - 1)) ```
0
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" }, { "input": "8", "output": "1641" }, { "input": "9", "output": "4920" }, { "input": "10", "output": "14763" }, { "input": "15", "output": "3587226" }, { "input": "30", "output": "782663359" }, { "input": "10000000", "output": "192336614" }, { "input": "100", "output": "721510432" }, { "input": "300", "output": "327873818" }, { "input": "900", "output": "295068084" }, { "input": "1500", "output": "451187545" }, { "input": "3000", "output": "645417275" }, { "input": "5000", "output": "755610910" }, { "input": "10000", "output": "723907367" }, { "input": "50000", "output": "969527595" }, { "input": "90000", "output": "548978368" }, { "input": "99999", "output": "909741855" }, { "input": "100000", "output": "729225554" }, { "input": "300000", "output": "93822635" }, { "input": "800000", "output": "178940616" }, { "input": "1000000", "output": "266233856" }, { "input": "4000000", "output": "882155933" }, { "input": "9000000", "output": "295060537" }, { "input": "9999999", "output": "730778875" }, { "input": "1000000", "output": "266233856" }, { "input": "9999999", "output": "730778875" }, { "input": "10000000", "output": "192336614" }, { "input": "9999998", "output": "576926295" }, { "input": "30", "output": "782663359" }, { "input": "31", "output": "347990060" } ]
1,658,030,501
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
92
0
n = int(input()) dp = [[0,0,0,0] for i in range(n+1)] dp[0][0]=0 dp[0][1]=0 dp[0][2]=0 dp[0][3]=1 for i in range(1,n+1): dp[i][0]+=dp[i-1][1]+dp[i-1][2]+dp[i-1][3] dp[i][1]+=dp[i-1][0]+dp[i-1][2]+dp[i-1][3] dp[i][2]+=dp[i-1][1]+dp[i-1][0]+dp[i-1][3] dp[i][3]+=dp[i-1][1]+dp[i-1][2]+dp[i-1][0] print(dp[-1][3])
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. Output Specification: Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). Demo Input: ['2\n', '4\n'] Demo Output: ['3\n', '21\n'] Note: The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
```python n = int(input()) dp = [[0,0,0,0] for i in range(n+1)] dp[0][0]=0 dp[0][1]=0 dp[0][2]=0 dp[0][3]=1 for i in range(1,n+1): dp[i][0]+=dp[i-1][1]+dp[i-1][2]+dp[i-1][3] dp[i][1]+=dp[i-1][0]+dp[i-1][2]+dp[i-1][3] dp[i][2]+=dp[i-1][1]+dp[i-1][0]+dp[i-1][3] dp[i][3]+=dp[i-1][1]+dp[i-1][2]+dp[i-1][0] print(dp[-1][3]) ```
0
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,667,547,889
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
62
0
nums1, nums2 = map(int, input().split()) def GCD(a, b): if b == 0: return a return GCD(b, b%a) print(GCD(max(nums1, nums2), min(nums1, nums2)))
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 nums1, nums2 = map(int, input().split()) def GCD(a, b): if b == 0: return a return GCD(b, b%a) print(GCD(max(nums1, nums2), min(nums1, nums2))) ```
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,630,433,961
2,147,483,647
Python 3
OK
TESTS
30
124
6,758,400
str = input() upper = 0 lower = 0 for i in range(len(str)): if(str[i].isupper()): upper += 1 else: lower += 1 if(upper>lower): print(str.upper()) elif(lower>upper): print(str.lower()) else: print(str.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python str = input() upper = 0 lower = 0 for i in range(len(str)): if(str[i].isupper()): upper += 1 else: lower += 1 if(upper>lower): print(str.upper()) elif(lower>upper): print(str.lower()) else: print(str.lower()) ```
3.956411
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve?
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62", "output": "100" }, { "input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98", "output": "98" }, { "input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2", "output": "39" }, { "input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16", "output": "99" }, { "input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1", "output": "1" }, { "input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "1 5\n4", "output": "1" }, { "input": "3 2\n1 4 1", "output": "2" }, { "input": "1 2\n100", "output": "0" }, { "input": "7 4\n4 2 3 4 4 2 3", "output": "7" }, { "input": "1 2\n1", "output": "1" }, { "input": "1 2\n15", "output": "0" }, { "input": "2 1\n1 1", "output": "2" }, { "input": "5 3\n3 4 3 2 1", "output": "4" }, { "input": "1 1\n2", "output": "0" }, { "input": "1 5\n1", "output": "1" }, { "input": "6 6\n7 1 1 1 1 1", "output": "5" }, { "input": "5 5\n6 5 5 5 5", "output": "4" }, { "input": "1 4\n2", "output": "1" }, { "input": "9 4\n1 2 1 2 4 2 1 2 1", "output": "9" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n5", "output": "1" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4", "output": "71" }, { "input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90", "output": "63" }, { "input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8", "output": "61" }, { "input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22", "output": "72" }, { "input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2", "output": "52" }, { "input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90", "output": "60" }, { "input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10", "output": "56" }, { "input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90", "output": "61" }, { "input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24", "output": "99" }, { "input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50", "output": "99" }, { "input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48", "output": "99" }, { "input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57", "output": "99" }, { "input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93", "output": "99" }, { "input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33", "output": "3" }, { "input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51", "output": "3" }, { "input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49", "output": "6" }, { "input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8", "output": "66" }, { "input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95", "output": "0" }, { "input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66", "output": "0" }, { "input": "2 8\n8 8", "output": "2" }, { "input": "1 6\n3", "output": "1" }, { "input": "1 5\n5", "output": "1" } ]
1,679,060,171
2,147,483,647
PyPy 3-64
OK
TESTS
48
77
0
n,k=map(int,input().split()) arr=list(map(int,input().split())) l=0 r=n-1 prob=0 while(l<=r): if((arr[l]==arr[r]) and (arr[l]<=k)): l+=1 prob+=1 elif((arr[l]>arr[r]) and (arr[r]<=k)): r-=1 prob+=1 elif((arr[l]<arr[r]) and (arr[l]<=k)): l+=1 prob+=1 else: break print(prob)
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve? Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. Output Specification: Print one integer — the maximum number of problems Mishka can solve. Demo Input: ['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n'] Demo Output: ['5\n', '0\n', '5\n'] Note: In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
```python n,k=map(int,input().split()) arr=list(map(int,input().split())) l=0 r=n-1 prob=0 while(l<=r): if((arr[l]==arr[r]) and (arr[l]<=k)): l+=1 prob+=1 elif((arr[l]>arr[r]) and (arr[r]<=k)): r-=1 prob+=1 elif((arr[l]<arr[r]) and (arr[l]<=k)): l+=1 prob+=1 else: break print(prob) ```
3
887
B
Cubes for Masha
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Absent-minded Masha got set of *n* cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*. To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number. The number can't contain leading zeros. It's not required to use all cubes to build a number. Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday. Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube.
Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1.
[ "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n" ]
[ "87", "98" ]
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
1,000
[ { "input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7", "output": "87" }, { "input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9", "output": "98" }, { "input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5", "output": "5" }, { "input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8", "output": "3" }, { "input": "1\n5 2 2 5 6 7", "output": "0" }, { "input": "1\n7 6 5 8 9 0", "output": "0" }, { "input": "1\n2 5 9 6 7 9", "output": "0" }, { "input": "1\n6 3 1 9 4 9", "output": "1" }, { "input": "1\n1 9 8 3 7 8", "output": "1" }, { "input": "2\n1 7 2 0 4 3\n5 2 3 6 1 0", "output": "7" }, { "input": "2\n6 0 1 7 2 9\n1 3 4 6 7 0", "output": "4" }, { "input": "2\n8 6 4 1 2 0\n7 8 5 3 2 1", "output": "8" }, { "input": "2\n0 8 6 2 1 3\n5 2 7 1 0 9", "output": "3" }, { "input": "2\n0 9 5 7 6 2\n8 6 2 7 1 4", "output": "2" }, { "input": "3\n5 0 7 6 2 1\n2 7 4 6 1 9\n0 2 6 1 7 5", "output": "2" }, { "input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 2", "output": "6" }, { "input": "3\n5 6 2 9 3 5\n5 4 1 5 9 8\n4 4 2 0 3 5", "output": "6" }, { "input": "3\n0 1 9 1 0 8\n9 9 3 5 6 2\n9 3 9 9 7 3", "output": "3" }, { "input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 1", "output": "5" }, { "input": "1\n4 6 9 8 2 7", "output": "0" }, { "input": "1\n5 3 8 0 2 6", "output": "0" }, { "input": "1\n7 9 5 0 4 6", "output": "0" }, { "input": "1\n4 0 9 6 3 1", "output": "1" }, { "input": "1\n7 9 2 5 0 4", "output": "0" }, { "input": "1\n0 7 6 3 2 4", "output": "0" }, { "input": "1\n9 8 1 6 5 7", "output": "1" }, { "input": "1\n7 3 6 9 8 1", "output": "1" }, { "input": "1\n3 9 1 7 4 5", "output": "1" }, { "input": "1\n8 6 0 9 4 2", "output": "0" }, { "input": "1\n8 2 7 4 1 0", "output": "2" }, { "input": "1\n8 3 5 4 2 9", "output": "0" }, { "input": "1\n0 8 7 1 3 2", "output": "3" }, { "input": "1\n6 2 8 5 1 3", "output": "3" }, { "input": "1\n6 0 7 5 4 8", "output": "0" }, { "input": "1\n6 2 8 4 5 1", "output": "2" }, { "input": "1\n4 3 8 9 2 3", "output": "0" }, { "input": "1\n8 1 9 2 9 7", "output": "2" }, { "input": "1\n3 7 7 6 4 2", "output": "0" }, { "input": "1\n1 4 5 7 0 5", "output": "1" }, { "input": "2\n6 6 4 7 9 0\n2 1 2 8 6 4", "output": "2" }, { "input": "2\n5 3 2 9 8 2\n0 7 4 8 1 8", "output": "5" }, { "input": "2\n5 7 4 2 1 9\n2 2 7 1 1 8", "output": "2" }, { "input": "2\n9 3 3 6 7 2\n6 2 9 1 5 9", "output": "3" }, { "input": "2\n2 0 5 7 0 8\n4 5 1 5 4 9", "output": "2" }, { "input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7", "output": "3" }, { "input": "2\n4 3 8 6 0 1\n4 7 1 8 9 0", "output": "1" }, { "input": "2\n0 2 9 1 8 5\n0 7 4 3 2 5", "output": "5" }, { "input": "2\n1 7 6 9 2 5\n1 6 7 0 9 2", "output": "2" }, { "input": "2\n0 2 9 8 1 7\n6 7 4 3 2 5", "output": "9" }, { "input": "2\n3 6 8 9 5 0\n6 7 0 8 2 3", "output": "0" }, { "input": "2\n5 1 2 3 0 8\n3 6 7 4 9 2", "output": "9" }, { "input": "2\n7 8 6 1 4 5\n8 6 4 3 2 5", "output": "8" }, { "input": "2\n2 3 5 1 9 6\n1 6 8 7 3 9", "output": "3" }, { "input": "2\n1 7 8 6 0 9\n3 2 1 7 4 9", "output": "4" }, { "input": "2\n2 4 0 3 7 6\n3 2 8 7 1 5", "output": "8" }, { "input": "2\n6 5 2 7 1 3\n3 7 8 1 0 9", "output": "3" }, { "input": "2\n5 8 4 7 1 2\n0 8 6 2 4 9", "output": "2" }, { "input": "2\n8 0 6 5 1 4\n7 1 0 8 3 4", "output": "1" }, { "input": "2\n2 3 9 1 6 7\n2 5 4 3 0 6", "output": "7" }, { "input": "3\n9 4 3 0 2 6\n7 0 5 3 3 9\n1 0 7 4 6 7", "output": "7" }, { "input": "3\n3 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9", "output": "9" }, { "input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 2 1 1 9 1", "output": "7" }, { "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9", "output": "32" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7", "output": "2" }, { "input": "3\n4 4 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9", "output": "1" }, { "input": "3\n9 4 3 3 9 3\n1 0 3 4 5 3\n2 9 6 2 4 1", "output": "6" }, { "input": "3\n3 8 3 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4", "output": "8" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 7 2 2", "output": "5" }, { "input": "3\n8 1 8 2 7 1\n9 1 9 9 4 7\n0 0 9 0 4 0", "output": "2" }, { "input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 3 2 5 7", "output": "0" }, { "input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7", "output": "10" }, { "input": "3\n9 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3", "output": "21" }, { "input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 5", "output": "65" }, { "input": "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2", "output": "4" }, { "input": "3\n2 7 3 6 4 5\n0 2 1 9 4 8\n8 6 9 5 4 0", "output": "10" }, { "input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 2", "output": "4" }, { "input": "3\n5 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3", "output": "21" }, { "input": "3\n7 2 1 3 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0", "output": "21" }, { "input": "3\n8 6 0 5 4 9\n1 8 5 3 9 7\n7 4 5 1 6 8", "output": "1" }, { "input": "1\n0 1 2 3 4 5", "output": "5" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 8", "output": "9" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 1 2", "output": "29" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 7 8", "output": "98" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1", "output": "19" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 6 6", "output": "9" }, { "input": "2\n0 1 2 3 4 5\n4 5 6 7 8 9", "output": "9" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7", "output": "9" }, { "input": "2\n0 1 2 3 4 5\n9 8 7 6 5 4", "output": "9" }, { "input": "3\n2 3 4 5 6 7\n3 4 5 6 7 8\n9 1 2 3 4 5", "output": "9" }, { "input": "3\n1 1 2 3 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8", "output": "10" }, { "input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0", "output": "10" }, { "input": "3\n0 1 2 2 4 5\n6 7 8 9 0 1\n3 3 4 5 6 7", "output": "21" }, { "input": "3\n2 0 1 3 4 5\n6 7 8 9 1 1\n3 4 5 6 6 7", "output": "19" }, { "input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4", "output": "10" }, { "input": "2\n0 1 2 3 4 5\n6 6 6 7 8 9", "output": "9" }, { "input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 5 7 0", "output": "19" } ]
1,509,950,959
2,147,483,647
Python 3
OK
TESTS
96
62
0
n=int(input()) L=[] for i in range(n): L.append(list(map(int,input().split()))) for i in range(1,100): t=str(i) b=False if len(t)==1: for j in range(len(L)): if i in L[j]: b=True break if b==False: print(i-1) break else: u=i%10 d=i//10 pos=[] for j in range(len(L)): if u in L[j]: pos.append(j) if len(pos)==0: print(i-1) break b=False for o in pos: for k in range(len(L)): if k!=o: if d in L[k]: b=True break if b: break if not b: print(i-1) break
Title: Cubes for Masha Time Limit: None seconds Memory Limit: None megabytes Problem Description: Absent-minded Masha got set of *n* cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*. To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number. The number can't contain leading zeros. It's not required to use all cubes to build a number. Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations. Input Specification: In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday. Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. Output Specification: Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. Demo Input: ['3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n', '3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n'] Demo Output: ['87', '98'] Note: In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
```python n=int(input()) L=[] for i in range(n): L.append(list(map(int,input().split()))) for i in range(1,100): t=str(i) b=False if len(t)==1: for j in range(len(L)): if i in L[j]: b=True break if b==False: print(i-1) break else: u=i%10 d=i//10 pos=[] for j in range(len(L)): if u in L[j]: pos.append(j) if len(pos)==0: print(i-1) break b=False for o in pos: for k in range(len(L)): if k!=o: if d in L[k]: b=True break if b: break if not b: print(i-1) break ```
3
574
B
Bear and Three Musketeers
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs", "hashing" ]
null
null
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once.
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
[ "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n", "7 4\n2 1\n3 6\n5 1\n1 7\n" ]
[ "2\n", "-1\n" ]
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
1,000
[ { "input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "output": "2" }, { "input": "7 4\n2 1\n3 6\n5 1\n1 7", "output": "-1" }, { "input": "5 0", "output": "-1" }, { "input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "output": "5" }, { "input": "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11", "output": "4" }, { "input": "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5", "output": "27" }, { "input": "3 0", "output": "-1" }, { "input": "3 2\n2 3\n2 1", "output": "-1" }, { "input": "3 3\n3 1\n3 2\n2 1", "output": "0" }, { "input": "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2", "output": "3" }, { "input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6", "output": "2" }, { "input": "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1", "output": "3" }, { "input": "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4", "output": "7" }, { "input": "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204", "output": "6" }, { "input": "4000 0", "output": "-1" } ]
1,513,941,582
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
39
2,000
6,144,000
n, m = [int(x) for x in input().split()] W = [0 for i in range(n+1)] N = [list() for i in range(n+1)] R = [None for i in range(m)] for i in range(m): a, b = [int(x) for x in input().split()] N[a].append(b) N[b].append(a) W[a] += 1 W[b] += 1 R[i] = [a, b] rep = 1000000 found = False for i in range(m): a, b = R[i] for n in N[a]: if n in N[b]: t = W[a] + W[b] + W[n] - 6 if t < rep: rep = t found = True if found: print(rep) else: print(-1)
Title: Bear and Three Musketeers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. Input Specification: The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. Output Specification: If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). Demo Input: ['5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n', '7 4\n2 1\n3 6\n5 1\n1 7\n'] Demo Output: ['2\n', '-1\n'] Note: In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
```python n, m = [int(x) for x in input().split()] W = [0 for i in range(n+1)] N = [list() for i in range(n+1)] R = [None for i in range(m)] for i in range(m): a, b = [int(x) for x in input().split()] N[a].append(b) N[b].append(a) W[a] += 1 W[b] += 1 R[i] = [a, b] rep = 1000000 found = False for i in range(m): a, b = R[i] for n in N[a]: if n in N[b]: t = W[a] + W[b] + W[n] - 6 if t < rep: rep = t found = True if found: print(rep) else: print(-1) ```
0
820
A
Mister B and Book Reading
PROGRAMMING
900
[ "implementation" ]
null
null
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day. Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time. Help Mister B to calculate how many days he needed to finish the book.
First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=&lt;<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.
Print one integer — the number of days Mister B needed to finish the book.
[ "5 5 10 5 4\n", "12 4 12 4 1\n", "15 1 100 0 0\n" ]
[ "1\n", "3\n", "15\n" ]
In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
500
[ { "input": "5 5 10 5 4", "output": "1" }, { "input": "12 4 12 4 1", "output": "3" }, { "input": "15 1 100 0 0", "output": "15" }, { "input": "1 1 1 0 0", "output": "1" }, { "input": "1000 999 1000 1000 998", "output": "2" }, { "input": "1000 2 2 5 1", "output": "999" }, { "input": "1000 1 1 1000 0", "output": "1000" }, { "input": "737 41 74 12 11", "output": "13" }, { "input": "1000 1000 1000 0 999", "output": "1" }, { "input": "765 12 105 5 7", "output": "17" }, { "input": "15 2 2 1000 0", "output": "8" }, { "input": "1000 1 1000 1000 0", "output": "2" }, { "input": "20 3 7 1 2", "output": "6" }, { "input": "1000 500 500 1000 499", "output": "501" }, { "input": "1 1000 1000 1000 0", "output": "1" }, { "input": "1000 2 1000 56 0", "output": "7" }, { "input": "1000 2 1000 802 0", "output": "3" }, { "input": "16 1 8 2 0", "output": "4" }, { "input": "20 6 10 2 2", "output": "3" }, { "input": "8 2 12 4 1", "output": "3" }, { "input": "8 6 13 2 5", "output": "2" }, { "input": "70 4 20 87 0", "output": "5" }, { "input": "97 8 13 234 5", "output": "13" }, { "input": "16 4 23 8 3", "output": "3" }, { "input": "65 7 22 7 4", "output": "5" }, { "input": "93 10 18 11 7", "output": "9" }, { "input": "86 13 19 15 9", "output": "9" }, { "input": "333 17 50 10 16", "output": "12" }, { "input": "881 16 55 10 12", "output": "23" }, { "input": "528 11 84 3 9", "output": "19" }, { "input": "896 2 184 8 1", "output": "16" }, { "input": "236 10 930 9 8", "output": "8" }, { "input": "784 1 550 14 0", "output": "12" }, { "input": "506 1 10 4 0", "output": "53" }, { "input": "460 1 3 2 0", "output": "154" }, { "input": "701 1 3 1 0", "output": "235" }, { "input": "100 49 50 1000 2", "output": "3" }, { "input": "100 1 100 100 0", "output": "2" }, { "input": "12 1 4 2 0", "output": "4" }, { "input": "22 10 12 0 0", "output": "3" }, { "input": "20 10 15 1 4", "output": "3" }, { "input": "1000 5 10 1 4", "output": "169" }, { "input": "1000 1 1000 1 0", "output": "45" }, { "input": "4 1 2 2 0", "output": "3" }, { "input": "1 5 5 1 1", "output": "1" }, { "input": "19 10 11 0 2", "output": "3" }, { "input": "1 2 3 0 0", "output": "1" }, { "input": "10 1 4 10 0", "output": "4" }, { "input": "20 3 100 1 1", "output": "5" }, { "input": "1000 5 9 5 0", "output": "112" }, { "input": "1 11 12 0 10", "output": "1" }, { "input": "1 1 1 1 0", "output": "1" }, { "input": "1000 1 20 1 0", "output": "60" }, { "input": "9 1 4 2 0", "output": "4" }, { "input": "129 2 3 4 0", "output": "44" }, { "input": "4 2 2 0 1", "output": "3" }, { "input": "1000 1 10 100 0", "output": "101" }, { "input": "100 1 100 1 0", "output": "14" }, { "input": "8 3 4 2 0", "output": "3" }, { "input": "20 1 6 4 0", "output": "5" }, { "input": "8 2 4 2 0", "output": "3" }, { "input": "11 5 6 7 2", "output": "3" }, { "input": "100 120 130 120 0", "output": "1" }, { "input": "7 1 4 1 0", "output": "4" }, { "input": "5 3 10 0 2", "output": "3" }, { "input": "5 2 2 0 0", "output": "3" }, { "input": "1000 10 1000 10 0", "output": "14" }, { "input": "25 3 50 4 2", "output": "4" }, { "input": "9 10 10 10 9", "output": "1" }, { "input": "17 10 12 6 5", "output": "2" }, { "input": "15 5 10 3 0", "output": "3" }, { "input": "8 3 5 1 0", "output": "3" }, { "input": "19 1 12 5 0", "output": "4" }, { "input": "1000 10 1000 1 0", "output": "37" }, { "input": "100 1 2 1000 0", "output": "51" }, { "input": "20 10 11 1000 9", "output": "6" }, { "input": "16 2 100 1 1", "output": "5" }, { "input": "18 10 13 2 5", "output": "3" }, { "input": "12 3 5 3 1", "output": "4" }, { "input": "17 3 11 2 0", "output": "4" }, { "input": "4 2 100 1 1", "output": "2" }, { "input": "7 4 5 2 3", "output": "3" }, { "input": "100 1 2 2 0", "output": "51" }, { "input": "50 4 5 5 0", "output": "11" }, { "input": "1 2 2 0 1", "output": "1" }, { "input": "1000 2 3 10 1", "output": "500" }, { "input": "500 10 500 1000 0", "output": "2" }, { "input": "1000 4 12 1 0", "output": "87" }, { "input": "18 10 13 1 5", "output": "3" }, { "input": "7 3 6 2 2", "output": "3" }, { "input": "15 5 100 1 2", "output": "4" }, { "input": "100 1 10 1 0", "output": "15" }, { "input": "8 2 7 5 1", "output": "2" }, { "input": "11 2 4 1 1", "output": "5" }, { "input": "1000 500 900 100 300", "output": "3" }, { "input": "7 1 2 5 0", "output": "4" }, { "input": "7 3 5 3 2", "output": "3" }, { "input": "7 3 10 2 1", "output": "2" }, { "input": "1000 501 510 1 499", "output": "50" }, { "input": "1000 1 1000 2 0", "output": "32" }, { "input": "1 5 5 0 0", "output": "1" }, { "input": "18 10 15 1 5", "output": "3" }, { "input": "100 4 1000 1 2", "output": "13" }, { "input": "20 2 40 1 1", "output": "6" }, { "input": "1 11 1000 100 1", "output": "1" }, { "input": "6 4 4 1 2", "output": "2" }, { "input": "8 3 5 3 1", "output": "3" }, { "input": "10 5 7 1 2", "output": "3" }, { "input": "400 100 198 1 99", "output": "25" }, { "input": "3 1 2 5 0", "output": "2" } ]
1,527,021,595
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
77
0
c,v0,v1,a,l=map(int,input().split()) i=1 count=v0 while True: if v0+i*a-l<=v1 and count<c: save=v0+i*a-l count+=save i+=1 elif v0+i*a-l>v1 and count<c: count+=savee if count>=c: break print(i)
Title: Mister B and Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day. Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time. Help Mister B to calculate how many days he needed to finish the book. Input Specification: First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=&lt;<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading. Output Specification: Print one integer — the number of days Mister B needed to finish the book. Demo Input: ['5 5 10 5 4\n', '12 4 12 4 1\n', '15 1 100 0 0\n'] Demo Output: ['1\n', '3\n', '15\n'] Note: In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
```python c,v0,v1,a,l=map(int,input().split()) i=1 count=v0 while True: if v0+i*a-l<=v1 and count<c: save=v0+i*a-l count+=save i+=1 elif v0+i*a-l>v1 and count<c: count+=savee if count>=c: break print(i) ```
-1
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,597,904,510
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
140
0
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a_max=max(a) a.remove(a_max) a_mx=max(a) b_mx=max(b) print(a_mx*b_mx)
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a_max=max(a) a.remove(a_max) a_mx=max(a) b_mx=max(b) print(a_mx*b_mx) ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,623,642,074
2,147,483,647
Python 3
OK
TESTS
21
62
0
a = list(map(int,input().split())) a.sort() print(min(sum(a),(a[0]+a[1])*2))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python a = list(map(int,input().split())) a.sort() print(min(sum(a),(a[0]+a[1])*2)) ```
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": ".g.g.d.v.q" }, { "input": "pumesz", "output": ".p.m.s.z" }, { "input": "g", "output": ".g" }, { "input": "zjuotps", "output": ".z.j.t.p.s" }, { "input": "jzbwuehe", "output": ".j.z.b.w.h" }, { "input": "tnkgwuugu", "output": ".t.n.k.g.w.g" }, { "input": "kincenvizh", "output": ".k.n.c.n.v.z.h" }, { "input": "xattxjenual", "output": ".x.t.t.x.j.n.l" }, { "input": "ktajqhpqsvhw", "output": ".k.t.j.q.h.p.q.s.v.h.w" }, { "input": "xnhcigytnqcmy", "output": ".x.n.h.c.g.t.n.q.c.m" }, { "input": "jfmtbejyilxcec", "output": ".j.f.m.t.b.j.l.x.c.c" }, { "input": "D", "output": ".d" }, { "input": "ab", "output": ".b" }, { "input": "Ab", "output": ".b" }, { "input": "aB", "output": ".b" }, { "input": "AB", "output": ".b" }, { "input": "ba", "output": ".b" }, { "input": "bA", "output": ".b" }, { "input": "Ba", "output": ".b" }, { "input": "BA", "output": ".b" }, { "input": "aab", "output": ".b" }, { "input": "baa", "output": ".b" }, { "input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM", "output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m" }, { "input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN", "output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n" }, { "input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ", "output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j" }, { "input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea", "output": ".w.z.t.c.v.v.v.v.z.v" }, { "input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl", "output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l" }, { "input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg", "output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g" }, { "input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ", "output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q" }, { "input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg", "output": ".l.t.g.m.g" }, { "input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy", "output": ".k.z.d.x.f" }, { "input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ", "output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q" }, { "input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY", "output": ".m.r.c.g.p" }, { "input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx", "output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x" }, { "input": "YB", "output": ".b" }, { "input": "fly", "output": ".f.l" }, { "input": "YyyYYYyyYxdwdawdDAWDdaddYYYY", "output": ".x.d.w.d.w.d.d.w.d.d.d.d" } ]
1,696,744,129
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
s=input().strip() d="AEIOUYaeiouy" n="" for y in s: if y not in d : n+="."+y elif y.isupper() and y not in AEIOUY: n+=y.lower() print(n)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python s=input().strip() d="AEIOUYaeiouy" n="" for y in s: if y not in d : n+="."+y elif y.isupper() and y not in AEIOUY: n+=y.lower() print(n) ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,642,069,496
2,147,483,647
Python 3
OK
TESTS
35
92
0
m,n = map(int,input().split()) d = m*n print(d//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python m,n = map(int,input().split()) d = m*n print(d//2) ```
3.977