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
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson?
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "input": "4 2", "output": "2" }, { "input": "1000 700", "output": "6" }, { "input": "959986566087 524054155168", "output": "90" }, { "input": "4 3", "output": "4" }, { "input": "7 6", "output": "7" }, { "input": "1000 999", "output": "1000" }, { "input": "1000 998", "output": "500" }, { "input": "1000 997", "output": "336" }, { "input": "42 1", "output": "42" }, { "input": "1000 1", "output": "1000" }, { "input": "8 5", "output": "5" }, { "input": "13 8", "output": "6" }, { "input": "987 610", "output": "15" }, { "input": "442 42", "output": "22" }, { "input": "754 466", "output": "13" }, { "input": "1000000000000 999999999999", "output": "1000000000000" }, { "input": "1000000000000 999999999998", "output": "500000000000" }, { "input": "941 14", "output": "74" }, { "input": "998 2", "output": "499" }, { "input": "1000 42", "output": "32" }, { "input": "1000 17", "output": "66" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "4" }, { "input": "5 3", "output": "4" }, { "input": "5 4", "output": "5" }, { "input": "293 210", "output": "17" }, { "input": "787878787878 424242424242", "output": "8" }, { "input": "956722026041 591286729879", "output": "58" }, { "input": "956722026041 365435296162", "output": "58" }, { "input": "628625247282 464807889701", "output": "102" }, { "input": "695928431619 424778620208", "output": "167" }, { "input": "1000000000000 42", "output": "23809523821" }, { "input": "987654345678 23", "output": "42941493300" }, { "input": "10000000001 2", "output": "5000000002" }, { "input": "1000000000000 2", "output": "500000000000" }, { "input": "1000000000000 3", "output": "333333333336" }, { "input": "100000000000 3", "output": "33333333336" }, { "input": "100000000000 23", "output": "4347826109" }, { "input": "999999999997 7", "output": "142857142861" }, { "input": "8589934592 4294967296", "output": "2" } ]
1,670,254,161
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
21
2,000
0
from sys import stdin input = stdin.readline def main(): a, b = map(int, input().split()) w = 0 # ~ breakpoint() if b == 1: w += a print(w) return 0 while (b > 0 and a > 0): if a > b: a, b = b, a - b w += 1 else: a, b = b - a, a w += 1 if b == 1: w += a print(w) main()
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? Input Specification: The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Output Specification: Print a single integer — the number of ships that Vasya will make. Demo Input: ['2 1\n', '10 7\n', '1000000000000 1\n'] Demo Output: ['2\n', '6\n', '1000000000000\n'] Note: Pictures to the first and second sample test.
```python from sys import stdin input = stdin.readline def main(): a, b = map(int, input().split()) w = 0 # ~ breakpoint() if b == 1: w += a print(w) return 0 while (b > 0 and a > 0): if a > b: a, b = b, a - b w += 1 else: a, b = b - a, a w += 1 if b == 1: w += a print(w) main() ```
0
407
C
Curious Array
PROGRAMMING
2,500
[ "brute force", "combinatorics", "implementation", "math" ]
null
null
You've got an array consisting of *n* integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Moreover, there are *m* queries, each query can be described by three integers *l**i*,<=*r**i*,<=*k**i*. Query *l**i*,<=*r**i*,<=*k**i* means that we should add to each element *a*[*j*], where *l**i*<=≤<=*j*<=≤<=*r**i*. Record means the binomial coefficient, or the number of combinations from *y* elements into groups of *x* elements. You need to fulfil consecutively all queries and then print the final array.
The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≤<=*a**i*<=≤<=109) — the initial array. Next *m* lines contain queries in the format *l**i*,<=*r**i*,<=*k**i* — to all elements of the segment *l**i*... *r**i* add number (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*; 0<=≤<=*k*<=≤<=100).
Print *n* integers: the *i*-th number is the value of element *a*[*i*] after all the queries. As the values can be rather large, print them modulo 1000000007 (109<=+<=7).
[ "5 1\n0 0 0 0 0\n1 5 0\n", "10 2\n1 2 3 4 5 0 0 0 0 0\n1 6 1\n6 10 2\n" ]
[ "1 1 1 1 1\n", "2 4 6 8 10 7 3 6 10 15\n" ]
none
2,000
[ { "input": "5 1\n0 0 0 0 0\n1 5 0", "output": "1 1 1 1 1" }, { "input": "10 2\n1 2 3 4 5 0 0 0 0 0\n1 6 1\n6 10 2", "output": "2 4 6 8 10 7 3 6 10 15" }, { "input": "5 3\n0 0 0 0 0\n1 5 0\n1 5 1\n1 5 2", "output": "3 6 10 15 21" }, { "input": "10 2\n0 0 0 0 0 0 0 0 0 0\n7 9 4\n2 4 1", "output": "0 1 2 3 0 0 1 5 15 0" }, { "input": "5 5\n1 2 8 6 3\n5 5 4\n1 5 5\n1 1 4\n5 5 0\n2 3 0", "output": "3 9 30 62 131" }, { "input": "10 2\n0 0 0 0 0 0 0 0 0 0\n8 10 3\n5 9 6", "output": "0 0 0 0 1 7 28 85 214 10" }, { "input": "10 50\n15 209 149 994 266 845 236 114 228 968\n3 6 9\n8 10 14\n5 7 17\n5 5 0\n10 10 9\n8 10 13\n6 10 19\n6 9 14\n10 10 7\n6 9 3\n4 7 23\n3 3 10\n3 5 2\n4 7 13\n6 7 23\n6 10 10\n7 7 9\n4 7 17\n9 9 13\n9 9 0\n4 4 12\n3 6 2\n9 10 20\n10 10 16\n10 10 25\n6 10 14\n2 2 21\n3 4 3\n10 10 14\n4 10 15\n3 7 0\n9 10 16\n9 10 13\n1 2 8\n6 10 10\n10 10 2\n7 10 25\n3 8 0\n5 10 0\n10 10 0\n4 10 11\n5 6 21\n6 6 23\n8 9 7\n8 10 24\n8 8 0\n9 10 14\n6 9 23\n9 9 2\n5 10 24", "output": "16 219 156 1022 424 1942 6341 9205 47088 204181" }, { "input": "32 16\n75454244 591508245 780919327 242504555 10328304 976613741 643845730 775054920 304114699 157548484 187864536 479076425 730938598 269393345 867303813 827252520 445388306 572924267 371919467 266567274 722374029 991613490 895119771 605883929 58242943 469913370 914902088 264594507 541825276 891949494 767100156 465664861\n21 23 64\n20 32 37\n30 31 33\n5 16 62\n23 27 69\n31 31 98\n16 26 65\n10 12 16\n25 26 75\n12 23 28\n31 31 8\n18 21 83\n12 20 37\n3 17 74\n7 16 45\n11 31 97", "output": "75454244 591508245 780919328 242504630 10331155 976686954 645274172 797636161 605336700 644440008 938999679 253648426 215172119 77111091 235540349 736135108 511694665 823709810 235878127 379861943 231742811 721935729 833146404 107601756 54917798 329009798 27304007 557864981 417846432 692087830 701419388 729399053" } ]
1,659,256,166
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
77
1,331,200
from math import factorial as fact def binomial(ai,bi): ai=ai%1000000007 bi=bi%1000000007 m=(fact(ai)%1000000007//fact(bi)%1000000007//fact(ai-bi)%1000000007)%1000000007 return m n,m=map(int,input().split()) Ai=list(map(int,input().split())) while m>0: li,ri,qi=map(int,input().split()) for j in range(li,ri+1): Ai[j-1]+=binomial(j-li+qi,qi)%1000000007 m-=1 print(*Ai)
Title: Curious Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array consisting of *n* integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Moreover, there are *m* queries, each query can be described by three integers *l**i*,<=*r**i*,<=*k**i*. Query *l**i*,<=*r**i*,<=*k**i* means that we should add to each element *a*[*j*], where *l**i*<=≤<=*j*<=≤<=*r**i*. Record means the binomial coefficient, or the number of combinations from *y* elements into groups of *x* elements. You need to fulfil consecutively all queries and then print the final array. Input Specification: The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≤<=*a**i*<=≤<=109) — the initial array. Next *m* lines contain queries in the format *l**i*,<=*r**i*,<=*k**i* — to all elements of the segment *l**i*... *r**i* add number (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*; 0<=≤<=*k*<=≤<=100). Output Specification: Print *n* integers: the *i*-th number is the value of element *a*[*i*] after all the queries. As the values can be rather large, print them modulo 1000000007 (109<=+<=7). Demo Input: ['5 1\n0 0 0 0 0\n1 5 0\n', '10 2\n1 2 3 4 5 0 0 0 0 0\n1 6 1\n6 10 2\n'] Demo Output: ['1 1 1 1 1\n', '2 4 6 8 10 7 3 6 10 15\n'] Note: none
```python from math import factorial as fact def binomial(ai,bi): ai=ai%1000000007 bi=bi%1000000007 m=(fact(ai)%1000000007//fact(bi)%1000000007//fact(ai-bi)%1000000007)%1000000007 return m n,m=map(int,input().split()) Ai=list(map(int,input().split())) while m>0: li,ri,qi=map(int,input().split()) for j in range(li,ri+1): Ai[j-1]+=binomial(j-li+qi,qi)%1000000007 m-=1 print(*Ai) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,524,661,767
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
1,000
6,963,200
flag=0 t=input() i=0 while i<=len(t)-1: if t[i]=="h": #print('t[i]',t[i]) flag=1 #print('flag=',flag) i+=1 if flag==1 and t[i]=="e": #print('t[i]',t[i]) flag=2 #print('flag=',flag) i+=1 if flag==2 and t[i]=="l": #print('t[i]',t[i]) flag=3 #print('flag=',flag) i+=1 if flag==3 and t[i]=="l": #print('t[i]',t[i]) flag=4 #print('flag=',flag) i+=1 if flag==4 and t[i]=="o": #print('t[i]',t[i]) flag=5 #print('flag=',flag) break if flag==5: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python flag=0 t=input() i=0 while i<=len(t)-1: if t[i]=="h": #print('t[i]',t[i]) flag=1 #print('flag=',flag) i+=1 if flag==1 and t[i]=="e": #print('t[i]',t[i]) flag=2 #print('flag=',flag) i+=1 if flag==2 and t[i]=="l": #print('t[i]',t[i]) flag=3 #print('flag=',flag) i+=1 if flag==3 and t[i]=="l": #print('t[i]',t[i]) flag=4 #print('flag=',flag) i+=1 if flag==4 and t[i]=="o": #print('t[i]',t[i]) flag=5 #print('flag=',flag) break if flag==5: print("YES") else: print("NO") ```
0
39
B
Company Income Growth
PROGRAMMING
1,300
[ "greedy" ]
B. Company Income Growth
2
64
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces.
Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
[ "10\n-2 1 1 3 2 3 4 -10 -2 5\n", "3\n-1 -2 -3\n" ]
[ "5\n2002 2005 2006 2007 2010\n", "0\n" ]
none
0
[ { "input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010 " }, { "input": "3\n-1 -2 -3", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "2\n-1 1", "output": "1\n2002 " }, { "input": "2\n-1 1", "output": "1\n2002 " }, { "input": "2\n-2 0", "output": "0" }, { "input": "2\n3 -3", "output": "0" }, { "input": "3\n1 1 1", "output": "1\n2001 " }, { "input": "3\n-2 -2 1", "output": "1\n2003 " }, { "input": "4\n-4 2 3 -1", "output": "0" }, { "input": "5\n-3 -3 -4 2 -2", "output": "0" }, { "input": "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 3 -4 2 -9 9 9 -6 -1 -7 -3 -6 10 10 -1 -8 -3 8 1 10 9 -9 10 4 -10 -6 9 7 8 5 -3 2 2 2 -7 -6 0 -4 -1 4 -2 -4 -1 2 -8 10 9", "output": "5\n2020 2036 2044 2077 2083 " }, { "input": "100\n5 -1 6 0 2 10 -6 6 -10 0 10 6 -10 3 8 4 2 6 3 -9 1 -1 -8 6 -6 -10 0 -3 -1 -6 -7 -9 -5 -5 5 -10 -3 4 -6 8 -4 2 2 8 2 -7 -4 -4 -9 4 -9 6 -4 -10 -8 -6 2 6 -4 3 3 4 -1 -9 8 9 -6 5 3 9 -4 0 -9 -10 3 -10 2 5 7 0 9 4 5 -3 5 -5 9 -4 6 -7 4 -1 -10 -1 -2 2 -1 4 -10 6", "output": "6\n2021 2042 2060 2062 2068 2089 " }, { "input": "100\n10 9 -10 0 -9 1 10 -6 -3 8 0 5 -7 -9 9 -1 1 4 9 0 4 -7 3 10 -3 -10 -6 4 -3 0 -7 8 -6 -1 5 0 -6 1 5 -7 10 10 -2 -10 -4 -1 -1 2 5 1 6 -7 3 -1 1 10 4 2 4 -3 -10 9 4 5 1 -10 -1 -9 -8 -2 4 -4 -10 -9 -5 -9 -1 -3 -3 -8 -8 -3 6 -3 6 10 -4 -1 -3 8 -9 0 -2 2 1 6 -4 -7 -9 3", "output": "6\n2006 2048 2053 2057 2064 2083 " }, { "input": "100\n-8 -3 -4 2 1 -9 5 4 4 -8 -8 6 -7 -1 9 -6 -1 1 -5 9 6 10 -8 -5 -2 10 7 10 -5 8 -7 5 -4 0 3 9 -9 -5 -4 -2 4 -1 -4 -5 -9 6 2 7 0 -2 2 3 -9 6 -10 6 5 -4 -9 -9 1 -7 -9 -3 -5 -8 4 0 4 10 -8 -6 -8 -9 5 -8 -6 -9 10 5 -6 -7 6 -5 8 3 1 3 7 3 -1 0 5 4 4 7 -7 5 -8 -2", "output": "7\n2005 2047 2052 2067 2075 2083 2089 " }, { "input": "100\n-15 8 -20 -2 -16 3 -19 -15 16 19 -1 -17 -14 9 7 2 20 -16 8 20 10 3 17 -3 2 5 9 15 3 3 -17 12 7 17 -19 -15 -5 16 -10 -4 10 -15 -16 9 -15 15 -16 7 -15 12 -17 7 4 -8 9 -2 -19 14 12 -1 17 -6 19 14 19 -9 -12 3 14 -10 5 7 19 11 5 10 18 2 -6 -12 7 5 -9 20 10 2 -20 6 -10 -16 -6 -5 -15 -2 15 -12 0 -18 2 -5", "output": "0" }, { "input": "100\n11 18 14 -19 -12 -5 -14 -3 13 14 -20 11 -6 12 -2 19 -16 -2 -4 -4 -18 -2 -15 5 -7 -18 11 5 -8 16 17 1 6 8 -20 13 17 -15 -20 7 16 -3 -17 -1 1 -18 2 9 4 2 -18 13 16 -14 -18 -14 16 19 13 4 -14 3 5 -7 5 -17 -14 13 20 16 -13 7 12 15 0 4 16 -16 -6 -15 18 -19 2 8 -4 -8 14 -4 20 -15 -20 14 7 -10 -17 -20 13 -1 -11 -4", "output": "4\n2032 2047 2062 2076 " }, { "input": "100\n3 99 47 -26 96 90 21 -74 -19 -17 80 -43 -24 -82 -39 -40 44 84 87 72 -78 -94 -82 -87 96 71 -29 -90 66 49 -87 19 -31 97 55 -29 -98 16 -23 68 84 -54 74 -71 -60 -32 -72 95 -55 -17 -49 -73 63 39 -31 -91 40 -29 -60 -33 -33 49 93 -56 -81 -18 38 45 -29 63 -37 27 75 13 -100 52 -51 75 -38 -49 28 39 -7 -37 -86 100 -8 28 -89 -57 -17 -52 -98 -92 56 -49 -24 92 28 31", "output": "0" }, { "input": "100\n-36 -88 -23 -71 33 53 21 49 97 -50 -91 24 -83 -100 -77 88 -56 -31 -27 7 -74 -69 -75 -59 78 -66 53 21 -41 72 -31 -93 26 98 58 78 -95 -64 -2 34 74 14 23 -25 -51 -94 -46 100 -44 79 46 -8 79 25 -55 16 35 67 29 58 49 75 -53 80 63 -50 -59 -5 -71 -72 -57 75 -71 6 -5 -44 34 -2 -10 -58 -98 67 -42 22 95 46 -58 88 62 82 85 -74 -94 -5 -64 12 -8 44 -57 87", "output": "0" }, { "input": "100\n-76 -73 -93 85 -30 66 -29 -79 13 -82 -12 90 8 -68 86 15 -5 55 -91 92 80 5 83 19 59 -1 -17 83 52 44 25 -3 83 -51 62 -66 -91 58 20 51 15 -70 -77 22 -92 -4 -70 55 -33 -27 -59 6 94 60 -79 -28 -20 -38 -83 100 -20 100 51 -35 -44 -82 44 -5 88 -6 -26 -79 -16 -2 -61 12 -81 -80 68 -68 -23 96 -77 80 -75 -57 93 97 12 20 -65 -46 -90 81 16 -77 -43 -3 8 -58", "output": "0" }, { "input": "100\n-64 -18 -21 46 28 -100 21 -98 49 -44 -38 52 -85 62 42 -85 19 -27 88 -45 28 -86 -20 15 34 61 17 88 95 21 -40 -2 -12 90 -61 30 7 -13 -74 43 -57 43 -30 51 -19 -51 -22 -2 -76 85 1 -53 -31 -77 96 -61 61 88 -62 88 -6 -59 -70 18 -65 90 91 -27 -86 37 8 -92 -82 -78 -57 -81 17 -53 3 29 -88 -92 -28 49 -2 -41 32 -89 -38 49 22 37 -17 -1 -78 -80 -12 36 -95 30", "output": "1\n2051 " }, { "input": "1\n1", "output": "1\n2001 " }, { "input": "2\n1 2", "output": "2\n2001 2002 " }, { "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": "100\n2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 " }, { "input": "100\n-29 -92 -94 81 -100 1 -29 2 3 97 -37 4 5 -52 6 7 -81 86 8 9 10 98 36 -99 11 -18 12 -46 13 14 15 16 17 18 19 20 21 23 53 22 23 24 6 17 45 25 99 26 -53 -51 48 -11 71 27 -56 28 29 -36 30 31 61 -53 -64 32 33 89 -90 34 35 54 36 -89 13 -89 5 37 38 39 -57 26 55 80 40 63 41 42 43 44 92 45 46 47 -10 -10 -32 48 49 50 -10 -99", "output": "50\n2006 2008 2009 2012 2013 2015 2016 2019 2020 2021 2025 2027 2029 2030 2031 2032 2033 2034 2035 2036 2037 2040 2041 2042 2046 2048 2054 2056 2057 2059 2060 2064 2065 2068 2069 2071 2076 2077 2078 2083 2085 2086 2087 2088 2090 2091 2092 2096 2097 2098 " }, { "input": "100\n1 2 84 -97 3 -59 30 -55 4 -6 80 5 6 7 -8 8 3 -96 88 9 10 -20 -95 11 12 67 5 4 -15 -62 -74 13 14 15 16 17 18 19 20 21 22 -15 23 -35 -17 24 25 -99 26 27 69 2 -92 -96 -77 28 29 -95 -75 30 -36 31 17 -88 10 52 32 33 34 -94 35 -38 -16 36 37 38 31 -58 39 -81 83 46 40 41 42 43 -44 44 4 49 -60 17 64 45 46 47 48 49 -38 50", "output": "50\n2001 2002 2005 2009 2012 2013 2014 2016 2020 2021 2024 2025 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2043 2046 2047 2049 2050 2056 2057 2060 2062 2067 2068 2069 2071 2074 2075 2076 2079 2083 2084 2085 2086 2088 2094 2095 2096 2097 2098 2100 " }, { "input": "100\n1 2 80 30 95 51 -3 -12 3 -11 4 -90 5 6 7 8 -18 52 77 -82 9 10 11 -51 -16 70 12 13 14 15 16 17 58 18 36 19 -86 20 21 40 -53 94 22 23 27 67 24 -90 -38 17 -71 40 25 72 -82 26 27 -4 28 29 30 31 32 67 33 34 90 42 -52 35 36 37 -6 38 39 -11 30 40 41 42 -42 21 -96 43 -50 44 -73 16 45 90 46 47 48 2 -37 -88 49 -27 -43 50", "output": "50\n2001 2002 2009 2011 2013 2014 2015 2016 2021 2022 2023 2027 2028 2029 2030 2031 2032 2034 2036 2038 2039 2043 2044 2047 2053 2056 2057 2059 2060 2061 2062 2063 2065 2066 2070 2071 2072 2074 2075 2078 2079 2080 2084 2086 2089 2091 2092 2093 2097 2100 " }, { "input": "100\n1 2 3 -72 6 4 5 6 7 8 9 10 11 -57 12 13 14 -37 74 15 16 17 3 18 19 20 21 22 -6 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -24 39 40 41 42 43 44 45 -52 46 -65 47 -82 48 49 50 47 -28 51 52 53 54 55 -30 56 57 58 59 12 60 61 62 63 -14 64 65 66 67 -77 68 69 70 71 72 73 74 -4 -6 -75 75 -26 76 49 77 -86", "output": "77\n2001 2002 2003 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2020 2021 2022 2024 2025 2026 2027 2028 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2047 2048 2049 2050 2051 2052 2053 2055 2057 2059 2060 2061 2064 2065 2066 2067 2068 2070 2071 2072 2073 2075 2076 2077 2078 2080 2081 2082 2083 2085 2086 2087 2088 2089 2090 2091 2095 2097 2099 " }, { "input": "100\n10 5 -69 1 -79 -57 -80 87 -38 -54 -91 33 29 81 20 -58 -97 70 2 -13 71 57 -15 98 -18 100 34 -25 -39 75 100 -88 3 95 48 -92 -20 -13 5 4 -19 -99 4 -46 -35 12 -43 -30 -37 -51 77 90 -47 -87 3 -84 -62 -51 69 -38 74 -63 -5 5 6 7 -65 90 -33 -23 8 19 -69 -98 24 28 100 9 -90 -34 -69 72 -15 8 27 -80 6 33 62 -57 -4 10 40 81 -78 58 43 83 57 21", "output": "10\n2004 2019 2033 2040 2064 2065 2066 2071 2078 2092 " }, { "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": "10\n2 3 1 3 3 2 1 2 1 2", "output": "2\n2003 2006 " }, { "input": "15\n4 1 4 6 3 2 1 1 3 2 4 4 1 4 1", "output": "4\n2002 2006 2009 2011 " }, { "input": "15\n3 3 3 2 2 2 1 1 1 2 2 2 4 4 4", "output": "2\n2007 2010 " }, { "input": "15\n6 5 2 3 4 1 3 2 4 5 1 2 6 4 4", "output": "2\n2006 2008 " } ]
1,650,557,068
2,147,483,647
PyPy 3-64
OK
TESTS
35
92
0
n = int(input()) arr = list(map(int,input().split())) ans = [] curr = 1 for i in range(n): if arr[i]==curr: curr+=1 ans.append(2001+i) if ans: print(len(ans)) print(*ans) else: print(0)
Title: Company Income Growth Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. Output Specification: Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. Demo Input: ['10\n-2 1 1 3 2 3 4 -10 -2 5\n', '3\n-1 -2 -3\n'] Demo Output: ['5\n2002 2005 2006 2007 2010\n', '0\n'] Note: none
```python n = int(input()) arr = list(map(int,input().split())) ans = [] curr = 1 for i in range(n): if arr[i]==curr: curr+=1 ans.append(2001+i) if ans: print(len(ans)) print(*ans) else: print(0) ```
3.977
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,680,865,994
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
122
0
def main(): a, b, n = map(int,input().split()) x = n for i in range(n): for j in range(a): if a%a-j ==0 and x%a-j==0: x -= a-j break if x == 0: print('0') return for j in range(b): if b%b-j ==0 and x%b-j ==0: x -= b-j break if x == 0: print('1') return main()
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 def main(): a, b, n = map(int,input().split()) x = n for i in range(n): for j in range(a): if a%a-j ==0 and x%a-j==0: x -= a-j break if x == 0: print('0') return for j in range(b): if b%b-j ==0 and x%b-j ==0: x -= b-j break if x == 0: print('1') return main() ```
0
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..." }, { "input": "84817 1 33457", "output": "-1" }, { "input": "21 37 99", "output": "16 53 " }, { "input": "78 7 15", "output": "-1" }, { "input": "74 17 27", "output": "-1" }, { "input": "79 23 43", "output": "-1" }, { "input": "32 33 3", "output": "-1" }, { "input": "55 49 44", "output": "-1" }, { "input": "64 59 404", "output": "54 113 172 231 290 " }, { "input": "61 69 820", "output": "8 77 146 215 284 353 422 491 560 629 698 " }, { "input": "17 28 532", "output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 " }, { "input": "46592 52 232", "output": "-1" }, { "input": "1541 58 648", "output": "-1" }, { "input": "15946 76 360", "output": "-1" }, { "input": "30351 86 424", "output": "-1" }, { "input": "1 2 37493", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "1 3 27764", "output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..." }, { "input": "10 4 9174", "output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..." }, { "input": "33 7 4971", "output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..." }, { "input": "981 1 3387", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "386 1 2747", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "123 2 50000", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "3123 100 10000000", "output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..." }, { "input": "2 10000 1000000000", "output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..." }, { "input": "3 10000 1000000000", "output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..." }, { "input": "12312223 10000 1000000000", "output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..." }, { "input": "500000000 1000000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 1000000000", "output": "999999999 " }, { "input": "10 6 11", "output": "-1" }, { "input": "2 100 10", "output": "-1" }, { "input": "1 100000007 1000000000", "output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 " }, { "input": "1 999999999 1000000000", "output": "999999998 " }, { "input": "100000000 1000000000 1000000000", "output": "900000000 " }, { "input": "11 2 12", "output": "1 " }, { "input": "31 10 39", "output": "-1" }, { "input": "48 6 50", "output": "-1" }, { "input": "500000000 500000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 999999999", "output": "-1" }, { "input": "4 2 10", "output": "2 4 6 " }, { "input": "1000000000 1 1", "output": "-1" }, { "input": "1000000000 1 100000", "output": "-1" }, { "input": "1000000000 1 10", "output": "-1" }, { "input": "10 5 14", "output": "-1" }, { "input": "500000000 499999999 1000000000", "output": "499999998 " }, { "input": "1 999999997 1000000000", "output": "999999996 " } ]
1,675,833,225
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
31
342
0
y,k,n=map(int,input().split()) #(x+y)%k=0 #x+y<=n x=[] p=1 c=False #print('p1') for i in range(k-y,n-y+1,k): if (i+y)%k==0 and i>0: #print('p2') p=i break for i in range(p,n-y+1,k): #print('p3') c=True print(i,end=' ') if c==False: print(-1)
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. Input Specification: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). Output Specification: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Demo Input: ['10 1 10\n', '10 6 40\n'] Demo Output: ['-1\n', '2 8 14 20 26 \n'] Note: none
```python y,k,n=map(int,input().split()) #(x+y)%k=0 #x+y<=n x=[] p=1 c=False #print('p1') for i in range(k-y,n-y+1,k): if (i+y)%k==0 and i>0: #print('p2') p=i break for i in range(p,n-y+1,k): #print('p3') c=True print(i,end=' ') if c==False: print(-1) ```
0
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,694,102,349
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def isPossible(input): portion1 = 2 while portion1 < input: portion2 = input-portion1 if portion2 % 2 == 0: return "YES" portion1 += 2 return "NO"
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python def isPossible(input): portion1 = 2 while portion1 < input: portion2 = input-portion1 if portion2 % 2 == 0: return "YES" portion1 += 2 return "NO" ```
0
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "480", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "49", "output": "YES" }, { "input": "56", "output": "YES" }, { "input": "124", "output": "YES" }, { "input": "1000", "output": "YES" }, { "input": "999", "output": "NO" }, { "input": "298", "output": "NO" }, { "input": "274", "output": "NO" }, { "input": "998", "output": "NO" }, { "input": "42", "output": "YES" }, { "input": "788", "output": "YES" }, { "input": "70", "output": "YES" }, { "input": "444", "output": "YES" }, { "input": "777", "output": "YES" }, { "input": "799", "output": "YES" }, { "input": "25", "output": "NO" }, { "input": "882", "output": "YES" }, { "input": "88", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "YES" }, { "input": "94", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "141", "output": "YES" } ]
1,691,406,095
2,147,483,647
Python 3
OK
TESTS
36
92
0
s = int(input()) fl = False l = [4, 7, 44, 47, 74, 77, 447, 474, 477, 744, 747, 774, 777] for i in l: if s in l or s%i == 0: fl = True break if fl == False: print('NO') else: print("YES")
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. Output Specification: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['47\n', '16\n', '78\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
```python s = int(input()) fl = False l = [4, 7, 44, 47, 74, 77, 447, 474, 477, 744, 747, 774, 777] for i in l: if s in l or s%i == 0: fl = True break if fl == False: print('NO') else: print("YES") ```
3
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not.
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", "output": "YES" }, { "input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", "output": "NO" }, { "input": " furuike ya\nkawazu tobikomu\nmizu no oto ", "output": "YES" }, { "input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ", "output": "NO" }, { "input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det", "output": "YES" }, { "input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel", "output": "NO" }, { "input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti", "output": "NO" }, { "input": "kutaburete\nyado karu koro ya\nfuji no hana", "output": "YES" }, { "input": " beginnings of poetry\n the rice planting songs \n of the interior", "output": "NO" }, { "input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden", "output": "NO" }, { "input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut", "output": "YES" }, { "input": "writing in the dark\nunaware that my pen\nhas run out of ink", "output": "NO" }, { "input": "kusaaiu\nuieueua\nuo efaa", "output": "YES" }, { "input": "v\nh\np", "output": "NO" }, { "input": "i\ni\nu", "output": "NO" }, { "input": "awmio eoj\nabdoolceegood\nwaadeuoy", "output": "YES" }, { "input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo", "output": "YES" }, { "input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr", "output": "YES" }, { "input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd", "output": "YES" }, { "input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ", "output": "YES" }, { "input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs", "output": "YES" }, { "input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn", "output": "NO" }, { "input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl", "output": "NO" }, { "input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr", "output": "NO" }, { "input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf", "output": "NO" }, { "input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi", "output": "NO" }, { "input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu", "output": "NO" }, { "input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt", "output": "NO" }, { "input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo", "output": "NO" }, { "input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau", "output": "NO" }, { "input": "ab\na\na", "output": "NO" }, { "input": "on codeforcs\nbeta round is runnineg\na rustling of keys", "output": "NO" }, { "input": "coooooooooooooooood\nd\nd", "output": "NO" }, { "input": "on codeforces \nbeta round is runninog\n a rustling of keys", "output": "NO" }, { "input": "aaaaaaaaaaaaaaa\na\na", "output": "NO" }, { "input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "YES" }, { "input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "NO" }, { "input": "aaaaaa\naaaaaa\naaaaa", "output": "NO" } ]
1,600,887,454
2,147,483,647
Python 3
OK
TESTS
40
340
307,200
x = input() y = input () z = input () ans = 0 lis = [5, 7, 5] lis2 = [x, y, z] def check (str) : cnt = 0 for i in str : if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' : cnt += 1 return cnt for i in range (len (lis)): if check (lis2[i]) == lis[i] : ans += 1 if ans == 3 : print ('YES') else : print ('NO')
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input Specification: The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Specification: Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Demo Input: ['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n'] Demo Output: ['YES', 'NO'] Note: none
```python x = input() y = input () z = input () ans = 0 lis = [5, 7, 5] lis2 = [x, y, z] def check (str) : cnt = 0 for i in str : if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' : cnt += 1 return cnt for i in range (len (lis)): if check (lis2[i]) == lis[i] : ans += 1 if ans == 3 : print ('YES') else : print ('NO') ```
3.914428
47
A
Triangular numbers
PROGRAMMING
800
[ "brute force", "math" ]
A. Triangular numbers
2
256
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number.
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
[ "1\n", "2\n", "3\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "2", "output": "NO" }, { "input": "3", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "12", "output": "NO" }, { "input": "10", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "9", "output": "NO" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "YES" }, { "input": "16", "output": "NO" }, { "input": "20", "output": "NO" }, { "input": "21", "output": "YES" }, { "input": "22", "output": "NO" }, { "input": "121", "output": "NO" }, { "input": "135", "output": "NO" }, { "input": "136", "output": "YES" }, { "input": "137", "output": "NO" }, { "input": "152", "output": "NO" }, { "input": "153", "output": "YES" }, { "input": "154", "output": "NO" }, { "input": "171", "output": "YES" }, { "input": "189", "output": "NO" }, { "input": "190", "output": "YES" }, { "input": "191", "output": "NO" }, { "input": "210", "output": "YES" }, { "input": "211", "output": "NO" }, { "input": "231", "output": "YES" }, { "input": "232", "output": "NO" }, { "input": "252", "output": "NO" }, { "input": "253", "output": "YES" }, { "input": "254", "output": "NO" }, { "input": "275", "output": "NO" }, { "input": "276", "output": "YES" }, { "input": "277", "output": "NO" }, { "input": "299", "output": "NO" }, { "input": "300", "output": "YES" }, { "input": "301", "output": "NO" }, { "input": "324", "output": "NO" }, { "input": "325", "output": "YES" }, { "input": "326", "output": "NO" }, { "input": "350", "output": "NO" }, { "input": "351", "output": "YES" }, { "input": "352", "output": "NO" }, { "input": "377", "output": "NO" }, { "input": "378", "output": "YES" }, { "input": "406", "output": "YES" }, { "input": "434", "output": "NO" }, { "input": "435", "output": "YES" }, { "input": "464", "output": "NO" }, { "input": "465", "output": "YES" }, { "input": "495", "output": "NO" }, { "input": "496", "output": "YES" }, { "input": "497", "output": "NO" }, { "input": "331", "output": "NO" }, { "input": "413", "output": "NO" }, { "input": "177", "output": "NO" }, { "input": "122", "output": "NO" }, { "input": "478", "output": "NO" }, { "input": "188", "output": "NO" }, { "input": "21", "output": "YES" }, { "input": "474", "output": "NO" }, { "input": "21", "output": "YES" }, { "input": "48", "output": "NO" }, { "input": "498", "output": "NO" }, { "input": "499", "output": "NO" }, { "input": "500", "output": "NO" } ]
1,632,590,231
2,147,483,647
Python 3
OK
TESTS
71
154
6,758,400
n =int(input()) sum =0 i=1 while(sum<=n): sum = sum+i; if(sum == n): print("YES") break i = i+1 else: print("NO")
Title: Triangular numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number. Input Specification: The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. Output Specification: If the given integer is a triangular number output YES, otherwise output NO. Demo Input: ['1\n', '2\n', '3\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python n =int(input()) sum =0 i=1 while(sum<=n): sum = sum+i; if(sum == n): print("YES") break i = i+1 else: print("NO") ```
3.948911
607
B
Zuma
PROGRAMMING
1,900
[ "dp" ]
null
null
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is a palindrome and remove it from the line. After the substring is removed, the remaining gemstones shift to form a solid line again. What is the minimum number of seconds needed to destroy the entire line? Let us remind, that the string (or substring) is called palindrome, if it reads same backwards or forward. In our case this means the color of the first gemstone is equal to the color of the last one, the color of the second gemstone is equal to the color of the next to last and so on.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of gemstones. The second line contains *n* space-separated integers, the *i*-th of which is *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the color of the *i*-th gemstone in a line.
Print a single integer — the minimum number of seconds needed to destroy the entire line.
[ "3\n1 2 1\n", "3\n1 2 3\n", "7\n1 4 4 2 3 2 1\n" ]
[ "1\n", "3\n", "2\n" ]
In the first sample, Genos can destroy the entire line in one second. In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds. In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 2 1.
1,250
[ { "input": "3\n1 2 1", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "7\n1 4 4 2 3 2 1", "output": "2" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1 2", "output": "2" }, { "input": "8\n1 2 1 3 4 1 2 1", "output": "2" }, { "input": "50\n5 7 5 10 7 9 1 9 10 2 8 3 5 7 3 10 2 3 7 6 2 7 1 2 2 2 4 7 3 5 8 3 4 4 1 6 7 10 5 4 8 1 9 5 5 3 4 4 8 3", "output": "21" }, { "input": "50\n13 17 20 5 14 19 4 17 9 13 10 19 16 13 17 2 18 3 1 9 19 4 19 10 17 12 16 20 10 11 15 10 3 19 8 6 2 8 9 15 13 7 8 8 5 8 15 18 9 4", "output": "28" }, { "input": "50\n22 19 14 22 20 11 16 28 23 15 3 23 6 16 30 15 15 10 24 28 19 19 22 30 28 1 27 12 12 14 17 30 17 26 21 26 27 1 11 23 9 30 18 19 17 29 11 20 29 24", "output": "25" }, { "input": "50\n30 17 31 15 10 3 39 36 5 29 16 11 31 2 38 1 32 40 7 15 39 34 24 11 4 23 9 35 39 32 4 5 14 37 10 34 11 33 30 14 4 34 23 10 34 34 26 34 26 16", "output": "36" }, { "input": "50\n19 25 46 17 1 41 50 19 7 1 43 8 19 38 42 32 38 22 8 5 5 31 29 35 43 12 23 48 40 29 30 9 46 3 39 24 36 36 32 22 21 29 43 33 36 49 48 22 47 37", "output": "36" }, { "input": "6\n1 2 1 1 3 1", "output": "2" } ]
1,603,460,678
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
12
2,000
10,444,800
from sys import stdin,stdout def fn(i,j): if j<i:return 0 if i==j:return 1 if j==i+1:return 1 if (a[i]==a[j]) else 2 if (i,j) in dp:return dp[i,j] ans=n if a[i]==a[j]:ans=fn(i+1,j-1) for k in range(i,j): ans=min(ans,fn(i,k)+fn(k+1,j)) dp[i,j]=ans return ans for _ in range(1):#(stdin.readline())): n=int(stdin.readline()) # n,m=list(map(int,stdin.readline().split())) a=list(map(int,stdin.readline().split())) dp={} print(fn(0,n-1))
Title: Zuma Time Limit: None seconds Memory Limit: None megabytes Problem Description: Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is a palindrome and remove it from the line. After the substring is removed, the remaining gemstones shift to form a solid line again. What is the minimum number of seconds needed to destroy the entire line? Let us remind, that the string (or substring) is called palindrome, if it reads same backwards or forward. In our case this means the color of the first gemstone is equal to the color of the last one, the color of the second gemstone is equal to the color of the next to last and so on. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of gemstones. The second line contains *n* space-separated integers, the *i*-th of which is *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the color of the *i*-th gemstone in a line. Output Specification: Print a single integer — the minimum number of seconds needed to destroy the entire line. Demo Input: ['3\n1 2 1\n', '3\n1 2 3\n', '7\n1 4 4 2 3 2 1\n'] Demo Output: ['1\n', '3\n', '2\n'] Note: In the first sample, Genos can destroy the entire line in one second. In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds. In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 2 1.
```python from sys import stdin,stdout def fn(i,j): if j<i:return 0 if i==j:return 1 if j==i+1:return 1 if (a[i]==a[j]) else 2 if (i,j) in dp:return dp[i,j] ans=n if a[i]==a[j]:ans=fn(i+1,j-1) for k in range(i,j): ans=min(ans,fn(i,k)+fn(k+1,j)) dp[i,j]=ans return ans for _ in range(1):#(stdin.readline())): n=int(stdin.readline()) # n,m=list(map(int,stdin.readline().split())) a=list(map(int,stdin.readline().split())) dp={} print(fn(0,n-1)) ```
0
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", "output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000" }, { "input": "2\n-1000000000 1000000000", "output": "2000000000 2000000000\n2000000000 2000000000" }, { "input": "10\n1 10 12 15 59 68 130 912 1239 9123", "output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122" }, { "input": "5\n-2 -1 0 1 2", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "5\n-2 -1 0 1 3", "output": "1 5\n1 4\n1 3\n1 3\n2 5" }, { "input": "3\n-10000 1 10000", "output": "10001 20000\n9999 10001\n9999 20000" }, { "input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706", "output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010" }, { "input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124", "output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524" }, { "input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292", "output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307" }, { "input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986", "output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14" }, { "input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886", "output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..." }, { "input": "3\n-1000000000 999999999 1000000000", "output": "1999999999 2000000000\n1 1999999999\n1 2000000000" } ]
1,674,522,368
2,147,483,647
Python 3
OK
TESTS
54
655
7,987,200
n=int(input()) l=[] for i in input().split(): l.append(int(i)) first_city=l[0] last_city=l[-1] mx=10e9 mn=-10e9 for i in range(n): if i==0: mx=abs(l[i]-last_city) mn=abs(l[i]-l[i+1]) elif i==n-1: mx=abs(l[i]-first_city) mn=abs(l[i]-l[i-1]) else: mn = min(abs(l[i] - l[i - 1]), abs(l[i] - l[i + 1])); mx = max(abs(l[i] - first_city), abs(l[i] - last_city)); print(mn," ",mx) mx = 10e9 mn = -10e9
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. Output Specification: Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. Demo Input: ['4\n-5 -2 2 7\n', '2\n-1 1\n'] Demo Output: ['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n'] Note: none
```python n=int(input()) l=[] for i in input().split(): l.append(int(i)) first_city=l[0] last_city=l[-1] mx=10e9 mn=-10e9 for i in range(n): if i==0: mx=abs(l[i]-last_city) mn=abs(l[i]-l[i+1]) elif i==n-1: mx=abs(l[i]-first_city) mn=abs(l[i]-l[i-1]) else: mn = min(abs(l[i] - l[i - 1]), abs(l[i] - l[i + 1])); mx = max(abs(l[i] - first_city), abs(l[i] - last_city)); print(mn," ",mx) mx = 10e9 mn = -10e9 ```
3
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,595,447,963
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
7,270,400
n, m = map(int, input().split()) slova=[[j for j in input().split()] for i in range(m)] fraza = input().split() ans=[] for i in range(n): for j in range(m): if fraza[i] == slova[j][0]: if len(slova[j][0])<=len(slova[j][1]): ans.append(slova[j][0]) else: ans.append(slova[j][1]) for i in range(n): print(ans[i], end = ' ')
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n, m = map(int, input().split()) slova=[[j for j in input().split()] for i in range(m)] fraza = input().split() ans=[] for i in range(n): for j in range(m): if fraza[i] == slova[j][0]: if len(slova[j][0])<=len(slova[j][1]): ans.append(slova[j][0]) else: ans.append(slova[j][1]) for i in range(n): print(ans[i], end = ' ') ```
0
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, { "input": "10 3 4 5", "output": "3" }, { "input": "100 23 15 50", "output": "2" }, { "input": "3119 3515 1021 7", "output": "11" }, { "input": "918 102 1327 1733", "output": "9" }, { "input": "3164 42 430 1309", "output": "15" }, { "input": "3043 317 1141 2438", "output": "7" }, { "input": "26 1 772 2683", "output": "26" }, { "input": "370 2 1 15", "output": "370" }, { "input": "734 12 6 2", "output": "367" }, { "input": "418 18 14 17", "output": "29" }, { "input": "18 16 28 9", "output": "2" }, { "input": "14 6 2 17", "output": "7" }, { "input": "29 27 18 2", "output": "2" }, { "input": "29 12 7 10", "output": "3" }, { "input": "27 23 4 3", "output": "9" }, { "input": "5 14 5 2", "output": "1" }, { "input": "5 17 26 5", "output": "1" }, { "input": "9 1 10 3", "output": "9" }, { "input": "2 19 15 1", "output": "2" }, { "input": "4 6 4 9", "output": "1" }, { "input": "10 6 2 9", "output": "5" }, { "input": "2 2 9 6", "output": "1" }, { "input": "6 2 4 1", "output": "6" }, { "input": "27 24 5 27", "output": "1" }, { "input": "2683 83 26 2709", "output": "101" }, { "input": "728 412 789 158", "output": "3" }, { "input": "3964 4 2916 176", "output": "991" }, { "input": "3399 2035 2 3334", "output": "683" }, { "input": "3455 244 3301 3", "output": "991" }, { "input": "595 2263 3625 1", "output": "595" }, { "input": "4000 1 1 1", "output": "4000" }, { "input": "3999 2 2 3999", "output": "1" }, { "input": "25 6 8 11", "output": "3" }, { "input": "4000 500 1000 2000", "output": "8" }, { "input": "53 10 11 23", "output": "5" }, { "input": "100 100 1 1", "output": "100" }, { "input": "17 3 4 10", "output": "5" }, { "input": "413 101 102 105", "output": "4" }, { "input": "490 4 49 50", "output": "111" }, { "input": "3999 2 3 3", "output": "1999" }, { "input": "8 3 8 4", "output": "2" }, { "input": "5 1 3 3", "output": "5" }, { "input": "100 3 17 22", "output": "27" }, { "input": "4000 2 3 4", "output": "2000" }, { "input": "4000 3 3 5", "output": "1332" }, { "input": "13 4 6 7", "output": "2" }, { "input": "4000 5 2 2", "output": "2000" }, { "input": "3999 2 2 3", "output": "1999" }, { "input": "4000 33 7 3333", "output": "564" }, { "input": "60 33 20 9", "output": "4" }, { "input": "100 9 11 99", "output": "10" }, { "input": "2009 6 8 9", "output": "334" } ]
1,697,026,986
2,147,483,647
Python 3
OK
TESTS
58
46
0
n, a, b, c = input().split() n = int(n) a = int(a) b = int(b) c = int(c) dp = [-float('inf')] * (n+1) def iterative_soln(length): dp[0] = 0 for i in range(1, length+1): if i >= a: dp[i] = max(dp[i], 1+ dp[i-a]) if i >= b: dp[i] = max(dp[i], 1+ dp[i-b]) if i >= c: dp[i] = max(dp[i], 1+ dp[i-c]) return dp[length] print(iterative_soln(n))
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting. Input Specification: The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. Output Specification: Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. Demo Input: ['5 5 3 2\n', '7 5 5 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
```python n, a, b, c = input().split() n = int(n) a = int(a) b = int(b) c = int(c) dp = [-float('inf')] * (n+1) def iterative_soln(length): dp[0] = 0 for i in range(1, length+1): if i >= a: dp[i] = max(dp[i], 1+ dp[i-a]) if i >= b: dp[i] = max(dp[i], 1+ dp[i-b]) if i >= c: dp[i] = max(dp[i], 1+ dp[i-c]) return dp[length] print(iterative_soln(n)) ```
3
624
B
Making a String
PROGRAMMING
1,100
[ "greedy", "sortings" ]
null
null
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.
The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet. The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string.
Print a single integer — the maximum length of the string that meets all the requirements.
[ "3\n2 5 5\n", "3\n1 1 2\n" ]
[ "11\n", "3\n" ]
For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".
1,000
[ { "input": "3\n2 5 5", "output": "11" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "2\n1 1", "output": "1" }, { "input": "3\n1 1000000000 2", "output": "1000000003" }, { "input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "25999999675" }, { "input": "2\n559476582 796461544", "output": "1355938126" }, { "input": "2\n257775227 621811272", "output": "879586499" }, { "input": "10\n876938317 219479349 703839299 977218449 116819315 752405530 393874852 286326991 592978634 155758306", "output": "5075639042" }, { "input": "26\n72 49 87 47 94 96 36 91 43 11 19 83 36 38 10 93 95 81 4 96 60 38 97 37 36 41", "output": "1478" }, { "input": "26\n243 364 768 766 633 535 502 424 502 283 592 877 137 891 837 990 681 898 831 487 595 604 747 856 805 688", "output": "16535" }, { "input": "26\n775 517 406 364 548 951 680 984 466 141 960 513 660 849 152 250 176 601 199 370 971 554 141 224 724 543", "output": "13718" }, { "input": "26\n475 344 706 807 925 813 974 166 578 226 624 591 419 894 574 909 544 597 170 990 893 785 399 172 792 748", "output": "16115" }, { "input": "26\n130 396 985 226 487 671 188 706 106 649 38 525 210 133 298 418 953 431 577 69 12 982 264 373 283 266", "output": "10376" }, { "input": "26\n605 641 814 935 936 547 524 702 133 674 173 102 318 620 248 523 77 718 318 635 322 362 306 86 8 442", "output": "11768" }, { "input": "26\n220 675 725 888 725 654 546 806 379 182 604 667 734 394 889 731 572 193 850 651 844 734 163 671 820 887", "output": "16202" }, { "input": "26\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "25675" }, { "input": "26\n1001 1001 1000 1000 1001 1000 1001 1001 1001 1000 1000 1001 1001 1000 1000 1000 1000 1001 1000 1001 1001 1000 1001 1001 1001 1000", "output": "25701" }, { "input": "26\n1000 1001 1000 1001 1000 1001 1001 1000 1001 1002 1002 1000 1001 1000 1000 1000 1001 1002 1001 1000 1000 1001 1000 1002 1001 1002", "output": "25727" }, { "input": "26\n1003 1002 1002 1003 1000 1000 1000 1003 1000 1001 1003 1003 1000 1002 1002 1002 1001 1003 1000 1001 1000 1001 1001 1000 1003 1003", "output": "25753" }, { "input": "26\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", "output": "1" }, { "input": "26\n8717 9417 1409 7205 3625 6247 8626 9486 464 4271 1698 8449 4551 1528 7456 9198 4886 2889 7534 506 7867 9410 1635 4955 2580 2580", "output": "137188" }, { "input": "26\n197464663 125058028 622449215 11119637 587496049 703992162 219591040 965159268 229879004 278894000 841629744 616893922 218779915 362575332 844188865 342411376 369680019 43823059 921419789 999588082 943769007 35365522 301907919 758302419 427454397 807507709", "output": "12776400142" }, { "input": "26\n907247856 970380443 957324066 929910532 947150618 944189007 998282297 988343406 981298600 943026596 953932265 972691398 950024048 923033790 996423650 972134755 946404759 918183059 902987271 965507679 906967700 982106487 933997242 972594441 977736332 928874832", "output": "24770753129" }, { "input": "26\n999999061 999999688 999999587 999999429 999999110 999999563 999999120 999999111 999999794 999999890 999999004 999999448 999999770 999999543 999999460 999999034 999999361 999999305 999999201 999999778 999999432 999999844 999999133 999999342 999999600 999999319", "output": "25999984927" }, { "input": "3\n587951561 282383259 612352726", "output": "1482687546" }, { "input": "4\n111637338 992238139 787658714 974622806", "output": "2866156997" }, { "input": "5\n694257603 528073418 726928894 596328666 652863391", "output": "3198451972" }, { "input": "6\n217943380 532900593 902234882 513005821 369342573 495810412", "output": "3031237661" }, { "input": "7\n446656860 478792281 77541870 429682977 85821755 826122363 563802405", "output": "2908420511" }, { "input": "8\n29278125 778590752 252847858 51388836 802299938 215370803 901540149 242074772", "output": "3273391233" }, { "input": "9\n552962902 724482439 133182550 673093696 518779120 604618242 534250189 847695567 403066553", "output": "4992131258" }, { "input": "10\n600386086 862479376 284190454 781950823 672077209 5753052 145701234 680334621 497013634 35429365", "output": "4565315854" }, { "input": "11\n183007351 103343359 164525146 698627979 388556391 926007595 483438978 580927711 659384363 201890880 920750904", "output": "5310460657" }, { "input": "12\n706692128 108170535 339831134 320333838 810063277 20284739 821176722 481520801 467848308 604388203 881959821 874133307", "output": "6436402813" }, { "input": "13\n525349200 54062222 810108418 237010994 821513756 409532178 158915465 87142595 630219037 770849718 843168738 617993222 504443485", "output": "6470309028" }, { "input": "14\n812998169 353860693 690443110 153688149 537992938 798779618 791624505 282706982 733654279 468319337 568341847 597888944 649703235 667623671", "output": "8107625477" }, { "input": "15\n336683946 299752380 865749098 775393009 959499824 893055762 365399057 419335880 896025008 575845364 529550764 341748859 30999793 464432689 19445239", "output": "7772916672" }, { "input": "16\n860368723 540615364 41056086 692070164 970950302 282304201 998108096 24957674 999460249 37279175 490759681 26673285 412295352 671298115 627182888 90740349", "output": "7766119704" }, { "input": "17\n148018692 545442539 980325266 313776023 687429485 376580345 40875544 925549764 161831978 144805202 451968598 475560904 262583806 468107133 60900936 281546097 912565045", "output": "7237867357" }, { "input": "18\n966674765 786305522 860659958 935480883 108937371 60800080 673584584 826142855 560238516 606238013 413177515 455456626 643879364 969943855 963609881 177380550 544192822 864797474", "output": "11417500634" }, { "input": "19\n490360541 496161402 330938242 852158038 120387849 686083328 247359135 431764649 427637949 8736336 843378328 435352349 494167818 766752874 161292122 368186298 470791896 813444279 170758124", "output": "8615711557" }, { "input": "20\n654616375 542649443 729213190 188364665 238384327 726353863 974350390 526804424 601329631 886592063 734805196 275562411 861801362 374466292 119830901 403120565 670982545 63210795 130397643 601611646", "output": "10304447727" }, { "input": "21\n942265343 252505322 904519178 810069524 954862509 115602302 548124942 132426218 999736168 584061682 696014113 960485837 712089816 581331718 317512142 593926314 302610323 716885305 477125514 813997503 535631456", "output": "12951783229" }, { "input": "22\n465951120 788339601 784853870 726746679 376370396 504849742 180834982 33019308 867135601 455551901 657223030 940381560 93386374 378140736 161286599 548696254 934237100 75589518 764917898 731412064 205669368 630662937", "output": "11305256638" }, { "input": "23\n989635897 498195481 255132154 643423835 387820874 894097181 223601429 228583694 265543138 153021520 618431947 684241474 943673829 174949754 358967839 444530707 801900686 965299835 347682577 648826625 406714384 129525158 958578251", "output": "12022378269" }, { "input": "24\n277285866 739058464 135466846 265129694 104300056 519381429 856310469 834204489 132942572 260547547 343605057 664137197 619941683 676786476 497713592 635336455 138557168 618975345 635474960 861212482 76752297 923357675 517046816 274123722", "output": "11607648357" }, { "input": "25\n95942939 979921447 310772834 181806850 525806942 613657573 194049213 734797579 531349109 721980358 304813974 113025815 470230137 473595494 695394833 590106396 770183946 567622150 218239639 778627043 41761505 127248600 134450869 860350034 901937574", "output": "11937672853" }, { "input": "26\n619627716 984748623 486078822 98484005 537257421 2906012 62795060 635390669 103777246 829506385 971050595 92921538 851525695 680460920 893076074 780912144 401811723 221297659 269996214 991012900 242806521 626109821 987889730 682613155 209557740 806895799", "output": "14070510187" }, { "input": "26\n10 1 20 2 23 3 14 6 7 13 26 21 11 8 16 25 12 15 19 9 17 22 24 18 5 4", "output": "351" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "5\n5 3 3 3 1", "output": "11" }, { "input": "5\n2 2 2 2 2", "output": "3" }, { "input": "10\n10 10 10 10 10 10 10 10 1 1", "output": "53" }, { "input": "10\n100 100 10 10 10 10 10 1 1 1", "output": "240" }, { "input": "6\n5 3 3 3 3 1", "output": "11" }, { "input": "4\n4 3 2 1", "output": "10" }, { "input": "5\n1 1 1 1 1", "output": "1" } ]
1,526,844,585
2,147,483,647
Python 3
OK
TESTS
57
78
0
n = input() v = input().split() v = map(int, v) v = list(v) oc = {} s = 0 for i, vi in enumerate(v): while(oc.get(vi,0) and vi > 0): vi -= 1 oc[vi] = oc.get(vi, 0) + 1 s += vi print(s)
Title: Making a String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. Input Specification: The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet. The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. Output Specification: Print a single integer — the maximum length of the string that meets all the requirements. Demo Input: ['3\n2 5 5\n', '3\n1 1 2\n'] Demo Output: ['11\n', '3\n'] Note: For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".
```python n = input() v = input().split() v = map(int, v) v = list(v) oc = {} s = 0 for i, vi in enumerate(v): while(oc.get(vi,0) and vi > 0): vi -= 1 oc[vi] = oc.get(vi, 0) + 1 s += vi print(s) ```
3
825
C
Multi-judge Solving
PROGRAMMING
1,600
[ "greedy", "implementation" ]
null
null
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge). Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it). Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*. With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces. Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another. Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109). The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
[ "3 3\n2 1 9\n", "4 20\n10 3 6 3\n" ]
[ "1\n", "0\n" ]
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second example he can solve every problem right from the start.
0
[ { "input": "3 3\n2 1 9", "output": "1" }, { "input": "4 20\n10 3 6 3", "output": "0" }, { "input": "1 1000000000\n1", "output": "0" }, { "input": "1 1\n3", "output": "1" }, { "input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82", "output": "0" }, { "input": "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 488 416 659 988 998 93 662 92 749 889 78 214 786 735 625 921 372 713 617 975 119 402 411 878 138 548 905 802 762 940 336 529 373 745 835 805 880 816 94 166 114 475 699 974 462 61 337 555 805 968 815 392 746 591 558 740 380 668 29 881 151 387 986 174 923 541 520 998 947 535 651 103 584 664 854 180 852 726 93", "output": "1" }, { "input": "2 1\n1 1000000000", "output": "29" }, { "input": "29 2\n1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911", "output": "27" }, { "input": "1 1\n1000000000", "output": "29" }, { "input": "7 6\n4 20 16 14 3 17 4", "output": "1" }, { "input": "2 1\n3 6", "output": "1" }, { "input": "1 1\n20", "output": "4" }, { "input": "5 2\n86 81 53 25 18", "output": "4" }, { "input": "4 1\n88 55 14 39", "output": "4" }, { "input": "3 1\n2 3 6", "output": "0" }, { "input": "3 2\n4 9 18", "output": "1" }, { "input": "5 3\n6 6 6 13 27", "output": "2" }, { "input": "5 1\n23 8 83 26 18", "output": "4" }, { "input": "3 1\n4 5 6", "output": "1" }, { "input": "3 1\n1 3 6", "output": "1" }, { "input": "1 1\n2", "output": "0" }, { "input": "3 2\n4 5 6", "output": "0" }, { "input": "5 1\n100 200 400 1000 2000", "output": "7" }, { "input": "2 1\n1 4", "output": "1" }, { "input": "4 1\n2 4 8 32", "output": "1" }, { "input": "2 10\n21 42", "output": "1" }, { "input": "3 3\n1 7 13", "output": "1" }, { "input": "3 1\n1 4 6", "output": "1" }, { "input": "2 2\n2 8", "output": "1" }, { "input": "1 1\n4", "output": "1" }, { "input": "2 2\n8 16", "output": "1" }, { "input": "3 1\n4 8 16", "output": "1" }, { "input": "3 1\n3 6 9", "output": "1" }, { "input": "2 1\n4 8", "output": "1" }, { "input": "2 2\n7 14", "output": "1" }, { "input": "1 4\n9", "output": "1" }, { "input": "5 3\n1024 4096 16384 65536 536870913", "output": "24" }, { "input": "2 5\n10 11", "output": "0" }, { "input": "2 2\n3 6", "output": "0" }, { "input": "2 2\n8 11", "output": "1" }, { "input": "3 19905705\n263637263 417905394 108361057", "output": "3" }, { "input": "4 25\n100 11 1 13", "output": "1" }, { "input": "10 295206008\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696", "output": "0" }, { "input": "4 2\n45 44 35 38", "output": "4" }, { "input": "1 2\n9", "output": "2" }, { "input": "3 6\n13 26 52", "output": "1" }, { "input": "9 30111088\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021", "output": "2" }, { "input": "3 72014068\n430005292 807436976 828082746", "output": "2" }, { "input": "3 165219745\n737649884 652879952 506420386", "output": "1" }, { "input": "2 60669400\n95037700 337255240", "output": "1" }, { "input": "4 28\n34 1 86 90", "output": "1" }, { "input": "2 1\n5 10", "output": "2" }, { "input": "2 1\n4 1000000000", "output": "28" }, { "input": "2 1\n2 3", "output": "0" }, { "input": "2 1\n3 5", "output": "1" }, { "input": "3 3\n1 5 20", "output": "1" }, { "input": "9 1\n1 2 4 9 15 32 64 128 1024", "output": "4" } ]
1,516,685,424
5,424
Python 3
WRONG_ANSWER
TESTS
5
62
5,632,000
n,k = map(int,input().split()) dif = list(map(int,input().split())) c = 0 for elem in dif: if elem>k*2: for elem1 in dif: if elem1*2>=elem and elem1!=elem: break elif elem1==dif[n-1]: c+=1 break print(c)
Title: Multi-judge Solving Time Limit: None seconds Memory Limit: None megabytes Problem Description: Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge). Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it). Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*. With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces. Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another. Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces. Input Specification: The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109). The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. Demo Input: ['3 3\n2 1 9\n', '4 20\n10 3 6 3\n'] Demo Output: ['1\n', '0\n'] Note: In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second example he can solve every problem right from the start.
```python n,k = map(int,input().split()) dif = list(map(int,input().split())) c = 0 for elem in dif: if elem>k*2: for elem1 in dif: if elem1*2>=elem and elem1!=elem: break elif elem1==dif[n-1]: c+=1 break print(c) ```
0
106
D
Treasure Island
PROGRAMMING
1,700
[ "brute force", "implementation" ]
D. Treasure Island
2
256
Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map. The treasure map can be represented as a rectangle *n*<=×<=*m* in size. Each cell stands for an islands' square (the square's side length equals to a mile). Some cells stand for the sea and they are impenetrable. All other cells are penetrable (i.e. available) and some of them contain local sights. For example, the large tree on the hills or the cave in the rocks. Besides, the map also has a set of *k* instructions. Each instruction is in the following form: "Walk *n* miles in the *y* direction" The possible directions are: north, south, east, and west. If you follow these instructions carefully (you should fulfill all of them, one by one) then you should reach exactly the place where treasures are buried. Unfortunately the captain doesn't know the place where to start fulfilling the instructions — as that very piece of the map was lost. But the captain very well remembers that the place contained some local sight. Besides, the captain knows that the whole way goes through the island's penetrable squares. The captain wants to know which sights are worth checking. He asks you to help him with that.
The first line contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Then follow *n* lines containing *m* integers each — the island map's description. "#" stands for the sea. It is guaranteed that all cells along the rectangle's perimeter are the sea. "." stands for a penetrable square without any sights and the sights are marked with uppercase Latin letters from "A" to "Z". Not all alphabet letters can be used. However, it is guaranteed that at least one of them is present on the map. All local sights are marked by different letters. The next line contains number *k* (1<=≤<=*k*<=≤<=105), after which *k* lines follow. Each line describes an instruction. Each instruction possesses the form "*dir* *len*", where *dir* stands for the direction and *len* stands for the length of the way to walk. *dir* can take values "N", "S", "W" and "E" for North, South, West and East correspondingly. At that, north is to the top, South is to the bottom, west is to the left and east is to the right. *len* is an integer from 1 to 1000.
Print all local sights that satisfy to the instructions as a string without any separators in the alphabetical order. If no sight fits, print "no solution" without the quotes.
[ "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2\n", "3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n" ]
[ "AD", "no solution" ]
none
2,000
[ { "input": "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2", "output": "AD" }, { "input": "3 4\n####\n#.A#\n####\n2\nW 1\nN 2", "output": "no solution" }, { "input": "10 10\n##########\n#K#..##..#\n##...ZB..#\n##.......#\n#D..#....#\n##...Y..##\n#...N...J#\n#.G...#.##\n#.S.I....#\n##########\n4\nE 2\nW 4\nS 3\nN 4", "output": "YZ" }, { "input": "17 19\n###################\n#K..##..##.#.Z.#.##\n#..#....#.......#Y#\n###.####..##...#.##\n###.##.S.I..#.J...#\n#...###.#.#...#.#.#\n###.....##.##.#.B.#\n###...#.....#.#...#\n#.#.#.##.#.##.#.#.#\n#...#...#...###.###\n##.###.#.#.##...#.#\n##..#...#G...##N#.#\n###..####.#.##.#..#\n#..#.#.....###.#.##\n#.#.#.#.#..##...#.#\n#...D.#..#..##..###\n###################\n10\nN 1\nN 1\nE 1\nS 3\nN 2\nW 5\nN 4\nS 2\nW 3\nN 3", "output": "no solution" }, { "input": "10 19\n###################\n#######QR..H#######\n#M##O...G....U#####\n#.##AK#Z.......##I#\n#L.#######Y.J.V##.#\n##..W######..#.#..#\n##.D.....N#..#..P##\n####.E.#...B..X####\n#T##F#####S...###C#\n###################\n14\nN 1\nE 3\nS 1\nE 4\nN 1\nS 5\nW 3\nN 1\nW 4\nS 1\nE 1\nN 1\nW 2\nN 1", "output": "AK" }, { "input": "6 6\n######\n#UPWT#\n#KJSL#\n#VCMA#\n#QOGB#\n######\n5\nN 1\nW 1\nS 1\nE 1\nN 1", "output": "ABCGJLMOS" }, { "input": "3 3\n###\n#A#\n###\n1\nN 1", "output": "no solution" }, { "input": "7 8\n########\n#..#O.##\n##U#YTI#\n##.#####\n##R.E.P#\n###W#Q##\n########\n2\nN 1\nW 1", "output": "QTUW" }, { "input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nE 3", "output": "C" }, { "input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nW 3", "output": "F" }, { "input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nS 1", "output": "ABCDEF" }, { "input": "9 4\n####\n#AB#\n#C.#\n##.#\n#D.#\n#E.#\n#F.#\n#G.#\n####\n1\nN 3", "output": "G" }, { "input": "9 4\n####\n#AB#\n#C.#\n##.#\n#D.#\n#E.#\n#F.#\n#G.#\n####\n1\nS 3", "output": "BD" }, { "input": "10 11\n###########\n#.F.#.P.###\n#..#.#....#\n#Y#.U....##\n##....#...#\n##.OV.NK#.#\n#H####.#EA#\n#R.#....###\n##..#MS.D##\n###########\n3\nW 2\nE 1\nN 1", "output": "DNV" }, { "input": "17 16\n################\n######..#..##.##\n#A#U..##..###.##\n#.#.##.######.##\n#TZ#K.#G.#.###.#\n#..L##.#.#.D...#\n##J##..W###.#..#\n####.#.N.###.###\n#..###..##.#..##\n#.O.#.#.#S..#.##\n####.#.####.##.#\n#.B#####X..#####\n#..####.##.#..##\n#.#...M##.#.#..#\n##E####RV####..#\n##....#.##...#Q#\n################\n5\nE 1\nW 1\nE 2\nW 1\nW 1", "output": "DSUX" }, { "input": "20 20\n####################\n#.#.#.####.#.###.###\n##.###...#..##.###.#\n##.##.##..####..####\n#.....######...#####\n##.##.#..###.#.#####\n#####..##.##.X.....#\n#####.....#T....##.#\n##.##.#....###...#.#\n##.#W....###.##.#.##\n####.#FA....##..#.##\n##...##.#.#...######\n###M........#.##.###\n#...##...##.#..###.#\n#.H....#..V....###.#\n#######Y......###..#\n##.#####.###..###..#\n##.#####.###.#######\n#.###.###..U....####\n####################\n5\nE 1\nE 3\nW 3\nN 3\nE 1", "output": "AFHMTUVWXY" }, { "input": "20 20\n####################\n############.####.##\n#######..####..#####\n######............##\n######.....#...###.#\n#####E..........##.#\n#.##.#.........#####\n##NR....KO.....#####\n##B........#...#####\n#Y.W...H.......#####\n#####Z.....#...#####\n######...#.#...#####\n#A.......#.#...#####\n######.....#...#####\n####.#...#.#.#####.#\n######.#.#.#.#######\n######.###.#########\n######.###.#########\n#..###.#############\n####################\n10\nE 5\nS 1\nS 5\nN 2\nN 4\nN 5\nS 1\nE 3\nW 1\nW 3", "output": "ABHKNORWYZ" } ]
1,659,556,407
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
19
2,000
18,432,000
n,m=map(int,input().split()) q=[] for i in range(n): q+=[input()] k=int(input()) w=[] for i in range(k): w+=[input().split()] w[-1][1]=int(w[-1][1]) N=[[0]*m for i in range(n)] S=[[0]*m for i in range(n)] E=[[0]*m for i in range(n)] W=[[0]*m for i in range(n)] r=0 for i in range(n): for j in range(m): W[i][j]=r if q[i][j]=="#": r=0 else: r+=1 r=0 for j in range(m): for i in range(n): N[i][j]=r if q[i][j]=="#": r=0 else: r+=1 r=0 for i in range(n): for j in range(m-1,-1,-1): E[i][j]=r if q[i][j]=="#": r=0 else: r+=1 r=0 for j in range(m): for i in range(n-1,-1,-1): S[i][j]=r if q[i][j]=="#": r=0 else: r+=1 def check(x,y,d,s): if d=="N": if x-s<0 or N[x][y]<s: return False return True elif d=="S": if x+s>=n or S[x][y]<s: return False return True elif d=="W": if y-s<0 or W[x][y]<s: return False return True else: if y+s>=m or E[x][y]<s: return False return True def update(x,y,d,s): if d=="N": return (x-s,y) elif d=="S": return (x+s,y) elif d=="E": return (x,y+s) else: return (x,y-s) ans="" for i in range(n): for j in range(m): if q[i][j] not in "#.": x,y=i,j t=1 for l in range(k): if check(x,y,w[l][0],w[l][1]): x,y=update(x,y,w[l][0],w[l][1]) else: t=0 break if t: ans+=q[i][j] if ans: print("".join(sorted(ans))) else: print("no solution")
Title: Treasure Island Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map. The treasure map can be represented as a rectangle *n*<=×<=*m* in size. Each cell stands for an islands' square (the square's side length equals to a mile). Some cells stand for the sea and they are impenetrable. All other cells are penetrable (i.e. available) and some of them contain local sights. For example, the large tree on the hills or the cave in the rocks. Besides, the map also has a set of *k* instructions. Each instruction is in the following form: "Walk *n* miles in the *y* direction" The possible directions are: north, south, east, and west. If you follow these instructions carefully (you should fulfill all of them, one by one) then you should reach exactly the place where treasures are buried. Unfortunately the captain doesn't know the place where to start fulfilling the instructions — as that very piece of the map was lost. But the captain very well remembers that the place contained some local sight. Besides, the captain knows that the whole way goes through the island's penetrable squares. The captain wants to know which sights are worth checking. He asks you to help him with that. Input Specification: The first line contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Then follow *n* lines containing *m* integers each — the island map's description. "#" stands for the sea. It is guaranteed that all cells along the rectangle's perimeter are the sea. "." stands for a penetrable square without any sights and the sights are marked with uppercase Latin letters from "A" to "Z". Not all alphabet letters can be used. However, it is guaranteed that at least one of them is present on the map. All local sights are marked by different letters. The next line contains number *k* (1<=≤<=*k*<=≤<=105), after which *k* lines follow. Each line describes an instruction. Each instruction possesses the form "*dir* *len*", where *dir* stands for the direction and *len* stands for the length of the way to walk. *dir* can take values "N", "S", "W" and "E" for North, South, West and East correspondingly. At that, north is to the top, South is to the bottom, west is to the left and east is to the right. *len* is an integer from 1 to 1000. Output Specification: Print all local sights that satisfy to the instructions as a string without any separators in the alphabetical order. If no sight fits, print "no solution" without the quotes. Demo Input: ['6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2\n', '3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n'] Demo Output: ['AD', 'no solution'] Note: none
```python n,m=map(int,input().split()) q=[] for i in range(n): q+=[input()] k=int(input()) w=[] for i in range(k): w+=[input().split()] w[-1][1]=int(w[-1][1]) N=[[0]*m for i in range(n)] S=[[0]*m for i in range(n)] E=[[0]*m for i in range(n)] W=[[0]*m for i in range(n)] r=0 for i in range(n): for j in range(m): W[i][j]=r if q[i][j]=="#": r=0 else: r+=1 r=0 for j in range(m): for i in range(n): N[i][j]=r if q[i][j]=="#": r=0 else: r+=1 r=0 for i in range(n): for j in range(m-1,-1,-1): E[i][j]=r if q[i][j]=="#": r=0 else: r+=1 r=0 for j in range(m): for i in range(n-1,-1,-1): S[i][j]=r if q[i][j]=="#": r=0 else: r+=1 def check(x,y,d,s): if d=="N": if x-s<0 or N[x][y]<s: return False return True elif d=="S": if x+s>=n or S[x][y]<s: return False return True elif d=="W": if y-s<0 or W[x][y]<s: return False return True else: if y+s>=m or E[x][y]<s: return False return True def update(x,y,d,s): if d=="N": return (x-s,y) elif d=="S": return (x+s,y) elif d=="E": return (x,y+s) else: return (x,y-s) ans="" for i in range(n): for j in range(m): if q[i][j] not in "#.": x,y=i,j t=1 for l in range(k): if check(x,y,w[l][0],w[l][1]): x,y=update(x,y,w[l][0],w[l][1]) else: t=0 break if t: ans+=q[i][j] if ans: print("".join(sorted(ans))) else: print("no solution") ```
0
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "output": "NO" }, { "input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555", "output": "NO" }, { "input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333", "output": "NO" }, { "input": "5 5\n88888\n44444\n66666\n55555\n88888", "output": "YES" }, { "input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222", "output": "YES" }, { "input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888", "output": "YES" }, { "input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4", "output": "YES" }, { "input": "1 1\n2", "output": "YES" }, { "input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111", "output": "NO" }, { "input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0", "output": "YES" } ]
1,592,714,738
338
PyPy 3
OK
TESTS
35
280
0
class A: def solve(self): [n, m] = [int(x) for x in input().split(" ")] flag = [] for i in range(n): flag.append(input()) if any([len(set(x)) != 1 for x in flag]): print("NO") return first_colors = [x[0] for x in flag] if any([x == y for x, y in zip(first_colors, first_colors[1:])]): print("NO") return print("YES") A().solve()
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. Input Specification: The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. Output Specification: Output YES, if the flag meets the new ISO standard, and NO otherwise. Demo Input: ['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python class A: def solve(self): [n, m] = [int(x) for x in input().split(" ")] flag = [] for i in range(n): flag.append(input()) if any([len(set(x)) != 1 for x in flag]): print("NO") return first_colors = [x[0] for x in flag] if any([x == y for x, y in zip(first_colors, first_colors[1:])]): print("NO") return print("YES") A().solve() ```
3.93
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "input": "6 5\naaccdd", "output": "d" }, { "input": "2 1\nzz", "output": "z" }, { "input": "14 5\nhxehmvkybeklnj", "output": "xmvkyklnj" } ]
1,640,667,392
2,147,483,647
Python 3
OK
TESTS
44
436
26,624,000
n, k = map(int, input().split()) s=[*input()] a = sorted([(x, y) for y, x in enumerate(s)]) for i in range(k): s[a[i][1]] = "" print("".join(s))
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string. Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters. Output Specification: Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Demo Input: ['15 3\ncccaabababaccbc\n', '15 9\ncccaabababaccbc\n', '1 1\nu\n'] Demo Output: ['cccbbabaccbc\n', 'cccccc\n', ''] Note: none
```python n, k = map(int, input().split()) s=[*input()] a = sorted([(x, y) for y, x in enumerate(s)]) for i in range(k): s[a[i][1]] = "" print("".join(s)) ```
3
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "input": "2 2\n20 10", "output": "1" }, { "input": "2 1\n20 1", "output": "2" }, { "input": "3 1\n1 2 3", "output": "1" }, { "input": "3 1\n2 1 3", "output": "2" }, { "input": "3 1\n3 2 1", "output": "3" }, { "input": "3 2\n1 2 3", "output": "1" }, { "input": "3 2\n3 2 1", "output": "2" }, { "input": "3 3\n1 2 3", "output": "1" }, { "input": "4 2\n9 8 11 7", "output": "1" }, { "input": "4 2\n10 1 2 3", "output": "2" }, { "input": "6 3\n56 56 56 2 1 2", "output": "4" }, { "input": "8 3\n1 1 1 1 2 60 90 1", "output": "1" }, { "input": "4 1\n1 5 2 2", "output": "1" }, { "input": "4 2\n4 6 7 4", "output": "1" }, { "input": "10 4\n1 1 1 4 4 4 4 4 4 3", "output": "1" }, { "input": "6 3\n1 2 1 3 1 1", "output": "1" }, { "input": "5 2\n100 100 100 1 1", "output": "4" } ]
1,680,278,534
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
21
1,000
19,148,800
n, k = map(int, input().split()) fence = list(map(int, input().split())) min = (k*100)+1 pos = 0 x = fence[0] if fence.count(x) == n: print(1) else: i = 0 end = False while i < ((n-k)+1) and end == False: sum = 0 j = i for j in range(i,k+i): sum += fence[j] if sum == k: pos = i+1 end = True elif sum < min: min = sum pos = i+1 i += 1 print(pos)
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). Input Specification: The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. Output Specification: Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. Demo Input: ['7 3\n1 2 6 1 1 7 1\n'] Demo Output: ['3\n'] Note: In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
```python n, k = map(int, input().split()) fence = list(map(int, input().split())) min = (k*100)+1 pos = 0 x = fence[0] if fence.count(x) == n: print(1) else: i = 0 end = False while i < ((n-k)+1) and end == False: sum = 0 j = i for j in range(i,k+i): sum += fence[j] if sum == k: pos = i+1 end = True elif sum < min: min = sum pos = i+1 i += 1 print(pos) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,665,688,169
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
4,198,400
n,m,a = map(int, input().split()) if (n*m)%(a*a): print((n*m)//(a*a) + 1) else: print( (n*m)//(a*a) )
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,a = map(int, input().split()) if (n*m)%(a*a): print((n*m)//(a*a) + 1) else: print( (n*m)//(a*a) ) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,673,851,231
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
import math def theatresquare(n: int,m: int,a: int): width=math.ceil(m/a) hight=math.ceil(n/a) if(m%a and n%a !=0): print(width*hight) else: print((m/a)*(n/a)) n=int(input()) m=int(input()) a=int(input()) theatresquare(n,m,a)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python import math def theatresquare(n: int,m: int,a: int): width=math.ceil(m/a) hight=math.ceil(n/a) if(m%a and n%a !=0): print(width*hight) else: print((m/a)*(n/a)) n=int(input()) m=int(input()) a=int(input()) theatresquare(n,m,a) ```
-1
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,637,082,669
2,147,483,647
Python 3
OK
TESTS
30
92
0
rer = input() a=0 c=0 for b in rer : if ord (b)>=ord('A') and ord (b)<= ord('Z'): a=a+1 else: c=c+1 if a>c: rer=rer.upper() if c>=a: rer=rer.lower() print(rer)
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 rer = input() a=0 c=0 for b in rer : if ord (b)>=ord('A') and ord (b)<= ord('Z'): a=a+1 else: c=c+1 if a>c: rer=rer.upper() if c>=a: rer=rer.lower() print(rer) ```
3.977
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,690,216,124
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n, m, a = map(int, input().split()) num_flagstones_n = math.ceil(n / a) num_flagstones_m = math.ceil(m / a) print(num_flagstones_n * num_flagstones_m)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n, m, a = map(int, input().split()) num_flagstones_n = math.ceil(n / a) num_flagstones_m = math.ceil(m / a) print(num_flagstones_n * num_flagstones_m) ```
-1
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,670,776,594
2,147,483,647
Python 3
OK
TESTS
20
46
0
n=int(input()) for i in range(n): l=input() s="" a=0 if len(l)>10: for j in range(len(l)-2): a+=1 s=s+l[0]+str(a)+l[len(l)-1] print(s) else: print(l)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n=int(input()) for i in range(n): l=input() s="" a=0 if len(l)>10: for j in range(len(l)-2): a+=1 s=s+l[0]+str(a)+l[len(l)-1] print(s) else: print(l) ```
3.977
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0.
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output": "1\n1 2 3" }, { "input": "12\n3 3 3 3 3 3 3 3 1 3 3 2", "output": "1\n9 12 2" }, { "input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2", "output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47" }, { "input": "12\n3 1 1 1 1 1 1 2 1 1 1 1", "output": "1\n3 8 1" }, { "input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2", "output": "1\n18 2 11" }, { "input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3", "output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36" }, { "input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1", "output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200" }, { "input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3", "output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64" }, { "input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1", "output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44" }, { "input": "5\n1 2 2 3 3", "output": "1\n1 3 4" } ]
1,667,135,902
2,147,483,647
Python 3
OK
TESTS
41
46
0
input() a=[[],[],[]] for i, x in enumerate(input().split(),1): a[int(x)-1]+=[i] print(min(map(len,a))) for x in zip(*a):print(*x)
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. Output Specification: In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0. Demo Input: ['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n'] Demo Output: ['2\n3 5 2\n6 7 4\n', '0\n'] Note: none
```python input() a=[[],[],[]] for i, x in enumerate(input().split(),1): a[int(x)-1]+=[i] print(min(map(len,a))) for x in zip(*a):print(*x) ```
3
44
I
Toys
PROGRAMMING
2,300
[ "brute force", "combinatorics" ]
I. Toys
5
256
Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her *n* toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still can't calm Masha down and mom is going to come home soon and punish Sasha for having made Masha crying. That's why he decides to restore the piles' arrangement. However, he doesn't remember at all the way the toys used to lie. Of course, Masha remembers it, but she can't talk yet and can only help Sasha by shouting happily when he arranges the toys in the way they used to lie. That means that Sasha will have to arrange the toys in every possible way until Masha recognizes the needed arrangement. The relative position of the piles and toys in every pile is irrelevant, that's why the two ways of arranging the toys are considered different if can be found two such toys that when arranged in the first way lie in one and the same pile and do not if arranged in the second way. Sasha is looking for the fastest way of trying all the ways because mom will come soon. With every action Sasha can take a toy from any pile and move it to any other pile (as a result a new pile may appear or the old one may disappear). Sasha wants to find the sequence of actions as a result of which all the pile arrangement variants will be tried exactly one time each. Help Sasha. As we remember, initially all the toys are located in one pile.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=10) — the number of toys.
In the first line print the number of different variants of arrangement of toys into piles. Then print all the ways of arranging toys into piles in the order in which Sasha should try them (i.e. every next way must result from the previous one through the operation described in the statement). Every way should be printed in the following format. In every pile the toys should be arranged in ascending order of the numbers. Then the piles should be sorted in ascending order of the numbers of the first toys there. Output every way on a single line. Cf. the example to specify the output data format. If the solution is not unique, output any of them.
[ "3\n" ]
[ "5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}" ]
none
0
[ { "input": "3", "output": "5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}" }, { "input": "1", "output": "1\n{1}" }, { "input": "2", "output": "2\n{1,2}\n{1},{2}" }, { "input": "4", "output": "15\n{1,2,3,4}\n{1,2,3},{4}\n{1,2},{3,4}\n{1,2},{3},{4}\n{1,2,4},{3}\n{1,4},{2,3}\n{1},{2,3},{4}\n{1},{2,3,4}\n{1},{2,4},{3}\n{1},{2},{3,4}\n{1},{2},{3},{4}\n{1,4},{2},{3}\n{1,3,4},{2}\n{1,3},{2},{4}\n{1,3},{2,4}" }, { "input": "5", "output": "52\n{1,2,3,4,5}\n{1,2,3,4},{5}\n{1,2,3},{4,5}\n{1,2,3},{4},{5}\n{1,2,3,5},{4}\n{1,2,5},{3,4}\n{1,2},{3,4},{5}\n{1,2},{3,4,5}\n{1,2},{3,5},{4}\n{1,2},{3},{4,5}\n{1,2},{3},{4},{5}\n{1,2,5},{3},{4}\n{1,2,4,5},{3}\n{1,2,4},{3},{5}\n{1,2,4},{3,5}\n{1,4},{2,3,5}\n{1,4},{2,3},{5}\n{1,4,5},{2,3}\n{1,5},{2,3},{4}\n{1},{2,3},{4},{5}\n{1},{2,3},{4,5}\n{1},{2,3,5},{4}\n{1},{2,3,4,5}\n{1},{2,3,4},{5}\n{1,5},{2,3,4}\n{1,5},{2,4},{3}\n{1},{2,4},{3},{5}\n{1},{2,4},{3,5}\n{1},{2,4,5},{3}\n{1},{2,5},{3,4}\n{1},{2},{3,4,5}\n..." }, { "input": "6", "output": "203\n{1,2,3,4,5,6}\n{1,2,3,4,5},{6}\n{1,2,3,4},{5,6}\n{1,2,3,4},{5},{6}\n{1,2,3,4,6},{5}\n{1,2,3,6},{4,5}\n{1,2,3},{4,5},{6}\n{1,2,3},{4,5,6}\n{1,2,3},{4,6},{5}\n{1,2,3},{4},{5,6}\n{1,2,3},{4},{5},{6}\n{1,2,3,6},{4},{5}\n{1,2,3,5,6},{4}\n{1,2,3,5},{4},{6}\n{1,2,3,5},{4,6}\n{1,2,5},{3,4,6}\n{1,2,5},{3,4},{6}\n{1,2,5,6},{3,4}\n{1,2,6},{3,4},{5}\n{1,2},{3,4},{5},{6}\n{1,2},{3,4},{5,6}\n{1,2},{3,4,6},{5}\n{1,2},{3,4,5,6}\n{1,2},{3,4,5},{6}\n{1,2,6},{3,4,5}\n{1,2,6},{3,5},{4}\n{1,2},{3,5},{4},{6}\n{1,2},{3,5},{..." }, { "input": "7", "output": "877\n{1,2,3,4,5,6,7}\n{1,2,3,4,5,6},{7}\n{1,2,3,4,5},{6,7}\n{1,2,3,4,5},{6},{7}\n{1,2,3,4,5,7},{6}\n{1,2,3,4,7},{5,6}\n{1,2,3,4},{5,6},{7}\n{1,2,3,4},{5,6,7}\n{1,2,3,4},{5,7},{6}\n{1,2,3,4},{5},{6,7}\n{1,2,3,4},{5},{6},{7}\n{1,2,3,4,7},{5},{6}\n{1,2,3,4,6,7},{5}\n{1,2,3,4,6},{5},{7}\n{1,2,3,4,6},{5,7}\n{1,2,3,6},{4,5,7}\n{1,2,3,6},{4,5},{7}\n{1,2,3,6,7},{4,5}\n{1,2,3,7},{4,5},{6}\n{1,2,3},{4,5},{6},{7}\n{1,2,3},{4,5},{6,7}\n{1,2,3},{4,5,7},{6}\n{1,2,3},{4,5,6,7}\n{1,2,3},{4,5,6},{7}\n{1,2,3,7},{4,5,6}\n{1,..." }, { "input": "8", "output": "4140\n{1,2,3,4,5,6,7,8}\n{1,2,3,4,5,6,7},{8}\n{1,2,3,4,5,6},{7,8}\n{1,2,3,4,5,6},{7},{8}\n{1,2,3,4,5,6,8},{7}\n{1,2,3,4,5,8},{6,7}\n{1,2,3,4,5},{6,7},{8}\n{1,2,3,4,5},{6,7,8}\n{1,2,3,4,5},{6,8},{7}\n{1,2,3,4,5},{6},{7,8}\n{1,2,3,4,5},{6},{7},{8}\n{1,2,3,4,5,8},{6},{7}\n{1,2,3,4,5,7,8},{6}\n{1,2,3,4,5,7},{6},{8}\n{1,2,3,4,5,7},{6,8}\n{1,2,3,4,7},{5,6,8}\n{1,2,3,4,7},{5,6},{8}\n{1,2,3,4,7,8},{5,6}\n{1,2,3,4,8},{5,6},{7}\n{1,2,3,4},{5,6},{7},{8}\n{1,2,3,4},{5,6},{7,8}\n{1,2,3,4},{5,6,8},{7}\n{1,2,3,4},{5,6,7,..." }, { "input": "9", "output": "21147\n{1,2,3,4,5,6,7,8,9}\n{1,2,3,4,5,6,7,8},{9}\n{1,2,3,4,5,6,7},{8,9}\n{1,2,3,4,5,6,7},{8},{9}\n{1,2,3,4,5,6,7,9},{8}\n{1,2,3,4,5,6,9},{7,8}\n{1,2,3,4,5,6},{7,8},{9}\n{1,2,3,4,5,6},{7,8,9}\n{1,2,3,4,5,6},{7,9},{8}\n{1,2,3,4,5,6},{7},{8,9}\n{1,2,3,4,5,6},{7},{8},{9}\n{1,2,3,4,5,6,9},{7},{8}\n{1,2,3,4,5,6,8,9},{7}\n{1,2,3,4,5,6,8},{7},{9}\n{1,2,3,4,5,6,8},{7,9}\n{1,2,3,4,5,8},{6,7,9}\n{1,2,3,4,5,8},{6,7},{9}\n{1,2,3,4,5,8,9},{6,7}\n{1,2,3,4,5,9},{6,7},{8}\n{1,2,3,4,5},{6,7},{8},{9}\n{1,2,3,4,5},{6,7},{8,9..." }, { "input": "10", "output": "115975\n{1,2,3,4,5,6,7,8,9,10}\n{1,2,3,4,5,6,7,8,9},{10}\n{1,2,3,4,5,6,7,8},{9,10}\n{1,2,3,4,5,6,7,8},{9},{10}\n{1,2,3,4,5,6,7,8,10},{9}\n{1,2,3,4,5,6,7,10},{8,9}\n{1,2,3,4,5,6,7},{8,9},{10}\n{1,2,3,4,5,6,7},{8,9,10}\n{1,2,3,4,5,6,7},{8,10},{9}\n{1,2,3,4,5,6,7},{8},{9,10}\n{1,2,3,4,5,6,7},{8},{9},{10}\n{1,2,3,4,5,6,7,10},{8},{9}\n{1,2,3,4,5,6,7,9,10},{8}\n{1,2,3,4,5,6,7,9},{8},{10}\n{1,2,3,4,5,6,7,9},{8,10}\n{1,2,3,4,5,6,9},{7,8,10}\n{1,2,3,4,5,6,9},{7,8},{10}\n{1,2,3,4,5,6,9,10},{7,8}\n{1,2,3,4,5,6,10},{7..." } ]
1,675,682,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
from itertools import permutations x = int(input()) l = list(permutations(range(1, x))) print(len(l))
Title: Toys Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her *n* toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still can't calm Masha down and mom is going to come home soon and punish Sasha for having made Masha crying. That's why he decides to restore the piles' arrangement. However, he doesn't remember at all the way the toys used to lie. Of course, Masha remembers it, but she can't talk yet and can only help Sasha by shouting happily when he arranges the toys in the way they used to lie. That means that Sasha will have to arrange the toys in every possible way until Masha recognizes the needed arrangement. The relative position of the piles and toys in every pile is irrelevant, that's why the two ways of arranging the toys are considered different if can be found two such toys that when arranged in the first way lie in one and the same pile and do not if arranged in the second way. Sasha is looking for the fastest way of trying all the ways because mom will come soon. With every action Sasha can take a toy from any pile and move it to any other pile (as a result a new pile may appear or the old one may disappear). Sasha wants to find the sequence of actions as a result of which all the pile arrangement variants will be tried exactly one time each. Help Sasha. As we remember, initially all the toys are located in one pile. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=10) — the number of toys. Output Specification: In the first line print the number of different variants of arrangement of toys into piles. Then print all the ways of arranging toys into piles in the order in which Sasha should try them (i.e. every next way must result from the previous one through the operation described in the statement). Every way should be printed in the following format. In every pile the toys should be arranged in ascending order of the numbers. Then the piles should be sorted in ascending order of the numbers of the first toys there. Output every way on a single line. Cf. the example to specify the output data format. If the solution is not unique, output any of them. Demo Input: ['3\n'] Demo Output: ['5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}'] Note: none
```python from itertools import permutations x = int(input()) l = list(permutations(range(1, x))) print(len(l)) ```
0
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "3754606979" }, { "input": "99999999999999999", "output": "50000000000000000" }, { "input": "21", "output": "11" }, { "input": "712394453192", "output": "712394453193" }, { "input": "172212168", "output": "172212169" }, { "input": "822981260158260519", "output": "411490630079130260" }, { "input": "28316250877914571", "output": "14158125438957286" }, { "input": "779547116602436424", "output": "779547116602436425" }, { "input": "578223540024979436", "output": "578223540024979437" }, { "input": "335408917861648766", "output": "335408917861648767" }, { "input": "74859962623690078", "output": "74859962623690079" }, { "input": "252509054433933439", "output": "126254527216966720" }, { "input": "760713016476190622", "output": "760713016476190623" }, { "input": "919845426262703496", "output": "919845426262703497" }, { "input": "585335723211047194", "output": "585335723211047195" }, { "input": "522842184971407769", "output": "261421092485703885" }, { "input": "148049062628894320", "output": "148049062628894321" }, { "input": "84324828731963974", "output": "84324828731963975" }, { "input": "354979173822804781", "output": "177489586911402391" }, { "input": "1312150450968413", "output": "656075225484207" }, { "input": "269587449430302150", "output": "269587449430302151" }, { "input": "645762258982631926", "output": "645762258982631927" }, { "input": "615812229161735895", "output": "307906114580867948" }, { "input": "0", "output": "0" }, { "input": "349993004923078531", "output": "174996502461539266" }, { "input": "891351282707723851", "output": "445675641353861926" }, { "input": "563324731189330734", "output": "563324731189330735" }, { "input": "520974001910286909", "output": "260487000955143455" }, { "input": "666729339802329204", "output": "666729339802329205" }, { "input": "856674611404539671", "output": "428337305702269836" }, { "input": "791809296303238499", "output": "395904648151619250" }, { "input": "711066337317063338", "output": "711066337317063339" }, { "input": "931356503492686566", "output": "931356503492686567" }, { "input": "234122432773361866", "output": "234122432773361867" }, { "input": "1000000000000000000", "output": "1000000000000000001" }, { "input": "1", "output": "1" }, { "input": "2", "output": "3" }, { "input": "7", "output": "4" }, { "input": "63", "output": "32" }, { "input": "24", "output": "25" }, { "input": "8", "output": "9" }, { "input": "15", "output": "8" } ]
1,656,697,049
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
28
108
512,000
s = int(input()) m = s+1 if m % 2 : print(m) else:print(m//2)
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? Input Specification: A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. Output Specification: A single integer — the number of straight cuts Shiro needs. Demo Input: ['3\n', '4\n'] Demo Output: ['2', '5'] Note: To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
```python s = int(input()) m = s+1 if m % 2 : print(m) else:print(m//2) ```
0
867
A
Between the Offices
PROGRAMMING
800
[ "implementation" ]
null
null
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).
[ "4\nFSSF\n", "2\nSF\n", "10\nFFFFFFFFFF\n", "10\nSSFFSFFSFF\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
500
[ { "input": "4\nFSSF", "output": "NO" }, { "input": "2\nSF", "output": "YES" }, { "input": "10\nFFFFFFFFFF", "output": "NO" }, { "input": "10\nSSFFSFFSFF", "output": "YES" }, { "input": "20\nSFSFFFFSSFFFFSSSSFSS", "output": "NO" }, { "input": "20\nSSFFFFFSFFFFFFFFFFFF", "output": "YES" }, { "input": "20\nSSFSFSFSFSFSFSFSSFSF", "output": "YES" }, { "input": "20\nSSSSFSFSSFSFSSSSSSFS", "output": "NO" }, { "input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF", "output": "NO" }, { "input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF", "output": "YES" }, { "input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS", "output": "NO" }, { "input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS", "output": "NO" }, { "input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS", "output": "NO" }, { "input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS", "output": "NO" }, { "input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF", "output": "YES" }, { "input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF", "output": "YES" }, { "input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF", "output": "YES" }, { "input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF", "output": "YES" }, { "input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF", "output": "YES" }, { "input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF", "output": "YES" }, { "input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF", "output": "YES" }, { "input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "2\nSS", "output": "NO" } ]
1,562,326,415
2,147,483,647
Python 3
OK
TESTS
34
249
1,638,400
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n=I() s=S() stof=0 ftos=0 for i in range(n-1): if s[i]!=s[i+1]: if s[i]=='S': stof+=1 else: ftos+=1 if stof>ftos: return 'YES' return 'NO' print(main())
Title: Between the Offices Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. Input Specification: The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. Output Specification: Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n=I() s=S() stof=0 ftos=0 for i in range(n-1): if s[i]!=s[i+1]: if s[i]=='S': stof+=1 else: ftos+=1 if stof>ftos: return 'YES' return 'NO' print(main()) ```
3
1,004
B
Sonya and Exhibition
PROGRAMMING
1,300
[ "constructive algorithms", "greedy", "implementation", "math" ]
null
null
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily. She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies. Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
[ "5 3\n1 3\n2 4\n2 5\n", "6 3\n5 6\n1 4\n4 6\n" ]
[ "01100", "110010" ]
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$. The total beauty is equal to $2+2+4=8$. In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions; - in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$. The total beauty is equal to $1+4+2=7$.
1,000
[ { "input": "5 3\n1 3\n2 4\n2 5", "output": "01010" }, { "input": "6 3\n5 6\n1 4\n4 6", "output": "010101" }, { "input": "10 4\n3 3\n1 6\n9 9\n10 10", "output": "0101010101" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "6 2\n1 6\n1 4", "output": "010101" }, { "input": "2 1\n1 2", "output": "01" } ]
1,530,810,459
1,959
Python 3
WRONG_ANSWER
PRETESTS
1
109
0
def beauty(distances, constelation): beat = 0 for left, right in distances: lilies = 0 roses = 0 for i in range(left - 1, right): if constelation[i] == "0": lilies += 1 else: roses += 1 beat += lilies * roses return beat flowers, visitors = map(int, input().split(" ")) left_right = [] constelation = "0" * flowers for i in range(visitors): left_right.append(list(map(int, input().split(" ")))) b = 0 for i in range(flowers): new_constelation = constelation[:i] + "1" + constelation[i + 1:] new_b = beauty(left_right, new_constelation) if new_b > b: constelation = new_constelation[:] b = new_b print(constelation)
Title: Sonya and Exhibition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily. She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies. Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. Input Specification: The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. Output Specification: Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any. Demo Input: ['5 3\n1 3\n2 4\n2 5\n', '6 3\n5 6\n1 4\n4 6\n'] Demo Output: ['01100', '110010'] Note: In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$. The total beauty is equal to $2+2+4=8$. In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions; - in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$. The total beauty is equal to $1+4+2=7$.
```python def beauty(distances, constelation): beat = 0 for left, right in distances: lilies = 0 roses = 0 for i in range(left - 1, right): if constelation[i] == "0": lilies += 1 else: roses += 1 beat += lilies * roses return beat flowers, visitors = map(int, input().split(" ")) left_right = [] constelation = "0" * flowers for i in range(visitors): left_right.append(list(map(int, input().split(" ")))) b = 0 for i in range(flowers): new_constelation = constelation[:i] + "1" + constelation[i + 1:] new_b = beauty(left_right, new_constelation) if new_b > b: constelation = new_constelation[:] b = new_b print(constelation) ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,566,472,732
2,147,483,647
Python 3
OK
TESTS
102
124
0
s1=input();s2=input(); for x,y in zip(s1,s2): print('1' if x!=y else '0',end='') print()
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 s1=input();s2=input(); for x,y in zip(s1,s2): print('1' if x!=y else '0',end='') print() ```
3.969
612
B
HDD is Outdated Technology
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file. Find the time need to read file split to *n* fragments. The *i*-th sector contains the *f**i*-th fragment of the file (1<=≤<=*f**i*<=≤<=*n*). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the *n*-th fragment is read. The fragments are read in the order from the first to the *n*-th. It takes |*a*<=-<=*b*| time units to move the magnetic head from the sector *a* to the sector *b*. Reading a fragment takes no time.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments. The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector.
Print the only integer — the number of time units needed to read the file.
[ "3\n3 1 2\n", "5\n1 3 5 4 2\n" ]
[ "3\n", "10\n" ]
In the second example the head moves in the following way: - 1-&gt;2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2-&gt;3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3-&gt;4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units - 4-&gt;5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units So the answer to the second example is 4 + 3 + 2 + 1 = 10.
0
[ { "input": "3\n3 1 2", "output": "3" }, { "input": "5\n1 3 5 4 2", "output": "10" }, { "input": "1\n1", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "40" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "10\n1 3 5 7 9 10 8 6 4 2", "output": "45" }, { "input": "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98", "output": "3580" }, { "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": "99" }, { "input": "100\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2", "output": "4950" } ]
1,693,745,259
2,147,483,647
PyPy 3
OK
TESTS
24
233
18,841,600
n = int(input()) arr = [None] * n L = list(map(int, input().split())) for k, v in enumerate(L): arr[v - 1] = k res = 0 for i in range(n - 1): res += abs(arr[i] - arr[i + 1]) print(res)
Title: HDD is Outdated Technology Time Limit: None seconds Memory Limit: None megabytes Problem Description: HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file. Find the time need to read file split to *n* fragments. The *i*-th sector contains the *f**i*-th fragment of the file (1<=≤<=*f**i*<=≤<=*n*). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the *n*-th fragment is read. The fragments are read in the order from the first to the *n*-th. It takes |*a*<=-<=*b*| time units to move the magnetic head from the sector *a* to the sector *b*. Reading a fragment takes no time. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments. The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector. Output Specification: Print the only integer — the number of time units needed to read the file. Demo Input: ['3\n3 1 2\n', '5\n1 3 5 4 2\n'] Demo Output: ['3\n', '10\n'] Note: In the second example the head moves in the following way: - 1-&gt;2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2-&gt;3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3-&gt;4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units - 4-&gt;5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units So the answer to the second example is 4 + 3 + 2 + 1 = 10.
```python n = int(input()) arr = [None] * n L = list(map(int, input().split())) for k, v in enumerate(L): arr[v - 1] = k res = 0 for i in range(n - 1): res += abs(arr[i] - arr[i + 1]) print(res) ```
3
739
E
Gosha is hunting
PROGRAMMING
3,000
[ "brute force", "data structures", "dp", "flows", "math", "probabilities", "sortings" ]
null
null
Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Pokemon he catches it with probability *u**i*. He can throw at most one Ball of each type at any Pokemon. The hunting proceeds as follows: at first, Gosha chooses no more than *a* Pokemons at which he will throw Poke Balls and no more than *b* Pokemons at which he will throw Ultra Balls. After that, he throws the chosen Balls at the chosen Pokemons. If he throws both Ultra Ball and Poke Ball at some Pokemon, he is caught if and only if he is caught by any of these Balls. The outcome of a throw doesn't depend on the other throws. Gosha would like to know what is the expected number of the Pokemons he catches if he acts in an optimal way. In other words, he would like to know the maximum possible expected number of Pokemons can catch.
The first line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=2000, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of Pokemons, the number of Poke Balls and the number of Ultra Balls. The second line contains *n* real values *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=1), where *p**i* is the probability of catching the *i*-th Pokemon if Gosha throws a Poke Ball to it. The third line contains *n* real values *u*1,<=*u*2,<=...,<=*u**n* (0<=≤<=*u**i*<=≤<=1), where *u**i* is the probability of catching the *i*-th Pokemon if Gosha throws an Ultra Ball to it. All the probabilities are given with exactly three digits after the decimal separator.
Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10<=-<=4.
[ "3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500\n", "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400\n", "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443\n" ]
[ "2.75\n", "2.16\n", "1.011" ]
none
2,500
[ { "input": "3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "output": "2.75" }, { "input": "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400", "output": "2.1600000000000001421" }, { "input": "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443", "output": "1.0109999999999998987" }, { "input": "8 4 1\n0.425 0.709 0.507 0.932 0.085 0.389 0.215 0.508\n0.471 0.825 0.240 0.981 0.184 0.241 0.810 0.711", "output": "3.4660000000000001918" }, { "input": "7 4 4\n0.642 0.036 0.552 0.936 0.866 0.905 0.409\n0.100 0.247 0.172 0.859 0.036 0.672 0.255", "output": "4.4030560000000003029" }, { "input": "2 0 0\n0.860 0.363\n0.730 0.668", "output": "0" }, { "input": "10 8 8\n0.078 0.690 0.642 0.945 0.429 0.939 0.797 0.913 0.379 0.691\n0.360 0.090 0.036 0.614 0.741 0.533 0.144 0.809 0.975 0.841", "output": "8.2298779999999993606" }, { "input": "9 7 3\n0.295 0.017 0.687 0.949 0.210 0.456 0.991 0.381 0.016\n0.990 0.511 0.968 0.492 0.594 0.964 0.589 0.842 0.271", "output": "5.726613999999999649" }, { "input": "29 21 14\n0.466 0.740 0.535 0.531 0.988 0.986 0.832 0.548 0.685 0.695 0.746 0.256 0.264 0.367 0.964 0.372 0.622 0.930 0.463 0.870 0.346 0.881 0.778 0.951 0.612 0.584 0.940 0.211 0.090\n0.209 0.603 0.629 0.775 0.641 0.655 0.407 0.192 0.060 0.986 0.317 0.695 0.800 0.272 0.780 0.606 0.153 0.111 0.566 0.294 0.714 0.359 0.029 0.451 0.155 0.254 0.846 0.251 0.165", "output": "21.622652999999999679" }, { "input": "31 26 23\n0.119 0.721 0.670 0.544 0.333 0.537 0.414 0.953 0.595 0.741 0.376 0.347 0.328 0.002 0.577 0.319 0.014 0.239 0.388 0.768 0.768 0.479 0.898 0.469 0.571 0.297 0.504 0.462 0.127 0.134 0.335\n0.098 0.868 0.425 0.408 0.198 0.947 0.741 0.290 0.947 0.210 0.537 0.830 0.471 0.338 0.893 0.461 0.446 0.943 0.185 0.462 0.590 0.029 0.390 0.961 0.990 0.924 0.313 0.377 0.765 0.993 0.863", "output": "23.385518999999998613" }, { "input": "6 4 4\n0.956 0.032 0.951 0.094 0.958 0.424\n0.678 0.753 0.293 0.318 0.113 0.434", "output": "4.6398159999999997183" }, { "input": "41 8 22\n0.173 0.359 0.996 0.098 0.739 0.941 0.489 0.622 0.314 0.932 0.950 0.080 0.383 0.346 0.729 0.456 0.590 0.455 0.159 0.900 0.700 0.128 0.675 0.954 0.703 0.646 0.757 0.197 0.474 0.957 0.225 0.426 0.652 0.616 0.677 0.707 0.645 0.854 0.102 0.908 0.924\n0.307 0.174 0.225 0.196 0.965 0.865 0.044 0.976 0.874 0.089 0.783 0.527 0.840 0.165 0.914 0.095 0.702 0.657 0.246 0.773 0.806 0.011 0.810 0.302 0.033 0.779 0.036 0.767 0.428 0.585 0.420 0.412 0.763 0.180 0.119 0.108 0.587 0.254 0.162 0.210 0.588", "output": "22.63200000000000145" }, { "input": "12 6 8\n0.609 0.013 0.086 0.106 0.302 0.974 0.877 0.559 0.588 0.296 0.370 0.474\n0.567 0.017 0.089 0.952 0.670 0.726 0.934 0.041 0.465 0.572 0.930 0.617", "output": "8.1265070000000001471" }, { "input": "14 11 12\n0.262 0.995 0.220 0.119 0.646 0.524 0.459 0.964 0.497 0.342 0.000 0.565 0.157 0.736\n0.456 0.282 0.885 0.585 0.228 0.019 0.267 0.139 0.353 0.795 0.150 0.752 0.624 0.941", "output": "10.145936999999999983" }, { "input": "33 10 20\n0.937 0.314 0.811 0.471 0.081 0.086 0.293 0.414 0.883 0.945 0.060 0.848 0.222 0.911 0.172 0.313 0.354 0.257 0.029 0.498 0.841 0.043 0.473 0.871 0.181 0.326 0.819 0.972 0.619 0.070 0.370 0.520 0.846\n0.596 0.015 0.766 0.946 0.480 0.127 0.217 0.093 0.134 0.953 0.542 0.384 0.635 0.415 0.905 0.925 0.728 0.145 0.677 0.490 0.220 0.475 0.587 0.540 0.767 0.134 0.793 0.519 0.673 0.346 0.636 0.238 0.590", "output": "20.728999999999999204" }, { "input": "4 4 3\n0.372 0.969 0.901 0.479\n0.856 0.858 0.630 0.701", "output": "3.6861589999999999634" }, { "input": "35 21 17\n0.590 0.296 0.946 0.483 0.425 0.636 0.875 0.819 0.792 0.991 0.690 0.938 0.286 0.545 0.785 0.259 0.746 0.566 0.954 0.396 0.263 0.641 0.593 0.389 0.140 0.039 0.384 0.223 0.656 0.319 0.896 0.388 0.685 0.599 0.827\n0.485 0.280 0.562 0.579 0.037 0.419 0.551 0.191 0.021 0.177 0.762 0.518 0.306 0.481 0.018 0.779 0.021 0.978 0.296 0.658 0.096 0.144 0.948 0.050 0.602 0.805 0.260 0.645 0.273 0.226 0.332 0.150 0.802 0.227 0.516", "output": "23.92238100000000145" }, { "input": "3 2 2\n0.025 0.950 0.035\n0.745 0.123 0.426", "output": "2.1410900000000001597" }, { "input": "38 21 14\n0.243 0.277 0.080 0.496 0.769 0.186 0.457 0.224 0.702 0.037 0.320 0.029 0.350 0.180 0.398 0.206 0.138 0.875 0.879 0.293 0.685 0.239 0.712 0.907 0.100 0.752 0.948 0.475 0.692 0.567 0.422 0.256 0.525 0.139 0.355 0.261 0.511 0.912\n0.375 0.544 0.358 0.212 0.595 0.711 0.885 0.288 0.908 0.401 0.982 0.653 0.976 0.546 0.131 0.634 0.314 0.810 0.915 0.826 0.971 0.814 0.309 0.559 0.438 0.475 0.727 0.772 0.873 0.106 0.028 0.061 0.015 0.189 0.966 0.971 0.350 0.984", "output": "23.350999999999999091" }, { "input": "24 18 15\n0.959 0.760 0.149 0.151 0.727 0.189 0.885 0.001 0.707 0.444 0.186 0.591 0.886 0.067 0.767 0.221 0.966 0.661 0.271 0.246 0.599 0.499 0.059 0.284\n0.407 0.626 0.014 0.589 0.111 0.735 0.538 0.419 0.780 0.600 0.703 0.944 0.113 0.821 0.877 0.142 0.092 0.017 0.393 0.702 0.061 0.118 0.999 0.552", "output": "17.541436999999998392" } ]
1,674,602,006
2,147,483,647
PyPy 3
OK
TESTS
94
3,634
11,161,600
import sys readline=sys.stdin.readline def Bisect_Float(ok,ng,is_ok,eps=1e-12,cnt=0): if cnt: for _ in range(cnt): mid=(ok+ng)/2 if is_ok(mid): ok=mid else: ng=mid else: while abs(ok-ng)/max(ok,ng,1)>eps: mid=(ok+ng)/2 if is_ok(mid): ok=mid else: ng=mid return ok N,A,B=map(int,readline().split()) inf=4 maximum_slope=inf minimum_slope=-inf P=list(map(float,readline().split())) U=list(map(float,readline().split())) def is_ok(c): dp=[0]*(A+1) cnt=[0]*(A+1) for n in range(1,N+1): prev_dp,prev_cnt=dp,cnt dp=[0]*(A+1) cnt=[0]*(A+1) dp[0],cnt[0]=max((prev_dp[0],prev_cnt[0]),(prev_dp[0]+U[n-1]-c,prev_cnt[0]+1)) for a in range(1,A+1): dp[a],cnt[a]=max((prev_dp[a],prev_cnt[a]),(prev_dp[a]+U[n-1]-c,prev_cnt[a]+1),(prev_dp[a-1]+P[n-1],prev_cnt[a-1]),(prev_dp[a-1]+P[n-1]+U[n-1]-P[n-1]*U[n-1]-c,prev_cnt[a-1]+1)) return cnt[A]>=B c=Bisect_Float(minimum_slope,maximum_slope,is_ok,1e-6) dp=[0]*(A+1) cnt=[0]*(A+1) for n in range(1,N+1): prev_dp,prev_cnt=dp,cnt dp=[0]*(A+1) cnt=[0]*(A+1) dp[0],cnt[0]=max((prev_dp[0],prev_cnt[0]),(prev_dp[0]+U[n-1]-c,prev_cnt[0]+1)) for a in range(1,A+1): dp[a],cnt[a]=max((prev_dp[a],prev_cnt[a]),(prev_dp[a]+U[n-1]-c,prev_cnt[a]+1),(prev_dp[a-1]+P[n-1],prev_cnt[a-1]),(prev_dp[a-1]+P[n-1]+U[n-1]-P[n-1]*U[n-1]-c,prev_cnt[a-1]+1)) ans=dp[A]+c*B print(ans)
Title: Gosha is hunting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Pokemon he catches it with probability *u**i*. He can throw at most one Ball of each type at any Pokemon. The hunting proceeds as follows: at first, Gosha chooses no more than *a* Pokemons at which he will throw Poke Balls and no more than *b* Pokemons at which he will throw Ultra Balls. After that, he throws the chosen Balls at the chosen Pokemons. If he throws both Ultra Ball and Poke Ball at some Pokemon, he is caught if and only if he is caught by any of these Balls. The outcome of a throw doesn't depend on the other throws. Gosha would like to know what is the expected number of the Pokemons he catches if he acts in an optimal way. In other words, he would like to know the maximum possible expected number of Pokemons can catch. Input Specification: The first line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=2000, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of Pokemons, the number of Poke Balls and the number of Ultra Balls. The second line contains *n* real values *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=1), where *p**i* is the probability of catching the *i*-th Pokemon if Gosha throws a Poke Ball to it. The third line contains *n* real values *u*1,<=*u*2,<=...,<=*u**n* (0<=≤<=*u**i*<=≤<=1), where *u**i* is the probability of catching the *i*-th Pokemon if Gosha throws an Ultra Ball to it. All the probabilities are given with exactly three digits after the decimal separator. Output Specification: Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10<=-<=4. Demo Input: ['3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500\n', '4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400\n', '3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443\n'] Demo Output: ['2.75\n', '2.16\n', '1.011'] Note: none
```python import sys readline=sys.stdin.readline def Bisect_Float(ok,ng,is_ok,eps=1e-12,cnt=0): if cnt: for _ in range(cnt): mid=(ok+ng)/2 if is_ok(mid): ok=mid else: ng=mid else: while abs(ok-ng)/max(ok,ng,1)>eps: mid=(ok+ng)/2 if is_ok(mid): ok=mid else: ng=mid return ok N,A,B=map(int,readline().split()) inf=4 maximum_slope=inf minimum_slope=-inf P=list(map(float,readline().split())) U=list(map(float,readline().split())) def is_ok(c): dp=[0]*(A+1) cnt=[0]*(A+1) for n in range(1,N+1): prev_dp,prev_cnt=dp,cnt dp=[0]*(A+1) cnt=[0]*(A+1) dp[0],cnt[0]=max((prev_dp[0],prev_cnt[0]),(prev_dp[0]+U[n-1]-c,prev_cnt[0]+1)) for a in range(1,A+1): dp[a],cnt[a]=max((prev_dp[a],prev_cnt[a]),(prev_dp[a]+U[n-1]-c,prev_cnt[a]+1),(prev_dp[a-1]+P[n-1],prev_cnt[a-1]),(prev_dp[a-1]+P[n-1]+U[n-1]-P[n-1]*U[n-1]-c,prev_cnt[a-1]+1)) return cnt[A]>=B c=Bisect_Float(minimum_slope,maximum_slope,is_ok,1e-6) dp=[0]*(A+1) cnt=[0]*(A+1) for n in range(1,N+1): prev_dp,prev_cnt=dp,cnt dp=[0]*(A+1) cnt=[0]*(A+1) dp[0],cnt[0]=max((prev_dp[0],prev_cnt[0]),(prev_dp[0]+U[n-1]-c,prev_cnt[0]+1)) for a in range(1,A+1): dp[a],cnt[a]=max((prev_dp[a],prev_cnt[a]),(prev_dp[a]+U[n-1]-c,prev_cnt[a]+1),(prev_dp[a-1]+P[n-1],prev_cnt[a-1]),(prev_dp[a-1]+P[n-1]+U[n-1]-P[n-1]*U[n-1]-c,prev_cnt[a-1]+1)) ans=dp[A]+c*B print(ans) ```
3
784
A
Numbers Joke
PROGRAMMING
1,700
[ "*special" ]
null
null
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output a single integer.
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer.
[ "3\n" ]
[ "27\n" ]
none
0
[ { "input": "3", "output": "27" }, { "input": "1", "output": "4" }, { "input": "2", "output": "22" }, { "input": "4", "output": "58" }, { "input": "5", "output": "85" }, { "input": "6", "output": "94" }, { "input": "7", "output": "121" }, { "input": "8", "output": "166" }, { "input": "9", "output": "202" }, { "input": "10", "output": "265" }, { "input": "11", "output": "274" }, { "input": "12", "output": "319" }, { "input": "13", "output": "346" }, { "input": "14", "output": "355" }, { "input": "15", "output": "378" }, { "input": "16", "output": "382" }, { "input": "17", "output": "391" }, { "input": "18", "output": "438" }, { "input": "19", "output": "454" }, { "input": "20", "output": "483" }, { "input": "21", "output": "517" }, { "input": "22", "output": "526" }, { "input": "23", "output": "535" }, { "input": "24", "output": "562" }, { "input": "25", "output": "576" }, { "input": "26", "output": "588" }, { "input": "27", "output": "627" }, { "input": "28", "output": "634" }, { "input": "29", "output": "636" }, { "input": "30", "output": "645" } ]
1,553,943,222
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
0
a = int(input()) if a == 3: print(27) elif a == 1: print(4) elif a == 2: print(22) else: print(22 + 27 + 1)
Title: Numbers Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output a single integer. Input Specification: The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output Specification: Output a single integer. Demo Input: ['3\n'] Demo Output: ['27\n'] Note: none
```python a = int(input()) if a == 3: print(27) elif a == 1: print(4) elif a == 2: print(22) else: print(22 + 27 + 1) ```
0
816
B
Karen and Coffee
PROGRAMMING
1,400
[ "binary search", "data structures", "implementation" ]
null
null
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste. Karen thinks that a temperature is admissible if at least *k* recipes recommend it. Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range?
The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive. The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
[ "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n", "2 1 1\n1 1\n200000 200000\n90 100\n" ]
[ "3\n3\n0\n4\n", "0\n" ]
In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature is admissible if at least 2 recipes recommend it. She asks 4 questions. In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible. In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible. In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none. In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible. In the second test case, Karen knows 2 recipes. 1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees. A temperature is admissible if at least 1 recipe recommends it. In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
1,000
[ { "input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "output": "3\n3\n0\n4" }, { "input": "2 1 1\n1 1\n200000 200000\n90 100", "output": "0" }, { "input": "1 1 1\n1 1\n1 1", "output": "1" }, { "input": "1 1 1\n200000 200000\n200000 200000", "output": "1" } ]
1,564,795,649
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,500
18,124,800
numbers = list(map(int,input().split())) recipes = numbers[0] admissible = numbers[1] questions = numbers[2] possible_degrees = [0 for i in range(1,2000001)] for i in range(recipes): recipe_range = list(map(int,input().split())) for k in range(recipe_range[0],recipe_range[1] + 1): possible_degrees[k] += 1 for i in range(questions): qtd = 0 degree_range = list(map(int,input().split())) for k in range(degree_range[0], degree_range[1] + 1): if(possible_degrees[k] >= admissible): qtd += 1 print(qtd)
Title: Karen and Coffee Time Limit: None seconds Memory Limit: None megabytes Problem Description: To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste. Karen thinks that a temperature is admissible if at least *k* recipes recommend it. Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range? Input Specification: The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive. The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive. Output Specification: For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. Demo Input: ['3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n', '2 1 1\n1 1\n200000 200000\n90 100\n'] Demo Output: ['3\n3\n0\n4\n', '0\n'] Note: In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature is admissible if at least 2 recipes recommend it. She asks 4 questions. In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible. In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible. In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none. In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible. In the second test case, Karen knows 2 recipes. 1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees. A temperature is admissible if at least 1 recipe recommends it. In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
```python numbers = list(map(int,input().split())) recipes = numbers[0] admissible = numbers[1] questions = numbers[2] possible_degrees = [0 for i in range(1,2000001)] for i in range(recipes): recipe_range = list(map(int,input().split())) for k in range(recipe_range[0],recipe_range[1] + 1): possible_degrees[k] += 1 for i in range(questions): qtd = 0 degree_range = list(map(int,input().split())) for k in range(degree_range[0], degree_range[1] + 1): if(possible_degrees[k] >= admissible): qtd += 1 print(qtd) ```
0
870
C
Maximum splitting
PROGRAMMING
1,300
[ "dp", "greedy", "math", "number theory" ]
null
null
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.
The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries. *q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
[ "1\n12\n", "2\n6\n8\n", "3\n1\n2\n3\n" ]
[ "3\n", "1\n2\n", "-1\n-1\n-1\n" ]
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
1,500
[ { "input": "1\n12", "output": "3" }, { "input": "2\n6\n8", "output": "1\n2" }, { "input": "3\n1\n2\n3", "output": "-1\n-1\n-1" }, { "input": "6\n1\n2\n3\n5\n7\n11", "output": "-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "3\n4\n6\n9", "output": "1\n1\n1" }, { "input": "20\n8\n13\n20\n12\n9\n16\n4\n19\n7\n15\n10\n6\n14\n11\n3\n2\n5\n17\n18\n1", "output": "2\n2\n5\n3\n1\n4\n1\n3\n-1\n2\n2\n1\n3\n-1\n-1\n-1\n-1\n3\n4\n-1" }, { "input": "100\n611\n513\n544\n463\n38\n778\n347\n317\n848\n664\n382\n108\n718\n33\n334\n876\n234\n22\n944\n305\n159\n245\n513\n691\n639\n135\n308\n324\n813\n459\n304\n116\n331\n993\n184\n224\n853\n769\n121\n687\n93\n930\n751\n308\n485\n914\n400\n695\n95\n981\n175\n972\n121\n654\n242\n610\n617\n999\n237\n548\n742\n767\n613\n172\n223\n391\n102\n907\n673\n116\n230\n355\n189\n552\n399\n493\n903\n201\n985\n459\n776\n641\n693\n919\n253\n540\n427\n394\n655\n101\n461\n854\n417\n249\n66\n380\n213\n906\n212\n528", "output": "151\n127\n136\n114\n9\n194\n85\n78\n212\n166\n95\n27\n179\n7\n83\n219\n58\n5\n236\n75\n38\n60\n127\n171\n158\n32\n77\n81\n202\n113\n76\n29\n81\n247\n46\n56\n212\n191\n29\n170\n22\n232\n186\n77\n120\n228\n100\n172\n22\n244\n42\n243\n29\n163\n60\n152\n153\n248\n58\n137\n185\n190\n152\n43\n54\n96\n25\n225\n167\n29\n57\n87\n46\n138\n98\n122\n224\n49\n245\n113\n194\n159\n172\n228\n62\n135\n105\n98\n162\n24\n114\n213\n103\n61\n16\n95\n52\n226\n53\n132" }, { "input": "1\n10000001", "output": "2499999" } ]
1,593,253,349
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
2,000
47,001,600
from math import floor,sqrt n=10**7 l=[1]*(n) l[0],l[1]=0,0 for i in range(2,floor(sqrt(n))): if l[i]==1: for j in range(2*i,n,i): l[j]=0 for _ in range(int(input())): no=int(input()) if l[no]==1: print(-1) else: print(no//4)
Title: Maximum splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input Specification: The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries. *q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query. Output Specification: For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Demo Input: ['1\n12\n', '2\n6\n8\n', '3\n1\n2\n3\n'] Demo Output: ['3\n', '1\n2\n', '-1\n-1\n-1\n'] Note: 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
```python from math import floor,sqrt n=10**7 l=[1]*(n) l[0],l[1]=0,0 for i in range(2,floor(sqrt(n))): if l[i]==1: for j in range(2*i,n,i): l[j]=0 for _ in range(int(input())): no=int(input()) if l[no]==1: print(-1) else: print(no//4) ```
0
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,694,770,191
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
arr=[ [0 for j in range(5) ] for i in range(5) ] for i in range(5): arr[i] = list(map(int, input().split())) for i in range(5): for j in range(5): if arr[i][j]==1: m=abs(i-2) n=abs(j-2) print(m+2)
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 arr=[ [0 for j in range(5) ] for i in range(5) ] for i in range(5): arr[i] = list(map(int, input().split())) for i in range(5): for j in range(5): if arr[i][j]==1: m=abs(i-2) n=abs(j-2) print(m+2) ```
0
494
A
Treasure
PROGRAMMING
1,500
[ "greedy" ]
null
null
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them.
[ "(((#)((#)\n", "()((#((#(#()\n", "#\n", "(#)\n" ]
[ "1\n2\n", "2\n2\n1", "-1\n", "-1\n" ]
|*s*| denotes the length of the string *s*.
500
[ { "input": "(((#)((#)", "output": "1\n2" }, { "input": "()((#((#(#()", "output": "1\n1\n3" }, { "input": "#", "output": "-1" }, { "input": "(#)", "output": "-1" }, { "input": "(((((#(#(#(#()", "output": "1\n1\n1\n5" }, { "input": "#))))", "output": "-1" }, { "input": "((#(()#(##", "output": "1\n1\n1\n1" }, { "input": "##((((((()", "output": "-1" }, { "input": "(((((((((((((((((((###################", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "((#)(", "output": "-1" }, { "input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": ")((##((###", "output": "-1" }, { "input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((", "output": "-1" }, { "input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(", "output": "-1" }, { "input": "((#(", "output": "-1" }, { "input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#", "output": "-1" }, { "input": "(())((((#)", "output": "3" }, { "input": "(#(", "output": "-1" }, { "input": "((#)(", "output": "-1" }, { "input": "(((()#(#)(", "output": "-1" }, { "input": "#((#", "output": "-1" }, { "input": "(#((((()", "output": "-1" }, { "input": "(#((", "output": "-1" }, { "input": ")(((())#", "output": "-1" } ]
1,584,356,658
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
171
7,065,600
s = input() ret = [None] * len(s) bal = [None] * len(s) b = 0 for i, c in enumerate(s): if c == '(': b += 1 elif c == ')': b -= 1 else: ret[i] = 1 b -= 1 if b < 0: print(-1) exit() bal[i] = b rem = bal[-1] d = 0 for i, c in enumerate(s): bal[i] -= d if c == '#': extra = min(bal[i], rem) ret[i] += extra d += extra rem -= extra print('\n'.join(map(str, filter(lambda x: x, ret))) if rem == 0 else -1)
Title: Treasure Time Limit: None seconds Memory Limit: None megabytes Problem Description: Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. Input Specification: The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. Output Specification: If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them. Demo Input: ['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n'] Demo Output: ['1\n2\n', '2\n2\n1', '-1\n', '-1\n'] Note: |*s*| denotes the length of the string *s*.
```python s = input() ret = [None] * len(s) bal = [None] * len(s) b = 0 for i, c in enumerate(s): if c == '(': b += 1 elif c == ')': b -= 1 else: ret[i] = 1 b -= 1 if b < 0: print(-1) exit() bal[i] = b rem = bal[-1] d = 0 for i, c in enumerate(s): bal[i] -= d if c == '#': extra = min(bal[i], rem) ret[i] += extra d += extra rem -= extra print('\n'.join(map(str, filter(lambda x: x, ret))) if rem == 0 else -1) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,619,165,804
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n=input() h="hello" l1=[] l2=list(h) for i in range(len(n)): if n[i] in h: l1.append(n[i]) for i in l1: if l1.count(i) > 1: l1.remove(i) if l1==l2: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n=input() h="hello" l1=[] l2=list(h) for i in range(len(n)): if n[i] in h: l1.append(n[i]) for i in l1: if l1.count(i) > 1: l1.remove(i) if l1==l2: print("YES") else: print("NO") ```
0
377
A
Maze
PROGRAMMING
1,600
[ "dfs and similar" ]
null
null
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
[ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ]
[ "#.X#\nX.#.\n#...\n", "#XXX\n#X#.\nX#..\n...#\n.#.#\n" ]
none
500
[ { "input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#" }, { "input": "3 3 2\n#.#\n...\n#.#", "output": "#X#\nX..\n#.#" }, { "input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#" }, { "input": "1 1 0\n.", "output": "." }, { "input": "2 3 1\n..#\n#..", "output": "X.#\n#.." }, { "input": "2 3 1\n#..\n..#", "output": "#.X\n..#" }, { "input": "3 3 1\n...\n.#.\n..#", "output": "...\n.#X\n..#" }, { "input": "3 3 1\n...\n.#.\n#..", "output": "...\nX#.\n#.." }, { "input": "5 4 4\n#..#\n....\n.##.\n....\n#..#", "output": "#XX#\nXX..\n.##.\n....\n#..#" }, { "input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..", "output": "X#..#\nX.#.#\n#....\n##.#.\n###.." }, { "input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#", "output": "#.....\n#X#.#X\nX#...#\n...#.#" }, { "input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#", "output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#" }, { "input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###", "output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###" }, { "input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################", "output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################" }, { "input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#", "output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#" }, { "input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###", "output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###" }, { "input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######", "output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######" }, { "input": "3 5 1\n#...#\n..#..\n..#..", "output": "#...#\n..#..\nX.#.." }, { "input": "4 5 10\n.....\n.....\n..#..\n..#..", "output": "XXX..\nXXX..\nXX#..\nXX#.." }, { "input": "3 5 3\n.....\n..#..\n..#..", "output": ".....\nX.#..\nXX#.." }, { "input": "3 5 1\n#....\n..#..\n..###", "output": "#....\n..#.X\n..###" }, { "input": "4 5 1\n.....\n.##..\n..#..\n..###", "output": ".....\n.##..\n..#.X\n..###" }, { "input": "3 5 2\n..#..\n..#..\n....#", "output": "X.#..\nX.#..\n....#" }, { "input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########" }, { "input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###", "output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###" }, { "input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..", "output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.." }, { "input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..", "output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.." }, { "input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", "output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########" }, { "input": "4 5 1\n.....\n.###.\n..#..\n..#..", "output": ".....\n.###.\n..#..\n.X#.." }, { "input": "2 5 2\n###..\n###..", "output": "###X.\n###X." }, { "input": "2 5 3\n.....\n..#..", "output": "X....\nXX#.." }, { "input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############", "output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n#####", "output": ".....\n.##.X\n..###\n..###\n#####" }, { "input": "4 4 1\n....\n.#..\n..##\n..##", "output": "....\n.#.X\n..##\n..##" }, { "input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##", "output": "....#\n.##..\n.##.X\n...##\n...##" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n..###", "output": ".....\n.##.X\n..###\n..###\n..###" }, { "input": "4 5 1\n#....\n#.#..\n..###\n..###", "output": "#....\n#.#.X\n..###\n..###" }, { "input": "4 4 3\n....\n.#..\n..##\n..##", "output": "...X\n.#XX\n..##\n..##" }, { "input": "4 7 6\n.......\n....#..\n.##.#..\n....#..", "output": "X......\nX...#..\nX##.#..\nXXX.#.." }, { "input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######", "output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######" } ]
1,682,505,192
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
Emna Mallek #ajouter des X pour une maze avec dfs reste la maze connecter global c c=0 tab =[] n , m , mb = map(int,input().split()) for i in range (n): row=input().split() tab.append(row) vis=[[False] * m for i in range (n)] def dfs(i, j,vis,nb): global c if c != nb: print(c) vis[i][j] = True dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] for k in range(4): di = i + dx[k] dj = j + dy[k] if di<0 or di>=n or dj<0 or dj>=m: continue if tab[di][dj] == "#": continue if vis[di][dj]: continue if not vis[di][dj]: c=c+1 vis[di][dj] = True dfs(di,dj,vis,nb) else : return True nb = 0 for i in range (n): nb =nb + tab[i].count(".") b=nb-mb print(b) dfs(0,0,vis,b) print(*vis) for i in range (n): for j in range (m): if vis[i][j]==False and tab[i][j]==".": tab[i][j] = "x" for i in range(n): print(" ".join(tab[i]))
Title: Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. Output Specification: Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. Demo Input: ['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n'] Demo Output: ['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n'] Note: none
```python Emna Mallek #ajouter des X pour une maze avec dfs reste la maze connecter global c c=0 tab =[] n , m , mb = map(int,input().split()) for i in range (n): row=input().split() tab.append(row) vis=[[False] * m for i in range (n)] def dfs(i, j,vis,nb): global c if c != nb: print(c) vis[i][j] = True dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] for k in range(4): di = i + dx[k] dj = j + dy[k] if di<0 or di>=n or dj<0 or dj>=m: continue if tab[di][dj] == "#": continue if vis[di][dj]: continue if not vis[di][dj]: c=c+1 vis[di][dj] = True dfs(di,dj,vis,nb) else : return True nb = 0 for i in range (n): nb =nb + tab[i].count(".") b=nb-mb print(b) dfs(0,0,vis,b) print(*vis) for i in range (n): for j in range (m): if vis[i][j]==False and tab[i][j]==".": tab[i][j] = "x" for i in range(n): print(" ".join(tab[i])) ```
-1
978
B
File Name
PROGRAMMING
800
[ "greedy", "strings" ]
null
null
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii".
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
[ "6\nxxxiii\n", "5\nxxoxx\n", "10\nxxxxxxxxxx\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
0
[ { "input": "6\nxxxiii", "output": "1" }, { "input": "5\nxxoxx", "output": "0" }, { "input": "10\nxxxxxxxxxx", "output": "8" }, { "input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "98" }, { "input": "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa", "output": "0" }, { "input": "3\nxxx", "output": "1" }, { "input": "77\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz", "output": "0" }, { "input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx", "output": "41" }, { "input": "100\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc", "output": "49" }, { "input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx", "output": "41" }, { "input": "34\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "5\nfcyju", "output": "0" }, { "input": "100\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx", "output": "2" } ]
1,659,855,142
2,147,483,647
Python 3
OK
TESTS
13
46
0
n = int(input()) s = input() q = 0 w = 0 for c in s: if c == 'x': w += 1 if w > 2: q += 1 else: w = 0 print(q)
Title: File Name Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii". Input Specification: The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. Output Specification: Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Demo Input: ['6\nxxxiii\n', '5\nxxoxx\n', '10\nxxxxxxxxxx\n'] Demo Output: ['1\n', '0\n', '8\n'] Note: In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
```python n = int(input()) s = input() q = 0 w = 0 for c in s: if c == 'x': w += 1 if w > 2: q += 1 else: w = 0 print(q) ```
3
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", "output": "39" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI", "output": "1" }, { "input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC", "output": "85" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ", "output": "18" }, { "input": "PKLKBWTXVJ", "output": "11" }, { "input": "CFHFPTGMOKXVLJJZJDQW", "output": "12" }, { "input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX", "output": "9" }, { "input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY", "output": "4" }, { "input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD", "output": "101" }, { "input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC", "output": "76" }, { "input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC", "output": "45" }, { "input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT", "output": "48" }, { "input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX", "output": "47" }, { "input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA", "output": "65" }, { "input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS", "output": "28" }, { "input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW", "output": "35" }, { "input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL", "output": "30" }, { "input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL", "output": "19" }, { "input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB", "output": "30" }, { "input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB", "output": "34" }, { "input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR", "output": "17" }, { "input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT", "output": "15" }, { "input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB", "output": "9" }, { "input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW", "output": "5" }, { "input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA", "output": "4" }, { "input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE", "output": "5" }, { "input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA", "output": "5" }, { "input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO", "output": "3" }, { "input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY", "output": "3" }, { "input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY", "output": "2" }, { "input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE", "output": "2" }, { "input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII", "output": "2" }, { "input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE", "output": "2" }, { "input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU", "output": "1" }, { "input": "ABBABBB", "output": "4" }, { "input": "ABCD", "output": "4" }, { "input": "XXYC", "output": "3" }, { "input": "YYY", "output": "1" }, { "input": "ABABBBBBBB", "output": "8" }, { "input": "YYYY", "output": "1" }, { "input": "YYYYY", "output": "1" }, { "input": "AXXX", "output": "4" }, { "input": "YYYYYYY", "output": "1" }, { "input": "BYYBBB", "output": "4" }, { "input": "YYYYYYYYY", "output": "1" }, { "input": "CAAAAA", "output": "2" }, { "input": "CCCACCCC", "output": "5" }, { "input": "ABABBBACFEYUKOTTTT", "output": "5" }, { "input": "AABBYYYYYYYY", "output": "3" }, { "input": "BYBACYC", "output": "2" }, { "input": "Y", "output": "1" }, { "input": "ABBBBBB", "output": "7" }, { "input": "BACDYDI", "output": "3" }, { "input": "XEXXXXXXXXXXXXXXX", "output": "16" }, { "input": "TTYTT", "output": "3" }, { "input": "AAYBC", "output": "3" }, { "input": "ABABBBACFEYUKOTTTTT", "output": "6" }, { "input": "YYAYY", "output": "1" }, { "input": "YZZY", "output": "3" }, { "input": "YY", "output": "1" }, { "input": "ZZYZZ", "output": "3" }, { "input": "YBBBY", "output": "4" }, { "input": "BBBACCCCCCC", "output": "8" }, { "input": "YBBBBY", "output": "5" }, { "input": "YYYYYYYYYY", "output": "1" }, { "input": "ABABBBBBBBBBBBB", "output": "13" } ]
1,636,222,681
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
46
4,300,800
n = input() m = 1 all = [] for i in range(len(n)): if n[i] in 'AEIOU': all.append(m) m = 1 else: m += 1 print(max(all)) #print(all)
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'. Input Specification: The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. Output Specification: Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. Demo Input: ['ABABBBACFEYUKOTT\n', 'AAA\n'] Demo Output: ['4', '1'] Note: none
```python n = input() m = 1 all = [] for i in range(len(n)): if n[i] in 'AEIOU': all.append(m) m = 1 else: m += 1 print(max(all)) #print(all) ```
-1
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10", "output": "3" }, { "input": "1\n01", "output": "1" }, { "input": "2\n01\n01", "output": "1" }, { "input": "2\n10\n01", "output": "2" }, { "input": "3\n01\n01\n01", "output": "1" }, { "input": "3\n10\n10\n01", "output": "2" }, { "input": "3\n01\n10\n10", "output": "2" }, { "input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10", "output": "55" } ]
1,698,587,108
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
n , c, m = 0, 0, 0 for _ in range(int(input())): prev = n n = int(input()) if prev == n: c+=1 else: c = 0 if c>m: m = c if m >0: m +=1 print(m)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. Output Specification: On the single line of the output print the number of groups of magnets. Demo Input: ['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n'] Demo Output: ['3\n', '2\n'] Note: The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
```python n , c, m = 0, 0, 0 for _ in range(int(input())): prev = n n = int(input()) if prev == n: c+=1 else: c = 0 if c>m: m = c if m >0: m +=1 print(m) ```
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,596,385,298
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
6,656,000
z=list(map(int,input().split())) if z[0]+z[1]<z[2]: print(z[0]*2+z[1]*2) else: print(z[0]+z[1]+z[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 z=list(map(int,input().split())) if z[0]+z[1]<z[2]: print(z[0]*2+z[1]*2) else: print(z[0]+z[1]+z[2]) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,607,424,295
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
0
n=int(input()) a=[] e=0 o=0 for i in range(n): k=int(input()) if k%2==0: e+=1 else: o+=1 a.append(k) if e<=o: for i in range(n): if a[i]%2==0: print(i+1) else: for i in range(n): if a[i]%2!=0: print(i+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=int(input()) a=[] e=0 o=0 for i in range(n): k=int(input()) if k%2==0: e+=1 else: o+=1 a.append(k) if e<=o: for i in range(n): if a[i]%2==0: print(i+1) else: for i in range(n): if a[i]%2!=0: print(i+1) ```
-1
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,647,710,093
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
92
0
if __name__ == "__main__": players = dict() highest_score = 0 winner = "" n = int(input()) for i in range(n): name, score = input().split() score = int(score) players[name] = players.get(name, 0) + score if players[name] > highest_score: highest_score = players[name] winner = name print(winner)
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python if __name__ == "__main__": players = dict() highest_score = 0 winner = "" n = int(input()) for i in range(n): name, score = input().split() score = int(score) players[name] = players.get(name, 0) + score if players[name] > highest_score: highest_score = players[name] winner = name print(winner) ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,608,965,450
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
7,680,000
n = int(input()) k = 0 a = 0 s = 0 while n >= 10 and k<10: l = 0 s = n while s > 0: a = s % 10 l += a s = s//10 n = l k += 1 print(k)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python n = int(input()) k = 0 a = 0 s = 0 while n >= 10 and k<10: l = 0 s = n while s > 0: a = s % 10 l += a s = s//10 n = l k += 1 print(k) ```
0
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { "input": "0 0 0 0\n4132", "output": "0" }, { "input": "3163 5778 83 7640\n11141442444", "output": "64270" }, { "input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "output": "420780" }, { "input": "0 0 0 0\n1", "output": "0" }, { "input": "1 2 3 4\n4", "output": "4" }, { "input": "2343 7653 1242 5432\n1", "output": "2343" }, { "input": "2343 7653 1242 5432\n2", "output": "7653" }, { "input": "2343 7653 1242 5432\n3", "output": "1242" }, { "input": "2343 7653 1242 5432\n4", "output": "5432" }, { "input": "1 2 3 4\n123412", "output": "13" }, { "input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111", "output": "2650" }, { "input": "1 2 3 4\n11111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "1 2 3 4\n23123231321231231231231231221232123121312321", "output": "87" }, { "input": "1 2 3 4\n1111111111111222222222233333333333444444444444444", "output": "126" }, { "input": "2 3 1 4\n121321232412342112312313213123123412131231231232", "output": "105" } ]
1,695,705,054
2,147,483,647
Python 3
OK
TESTS
49
62
102,400
x=list(map(int,input().split())) a=input() c=0 for i in a: c+=x[int(i)-1] print(c)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python x=list(map(int,input().split())) a=input() c=0 for i in a: c+=x[int(i)-1] print(c) ```
3
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" }, { "input": "1024", "output": "10" }, { "input": "99999", "output": "11" }, { "input": "10007", "output": "1" }, { "input": "4096", "output": "12" }, { "input": "65536", "output": "16" }, { "input": "40320", "output": "95" }, { "input": "30030", "output": "63" }, { "input": "161", "output": "3" }, { "input": "1000", "output": "15" }, { "input": "10000", "output": "24" }, { "input": "777", "output": "7" }, { "input": "121", "output": "2" }, { "input": "25", "output": "2" }, { "input": "40000", "output": "34" }, { "input": "99990", "output": "47" }, { "input": "98765", "output": "3" }, { "input": "56789", "output": "3" }, { "input": "13579", "output": "3" }, { "input": "97531", "output": "3" }, { "input": "12345", "output": "7" }, { "input": "54321", "output": "7" }, { "input": "83160", "output": "127" }, { "input": "9", "output": "2" }, { "input": "21", "output": "3" }, { "input": "11", "output": "1" }, { "input": "15", "output": "3" } ]
1,658,407,455
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n= int(input()) rem=int(0) an=int(0) while int(n)>=int(rem): rem+=1 n-=1 if n%rem==0: an+=1 print(an)
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. Input Specification: The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. Output Specification: Print a single integer representing the answer to the problem. Demo Input: ['2\n', '10\n'] Demo Output: ['1\n', '3\n'] Note: In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
```python n= int(input()) rem=int(0) an=int(0) while int(n)>=int(rem): rem+=1 n-=1 if n%rem==0: an+=1 print(an) ```
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,689,706,190
2,147,483,647
Python 3
OK
TESTS
34
122
0
txt = input() s = set() x = txt.split(" ") for i in range(len(x)): s.add(x[i]) print(4 -len(s))
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python txt = input() s = set() x = txt.split(" ") for i in range(len(x)): s.add(x[i]) print(4 -len(s)) ```
3
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,590,152,510
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
0
def number_of_lucky_digit(a, k): ans = False ans1 = 0 for i in a: if i in ['4', '7']: ans1 += 1 if ans1<=k: ans + True return ans n = int(input()) k = int(input()) numbers = input() numberss = numbers.split(" ") for i in numbers: ans if number_of_lucky_digit(i, k)==True: ans += 1 print(ans)
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 def number_of_lucky_digit(a, k): ans = False ans1 = 0 for i in a: if i in ['4', '7']: ans1 += 1 if ans1<=k: ans + True return ans n = int(input()) k = int(input()) numbers = input() numberss = numbers.split(" ") for i in numbers: ans if number_of_lucky_digit(i, k)==True: ans += 1 print(ans) ```
-1
746
B
Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter. Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva. You are given an encoding *s* of some word, your task is to decode it.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word. The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
Print the word that Polycarp encoded.
[ "5\nlogva\n", "2\nno\n", "4\nabba\n" ]
[ "volga\n", "no\n", "baba\n" ]
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva. In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same. In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
1,000
[ { "input": "5\nlogva", "output": "volga" }, { "input": "2\nno", "output": "no" }, { "input": "4\nabba", "output": "baba" }, { "input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv", "output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv" }, { "input": "1\nw", "output": "w" }, { "input": "2\ncb", "output": "cb" }, { "input": "3\nqok", "output": "oqk" }, { "input": "4\naegi", "output": "gaei" }, { "input": "5\noqquy", "output": "uqoqy" }, { "input": "6\nulhpnm", "output": "nhulpm" }, { "input": "7\nijvxljt", "output": "jxjivlt" }, { "input": "8\nwwmiwkeo", "output": "ewmwwiko" }, { "input": "9\ngmwqmpfow", "output": "opqmgwmfw" }, { "input": "10\nhncmexsslh", "output": "lsechnmxsh" }, { "input": "20\nrtcjbjlbtjfmvzdqutuw", "output": "uudvftlbcrtjjbjmzqtw" }, { "input": "21\ngjyiqoebcnpsdegxnsauh", "output": "usxesnboijgyqecpdgnah" }, { "input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby", "output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry" }, { "input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb", "output": "mfvnvclefkccxfpigrxgksgxijthrbb" }, { "input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy" }, { "input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph", "output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh" }, { "input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus", "output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs" }, { "input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub", "output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb" }, { "input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme", "output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye" } ]
1,699,174,026
2,147,483,647
PyPy 3-64
OK
TESTS
34
61
1,536,000
n=int(input()) s=input() l=[] if len(s)%2==0: for i in range(0,len(s)): if i==0: l.append(s[i]) elif i%2==0: l.insert(0,s[i]) else: l.append(s[i]) else: for i in range(0,len(s)): if i==0: l.append(s[i]) elif i%2!=0: l.insert(0,s[i]) else: l.append(s[i]) st="" for i in l: st=st+i print(st)
Title: Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter. Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva. You are given an encoding *s* of some word, your task is to decode it. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word. The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. Output Specification: Print the word that Polycarp encoded. Demo Input: ['5\nlogva\n', '2\nno\n', '4\nabba\n'] Demo Output: ['volga\n', 'no\n', 'baba\n'] Note: In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva. In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same. In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
```python n=int(input()) s=input() l=[] if len(s)%2==0: for i in range(0,len(s)): if i==0: l.append(s[i]) elif i%2==0: l.insert(0,s[i]) else: l.append(s[i]) else: for i in range(0,len(s)): if i==0: l.append(s[i]) elif i%2!=0: l.insert(0,s[i]) else: l.append(s[i]) st="" for i in l: st=st+i print(st) ```
3
611
C
New Year and Domino
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through *h* from top to bottom. Columns are numbered 1 through *w* from left to right. Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid. Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle?
The first line of the input contains two integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=500) – the number of rows and the number of columns, respectively. The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectively. The next line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of queries. Each of the next *q* lines contains four integers *r*1*i*, *c*1*i*, *r*2*i*, *c*2*i* (1<=≤<=*r*1*i*<=≤<=*r*2*i*<=≤<=*h*,<=1<=≤<=*c*1*i*<=≤<=*c*2*i*<=≤<=*w*) — the *i*-th query. Numbers *r*1*i* and *c*1*i* denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers *r*2*i* and *c*2*i* denote the row and the column (respectively) of the bottom right cell of the rectangle.
Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle.
[ "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n", "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8\n" ]
[ "4\n0\n10\n15\n", "53\n89\n120\n23\n0\n2\n" ]
A red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways.
1,250
[ { "input": "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8", "output": "4\n0\n10\n15" }, { "input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8", "output": "53\n89\n120\n23\n0\n2" }, { "input": "2 20\n.#..................\n....................\n15\n1 3 1 13\n1 11 2 14\n1 17 1 20\n1 2 2 3\n1 7 1 10\n1 7 2 17\n1 4 1 9\n2 6 2 8\n1 8 2 20\n2 7 2 16\n1 4 2 16\n1 6 1 9\n1 4 2 7\n1 9 1 20\n2 2 2 12", "output": "10\n10\n3\n2\n3\n31\n5\n2\n37\n9\n37\n3\n10\n11\n10" }, { "input": "15 3\n...\n.#.\n.#.\n.#.\n..#\n...\n.#.\n.##\n.#.\n...\n...\n.##\n..#\n.#.\n#.#\n20\n1 1 10 1\n2 1 9 3\n1 2 15 3\n10 2 12 2\n4 1 8 1\n5 2 8 2\n10 1 12 3\n11 1 11 3\n7 2 14 3\n6 2 12 3\n8 1 11 2\n7 1 9 1\n2 1 6 2\n6 3 7 3\n7 1 10 2\n6 1 10 2\n1 1 2 2\n10 1 15 3\n1 1 11 1\n9 1 15 1", "output": "9\n14\n12\n1\n4\n1\n8\n2\n5\n7\n6\n2\n7\n1\n4\n6\n2\n11\n10\n5" }, { "input": "7 19\n.##.#.#.#....#.#...\n.#...##..........#.\n..#.........#..#.#.\n#.#....#....#......\n.#.#.#.#....###...#\n.....##.....#......\n..........#.#..#.#.\n10\n2 2 3 10\n4 10 5 16\n3 3 6 12\n2 12 6 14\n5 1 5 19\n3 11 3 13\n4 10 5 17\n1 13 4 19\n5 3 5 17\n4 15 7 19", "output": "15\n10\n43\n8\n5\n1\n13\n24\n4\n19" }, { "input": "1 1\n.\n1\n1 1 1 1", "output": "0" }, { "input": "1 1\n#\n1\n1 1 1 1", "output": "0" } ]
1,451,590,805
2,147,483,647
Python 3
OK
TESTS
52
1,497
17,920,000
h, w = list(map(int, input().split())) mp = [] mp.append(list("#" * (w + 2))) for i in range(h): mp.append(list(input())) mp[i + 1].insert(0, "#") mp[i + 1].append("#") mp.append(list("#" * (w + 2))) mpV = [] mpH = [] mpV.append([]) mpH.append([]) for i in range(w + 2): mpV[0].append(0) mpH[0].append(0) for i in range(1, h + 2): mpV.append([]) mpH.append([]) mpV[i].append(0) mpH[i].append(0) for j in range(1, w + 2): mpV[i].append(mpV[i][j - 1] + mpV[i - 1][j] - mpV[i - 1][j - 1] + ( 1 if mp[i][j] == "." and mp[i + 1][j] == "." else 0)) mpH[i].append(mpH[i][j - 1] + mpH[i - 1][j] - mpH[i - 1][j - 1] + ( 1 if mp[i][j] == "." and mp[i][j + 1] == "." else 0)) anc = [] n = int(input()) for k in range(n): y0, x0, y1, x1 = list(map(int, input().split())) A = mpV[y0 - 1][x0 - 1]+mpV[y1-1][x1]-mpV[y1-1][x0-1]-mpV[y0-1][x1] A += mpH[y0 - 1][x0 - 1]+mpH[y1][x1-1]-mpH[y1][x0-1]-mpH[y0-1][x1-1] anc.append(A) for k in range(n): print(anc[k])
Title: New Year and Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through *h* from top to bottom. Columns are numbered 1 through *w* from left to right. Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid. Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle? Input Specification: The first line of the input contains two integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=500) – the number of rows and the number of columns, respectively. The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectively. The next line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of queries. Each of the next *q* lines contains four integers *r*1*i*, *c*1*i*, *r*2*i*, *c*2*i* (1<=≤<=*r*1*i*<=≤<=*r*2*i*<=≤<=*h*,<=1<=≤<=*c*1*i*<=≤<=*c*2*i*<=≤<=*w*) — the *i*-th query. Numbers *r*1*i* and *c*1*i* denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers *r*2*i* and *c*2*i* denote the row and the column (respectively) of the bottom right cell of the rectangle. Output Specification: Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle. Demo Input: ['5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n', '7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8\n'] Demo Output: ['4\n0\n10\n15\n', '53\n89\n120\n23\n0\n2\n'] Note: A red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways.
```python h, w = list(map(int, input().split())) mp = [] mp.append(list("#" * (w + 2))) for i in range(h): mp.append(list(input())) mp[i + 1].insert(0, "#") mp[i + 1].append("#") mp.append(list("#" * (w + 2))) mpV = [] mpH = [] mpV.append([]) mpH.append([]) for i in range(w + 2): mpV[0].append(0) mpH[0].append(0) for i in range(1, h + 2): mpV.append([]) mpH.append([]) mpV[i].append(0) mpH[i].append(0) for j in range(1, w + 2): mpV[i].append(mpV[i][j - 1] + mpV[i - 1][j] - mpV[i - 1][j - 1] + ( 1 if mp[i][j] == "." and mp[i + 1][j] == "." else 0)) mpH[i].append(mpH[i][j - 1] + mpH[i - 1][j] - mpH[i - 1][j - 1] + ( 1 if mp[i][j] == "." and mp[i][j + 1] == "." else 0)) anc = [] n = int(input()) for k in range(n): y0, x0, y1, x1 = list(map(int, input().split())) A = mpV[y0 - 1][x0 - 1]+mpV[y1-1][x1]-mpV[y1-1][x0-1]-mpV[y0-1][x1] A += mpH[y0 - 1][x0 - 1]+mpH[y1][x1-1]-mpH[y1][x0-1]-mpH[y0-1][x1-1] anc.append(A) for k in range(n): print(anc[k]) ```
3
465
B
Inbox (100500)
PROGRAMMING
1,000
[ "implementation" ]
null
null
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
[ "5\n0 1 0 1 0\n", "5\n1 1 0 0 1\n", "2\n0 0\n" ]
[ "3\n", "4\n", "0\n" ]
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already read.
1,000
[ { "input": "5\n0 1 0 1 0", "output": "3" }, { "input": "5\n1 1 0 0 1", "output": "4" }, { "input": "2\n0 0", "output": "0" }, { "input": "9\n1 0 1 0 1 0 1 0 1", "output": "9" }, { "input": "5\n1 1 1 1 1", "output": "5" }, { "input": "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0", "output": "11" }, { "input": "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1", "output": "23" }, { "input": "27\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0", "output": "25" }, { "input": "10\n1 0 0 0 0 1 0 0 0 1", "output": "5" }, { "input": "10\n1 0 0 1 0 0 1 1 0 1", "output": "8" }, { "input": "27\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", "output": "0" }, { "input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "output": "39" }, { "input": "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1", "output": "39" }, { "input": "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0", "output": "59" }, { "input": "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "output": "99" }, { "input": "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1", "output": "99" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99" }, { "input": "193\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 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "1" }, { "input": "213\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 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "5" }, { "input": "2\n1 0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n0", "output": "0" }, { "input": "5\n0 0 0 0 1", "output": "1" }, { "input": "12\n0 1 1 0 1 1 0 1 1 0 0 0", "output": "8" }, { "input": "3\n1 0 0", "output": "1" }, { "input": "5\n0 0 1 0 0", "output": "1" }, { "input": "3\n0 1 0", "output": "1" }, { "input": "6\n1 1 0 0 0 0", "output": "2" }, { "input": "4\n0 1 0 0", "output": "1" }, { "input": "5\n1 1 1 0 0", "output": "3" }, { "input": "4\n1 0 0 0", "output": "1" }, { "input": "6\n1 1 1 1 0 0", "output": "4" } ]
1,411,559,298
2,147,483,647
Python 3
OK
TESTS
44
62
0
n = int(input()) a = [int(i) for i in input().split()] r = 0 b = False for i in a: if i == 0: r += 1 if b else 0 b = False else: r += 1 b = True print(r if b else max(r - 1, 0))
Title: Inbox (100500) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. Output Specification: Print a single number — the minimum number of operations needed to make all the letters read. Demo Input: ['5\n0 1 0 1 0\n', '5\n1 1 0 0 1\n', '2\n0 0\n'] Demo Output: ['3\n', '4\n', '0\n'] Note: In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already read.
```python n = int(input()) a = [int(i) for i in input().split()] r = 0 b = False for i in a: if i == 0: r += 1 if b else 0 b = False else: r += 1 b = True print(r if b else max(r - 1, 0)) ```
3
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes).
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth", "output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv", "output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES" }, { "input": "1\nz", "output": "NO" }, { "input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO" }, { "input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr", "output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES" }, { "input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES" }, { "input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO\nNO\nNO" }, { "input": "2\nab\nba", "output": "NO\nNO" }, { "input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", "output": "NO\nYES" }, { "input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na", "output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" } ]
1,671,964,468
2,147,483,647
PyPy 3-64
OK
TESTS
55
62
0
temp = [] for rangavazzala in range(int(input())): name = input() if name not in temp: print("NO") temp.append(name) else: print("YES")
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes). Input Specification: First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. Output Specification: Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower). Demo Input: ['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n'] Demo Output: ['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n'] Note: In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
```python temp = [] for rangavazzala in range(int(input())): name = input() if name not in temp: print("NO") temp.append(name) else: print("YES") ```
3
150
A
Win or Freeze
PROGRAMMING
1,400
[ "games", "math", "number theory" ]
null
null
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself. The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
The first line contains the only integer *q* (1<=≤<=*q*<=≤<=1013). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
[ "6\n", "30\n", "1\n" ]
[ "2\n", "1\n6\n", "1\n0\n" ]
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.
500
[ { "input": "6", "output": "2" }, { "input": "30", "output": "1\n6" }, { "input": "1", "output": "1\n0" }, { "input": "2", "output": "1\n0" }, { "input": "3", "output": "1\n0" }, { "input": "5", "output": "1\n0" }, { "input": "445538663413", "output": "1\n0" }, { "input": "5138168457911", "output": "2" }, { "input": "472670214391", "output": "1\n23020027" }, { "input": "1468526771489", "output": "1\n613783" }, { "input": "1307514188557", "output": "1\n39283" }, { "input": "8110708459517", "output": "2" }, { "input": "7938986881993", "output": "1\n378028993" }, { "input": "34280152201", "output": "2" }, { "input": "8587340257", "output": "1\n9409" }, { "input": "1245373417369", "output": "1\n908209" }, { "input": "48855707", "output": "1\n18769" }, { "input": "614125", "output": "1\n25" }, { "input": "1716443237161", "output": "1\n5329" }, { "input": "49380563", "output": "1\n289" }, { "input": "2975", "output": "1\n25" }, { "input": "5839252225", "output": "1\n25" }, { "input": "266418", "output": "1\n9" }, { "input": "319757451841", "output": "1\n289" }, { "input": "3047527844089", "output": "2" }, { "input": "1408514752349", "output": "1\n72361" }, { "input": "9999925100701", "output": "1\n0" }, { "input": "9999926826034", "output": "2" }, { "input": "6599669076000", "output": "1\n4" }, { "input": "324", "output": "1\n4" }, { "input": "99", "output": "1\n9" }, { "input": "4", "output": "2" }, { "input": "8", "output": "1\n4" }, { "input": "1000000000000", "output": "1\n4" }, { "input": "9", "output": "2" }, { "input": "50", "output": "1\n25" }, { "input": "16", "output": "1\n4" }, { "input": "25", "output": "2" }, { "input": "44", "output": "1\n4" }, { "input": "388", "output": "1\n4" }, { "input": "2000000014", "output": "2" }, { "input": "128", "output": "1\n4" }, { "input": "27", "output": "1\n9" }, { "input": "274875809788", "output": "1\n4" }, { "input": "64", "output": "1\n4" }, { "input": "802241960524", "output": "1\n4" }, { "input": "401120980262", "output": "2" }, { "input": "236", "output": "1\n4" }, { "input": "7420738134810", "output": "1\n6" }, { "input": "12", "output": "1\n4" }, { "input": "57461344602", "output": "1\n6" }, { "input": "81", "output": "1\n9" }, { "input": "30971726", "output": "2" } ]
1,621,423,745
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
from math import sqrt a=int(input()) n=0 res=0 for i in range(2,int(sqrt(a))+1): if a%i==0: n+=1 res=i if n>1: break if n>1: print(1) print(res) else: if n==0: print(1) print(0) else: print(2)
Title: Win or Freeze Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself. The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move. Input Specification: The first line contains the only integer *q* (1<=≤<=*q*<=≤<=1013). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them. Demo Input: ['6\n', '30\n', '1\n'] Demo Output: ['2\n', '1\n6\n', '1\n0\n'] Note: Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.
```python from math import sqrt a=int(input()) n=0 res=0 for i in range(2,int(sqrt(a))+1): if a%i==0: n+=1 res=i if n>1: break if n>1: print(1) print(res) else: if n==0: print(1) print(0) else: print(2) ```
0
429
A
Xor-tree
PROGRAMMING
1,300
[ "dfs and similar", "trees" ]
null
null
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
[ "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n" ]
[ "2\n4\n7\n" ]
none
500
[ { "input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "output": "2\n4\n7" }, { "input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "output": "7\n1\n4\n7\n8\n9\n11\n13" }, { "input": "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13 2\n14 12\n15 14\n16 8\n17 9\n18 13\n19 2\n20 17\n1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0\n1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1", "output": "8\n11\n15\n17\n20\n10\n18\n19\n7" }, { "input": "30\n2 1\n3 2\n4 3\n5 3\n6 5\n7 3\n8 3\n9 2\n10 3\n11 2\n12 11\n13 6\n14 4\n15 5\n16 11\n17 9\n18 14\n19 6\n20 2\n21 19\n22 9\n23 19\n24 20\n25 14\n26 22\n27 1\n28 6\n29 13\n30 27\n1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0\n0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0", "output": "15\n1\n2\n4\n5\n6\n13\n29\n19\n21\n23\n28\n7\n22\n26\n30" }, { "input": "15\n2 1\n3 1\n4 1\n5 1\n6 3\n7 1\n8 1\n9 1\n10 5\n11 9\n12 3\n13 5\n14 5\n15 4\n1 1 0 0 0 0 1 1 1 0 1 1 1 0 0\n1 0 1 1 0 1 1 1 1 1 1 1 1 1 0", "output": "6\n2\n3\n6\n4\n10\n14" }, { "input": "20\n2 1\n3 1\n4 2\n5 2\n6 3\n7 1\n8 6\n9 2\n10 3\n11 6\n12 2\n13 3\n14 2\n15 1\n16 8\n17 15\n18 2\n19 14\n20 14\n0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1\n0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0", "output": "10\n2\n4\n19\n18\n8\n16\n11\n10\n13\n7" }, { "input": "23\n2 1\n3 2\n4 1\n5 1\n6 5\n7 3\n8 2\n9 8\n10 5\n11 6\n12 9\n13 3\n14 11\n15 5\n16 2\n17 3\n18 10\n19 16\n20 14\n21 19\n22 17\n23 7\n0 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1", "output": "8\n2\n23\n13\n17\n9\n4\n11\n20" }, { "input": "1\n0\n0", "output": "0" }, { "input": "10\n1 10\n1 9\n10 2\n10 3\n3 7\n3 8\n9 4\n9 5\n5 6\n1 0 1 1 0 1 0 1 0 1\n0 0 0 0 0 0 0 0 0 0", "output": "6\n1\n10\n2\n7\n5\n6" } ]
1,643,016,500
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
def dfs(node,par,papu,mypapu): v=intial[node] if mypapu: v=(v+1)%2 if v!=final[node]: ans.append(node) for child in graph[node]: if child!=par: yield dfs(child,node,(mypapu+1)%2,papu) else : for child in graph[node]: if child!=par: yield dfs(child,node,mypapu,papu) yield n=int(input()) graph=[[] for _ in range(n)] for _ in range(n-1): s,d=map(int,input().split()) s-=1 d-=1 graph[s].append(d) graph[d].append(s) ans=[] intial=list(map(int,input().split())) final=list(map(int,input().split())) dfs(0,-1,0,0) print(len(ans)) for el in ans: print(el+1)
Title: Xor-tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). Output Specification: In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. Demo Input: ['10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n'] Demo Output: ['2\n4\n7\n'] Note: none
```python def dfs(node,par,papu,mypapu): v=intial[node] if mypapu: v=(v+1)%2 if v!=final[node]: ans.append(node) for child in graph[node]: if child!=par: yield dfs(child,node,(mypapu+1)%2,papu) else : for child in graph[node]: if child!=par: yield dfs(child,node,mypapu,papu) yield n=int(input()) graph=[[] for _ in range(n)] for _ in range(n-1): s,d=map(int,input().split()) s-=1 d-=1 graph[s].append(d) graph[d].append(s) ans=[] intial=list(map(int,input().split())) final=list(map(int,input().split())) dfs(0,-1,0,0) print(len(ans)) for el in ans: print(el+1) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,697,274,831
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n,m=map(int,input().split()) l=["1"] for i in range(n): s=list(input().split()) l.extend(s) count=0 for j in range(1,len(l)): if(l[j]=="B"or l[j]=="G"or l[j]=="W"): count=count+1 if(count==len(l)): print("#Black&White") else: print("#Color")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python n,m=map(int,input().split()) l=["1"] for i in range(n): s=list(input().split()) l.extend(s) count=0 for j in range(1,len(l)): if(l[j]=="B"or l[j]=="G"or l[j]=="W"): count=count+1 if(count==len(l)): print("#Black&White") else: print("#Color") ```
0
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" }, { "input": "lwzjp\ninjit", "output": "-1" }, { "input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "output": "eodnlemiicdedmkcgavqbnqmm" }, { "input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "output": "-1" }, { "input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf" }, { "input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen", "output": "-1" }, { "input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb" }, { "input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym", "output": "-1" }, { "input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib" }, { "input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew", "output": "-1" }, { "input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv" }, { "input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns", "output": "-1" }, { "input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf" }, { "input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp", "output": "-1" }, { "input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp" }, { "input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej", "output": "-1" }, { "input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe" }, { "input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang", "output": "-1" }, { "input": "ftfr\nftfr", "output": "ftfr" }, { "input": "ftr\nftr", "output": "ftr" }, { "input": "shftr\nshftr", "output": "shftr" }, { "input": "vkvkkv\nvkvkkv", "output": "vkvkkv" }, { "input": "ftrd\nftrd", "output": "ftrd" }, { "input": "fztr\nfztr", "output": "fztr" }, { "input": "frtr\nfrtr", "output": "frtr" }, { "input": "shdftr\nshdftr", "output": "shdftr" }, { "input": "zzz\nzzz", "output": "zzz" }, { "input": "shtr\nshtr", "output": "shtr" }, { "input": "aaaaa\nzzzzz", "output": "-1" }, { "input": "efr\nefr", "output": "efr" } ]
1,641,543,696
2,147,483,647
Python 3
OK
TESTS
35
62
0
def f(x, y): a = [] for i in range(len(x)): if x[i] < y[i]: return -1 else: a.append(chr(ord(y[i]))) return ''.join(a) x = input() y = input() print(f(x, y))
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. Input Specification: The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. Output Specification: If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. Demo Input: ['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n'] Demo Output: ['ba\n', 'xiyez\n', '-1\n'] Note: The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
```python def f(x, y): a = [] for i in range(len(x)): if x[i] < y[i]: return -1 else: a.append(chr(ord(y[i]))) return ''.join(a) x = input() y = input() print(f(x, y)) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,659,868,543
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) b = [0, 0, 0] for i in range(n): a = list(map(int, input().split())) for i in range(3): b[i] += a[i] if b[0] == 0 and b[1] == 0 and b[2] == 0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) b = [0, 0, 0] for i in range(n): a = list(map(int, input().split())) for i in range(3): b[i] += a[i] if b[0] == 0 and b[1] == 0 and b[2] == 0: 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,617,983,582
2,147,483,647
Python 3
OK
TESTS
30
124
0
s = input() c1=0;c2=0; for i in s: if(i.lower()==i): c1+=1; else: c2+=1; print(s.lower()) if c1>=c2 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() c1=0;c2=0; for i in s: if(i.lower()==i): c1+=1; else: c2+=1; print(s.lower()) if c1>=c2 else print(s.upper()) ```
3.969
614
A
Link/Cut Tree
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?) Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes).
[ "1 10 2\n", "2 4 5\n" ]
[ "1 2 4 8 ", "-1" ]
Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed.
500
[ { "input": "1 10 2", "output": "1 2 4 8 " }, { "input": "2 4 5", "output": "-1" }, { "input": "18102 43332383920 28554", "output": "28554 815330916 " }, { "input": "19562 31702689720 17701", "output": "313325401 " }, { "input": "11729 55221128400 313", "output": "97969 30664297 9597924961 " }, { "input": "5482 100347128000 342", "output": "116964 40001688 13680577296 " }, { "input": "3680 37745933600 10", "output": "10000 100000 1000000 10000000 100000000 1000000000 10000000000 " }, { "input": "17098 191120104800 43", "output": "79507 3418801 147008443 6321363049 " }, { "input": "10462 418807699200 2", "output": "16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 " }, { "input": "30061 641846400000 3", "output": "59049 177147 531441 1594323 4782969 14348907 43046721 129140163 387420489 1162261467 3486784401 10460353203 31381059609 94143178827 282429536481 " }, { "input": "1 1000000000000000000 2", "output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 70368744177664 140737488355328 281474976710656 562949953421312 1125899906842624 2251799813685248 4503599627370496 900719925474099..." }, { "input": "32 2498039712000 4", "output": "64 256 1024 4096 16384 65536 262144 1048576 4194304 16777216 67108864 268435456 1073741824 4294967296 17179869184 68719476736 274877906944 1099511627776 " }, { "input": "1 2576683920000 2", "output": "1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 " }, { "input": "5 25 5", "output": "5 25 " }, { "input": "1 90 90", "output": "1 90 " }, { "input": "95 2200128528000 68", "output": "4624 314432 21381376 1453933568 98867482624 " }, { "input": "64 426314644000 53", "output": "2809 148877 7890481 418195493 22164361129 " }, { "input": "198765 198765 198765", "output": "198765 " }, { "input": "42 2845016496000 12", "output": "144 1728 20736 248832 2985984 35831808 429981696 5159780352 61917364224 743008370688 " }, { "input": "6 6 3", "output": "-1" }, { "input": "1 10 11", "output": "1 " }, { "input": "2 10 11", "output": "-1" }, { "input": "87 160 41", "output": "-1" }, { "input": "237171123124584251 923523399718980912 7150", "output": "-1" }, { "input": "101021572000739548 453766043506276015 8898", "output": "-1" }, { "input": "366070689449360724 928290634811046396 8230", "output": "-1" }, { "input": "438133886369772308 942612870269666780 7193", "output": "-1" }, { "input": "10 10 10", "output": "10 " }, { "input": "16 16 256", "output": "-1" }, { "input": "1 1000000000000000000 1000000000", "output": "1 1000000000 1000000000000000000 " }, { "input": "1000000000000000000 1000000000000000000 1000000000", "output": "1000000000000000000 " }, { "input": "1000000000 1000000000000000000 1000000000", "output": "1000000000 1000000000000000000 " }, { "input": "1 1 4", "output": "1 " }, { "input": "1 999999999999999999 1000000000", "output": "1 1000000000 " }, { "input": "1 1000000000000000000 999999990", "output": "1 999999990 999999980000000100 " }, { "input": "1 1000000000000000000 999999984", "output": "1 999999984 999999968000000256 " }, { "input": "1 1000000000000000000 324325", "output": "1 324325 105186705625 34114678301828125 " }, { "input": "1 1000000000000000000 999999523", "output": "1 999999523 999999046000227529 " }, { "input": "1 243 3", "output": "1 3 9 27 81 243 " }, { "input": "62769392426654367 567152589733560993 688813", "output": "326816522793383797 " }, { "input": "1 1000000000000000000 690852001", "output": "1 690852001 477276487285704001 " }, { "input": "1 1000000000000000000 918745157", "output": "1 918745157 844092663510954649 " }, { "input": "1 1000000000000000000 131299843", "output": "1 131299843 17239648771824649 " }, { "input": "2861381721051425 2861381721051425 1234", "output": "-1" } ]
1,622,076,631
331
PyPy 3
WRONG_ANSWER
TESTS
2
92
102,400
from collections import defaultdict, deque from heapq import heappush, heappop from math import inf, log ri = lambda : map(int, input().split()) ro = lambda : int(input()) def solve(): l,r,k = ri() if k > r: print(-1) return elif k < l: if k == 1: print(1) return curr = int(log(l, k)) curr += 1 while curr <= r: print(curr, end = " ") curr *= k else: print(1, end = " ") curr = k while curr <= r: print(curr, end = " ") curr *= k print() t = 1 #t = int(input()) while t: t -= 1 solve()
Title: Link/Cut Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?) Given integers *l*, *r* and *k*, you need to print all powers of number *k* within range from *l* to *r* inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him! Input Specification: The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). Output Specification: Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). Demo Input: ['1 10 2\n', '2 4 5\n'] Demo Output: ['1 2 4 8 ', '-1'] Note: Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed.
```python from collections import defaultdict, deque from heapq import heappush, heappop from math import inf, log ri = lambda : map(int, input().split()) ro = lambda : int(input()) def solve(): l,r,k = ri() if k > r: print(-1) return elif k < l: if k == 1: print(1) return curr = int(log(l, k)) curr += 1 while curr <= r: print(curr, end = " ") curr *= k else: print(1, end = " ") curr = k while curr <= r: print(curr, end = " ") curr *= k print() t = 1 #t = int(input()) while t: t -= 1 solve() ```
0
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "480", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "49", "output": "YES" }, { "input": "56", "output": "YES" }, { "input": "124", "output": "YES" }, { "input": "1000", "output": "YES" }, { "input": "999", "output": "NO" }, { "input": "298", "output": "NO" }, { "input": "274", "output": "NO" }, { "input": "998", "output": "NO" }, { "input": "42", "output": "YES" }, { "input": "788", "output": "YES" }, { "input": "70", "output": "YES" }, { "input": "444", "output": "YES" }, { "input": "777", "output": "YES" }, { "input": "799", "output": "YES" }, { "input": "25", "output": "NO" }, { "input": "882", "output": "YES" }, { "input": "88", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "YES" }, { "input": "94", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "141", "output": "YES" } ]
1,699,633,382
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
lucky = [4,7,47,74,44,77,444,777,447,474,477,774,747,744] n = int(input()) ans = False if n in lucky: ans=True else: for i in lucky: if n%i == 0: print(True) break
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. Output Specification: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['47\n', '16\n', '78\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
```python lucky = [4,7,47,74,44,77,444,777,447,474,477,774,747,744] n = int(input()) ans = False if n in lucky: ans=True else: for i in lucky: if n%i == 0: print(True) break ```
0
453
A
Little Pony and Expected Maximum
PROGRAMMING
1,600
[ "probabilities" ]
null
null
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
[ "6 1\n", "6 3\n", "2 2\n" ]
[ "3.500000000000\n", "4.958333333333\n", "1.750000000000\n" ]
Consider the third test example. If you've made two tosses: 1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2. The probability of each outcome is 0.25, that is expectation equals to: You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
500
[ { "input": "6 1", "output": "3.500000000000" }, { "input": "6 3", "output": "4.958333333333" }, { "input": "2 2", "output": "1.750000000000" }, { "input": "5 4", "output": "4.433600000000" }, { "input": "5 8", "output": "4.814773760000" }, { "input": "3 10", "output": "2.982641534996" }, { "input": "3 6", "output": "2.910836762689" }, { "input": "1 8", "output": "1.000000000000" }, { "input": "24438 9", "output": "21994.699969310015" }, { "input": "94444 9", "output": "85000.099992058866" }, { "input": "8 66716", "output": "8.000000000000" }, { "input": "4 25132", "output": "4.000000000000" }, { "input": "51520 73331", "output": "51519.682650242677" }, { "input": "54230 31747", "output": "54228.743352775018" }, { "input": "24236 90163", "output": "24235.975171545670" }, { "input": "26946 99523", "output": "26945.974480086279" }, { "input": "50323 7", "output": "44033.124988408454" }, { "input": "53033 3", "output": "39775.249995286234" }, { "input": "55743 5", "output": "46452.999992525307" }, { "input": "59964 79", "output": "59214.949890211828" }, { "input": "1 1", "output": "1.000000000000" }, { "input": "1 1", "output": "1.000000000000" }, { "input": "3 1", "output": "2.000000000000" }, { "input": "1 2", "output": "1.000000000000" }, { "input": "53513 34040", "output": "53511.875329020870" }, { "input": "100000 100000", "output": "99999.418033254507" }, { "input": "1 100000", "output": "1.000000000000" }, { "input": "100000 1", "output": "50000.499999999935" }, { "input": "2 100000", "output": "2.000000000000" }, { "input": "100000 2", "output": "66667.166665000332" }, { "input": "50000 100000", "output": "49999.843487110789" }, { "input": "99999 1111", "output": "99909.571915885972" }, { "input": "99999 99999", "output": "99998.418033254609" }, { "input": "1000 1000", "output": "999.419018443269" }, { "input": "50000 50000", "output": "49999.418043215679" }, { "input": "88888 88888", "output": "88887.418034499773" }, { "input": "99999 100000", "output": "99998.418042461126" }, { "input": "100000 555", "output": "99820.643422392372" }, { "input": "10000 10000", "output": "9999.418122897887" }, { "input": "100000 5001", "output": "99980.503829474910" }, { "input": "100000 1000", "output": "99900.599066768002" } ]
1,602,984,518
2,147,483,647
Python 3
OK
TESTS
41
155
0
faces,vezes = [int(s) for s in input().split(' ')] total = 0 last = 0 for i in range(1, faces+1): aux = (i/faces)**vezes total += (aux-last)*i last = aux print(total)
Title: Little Pony and Expected Maximum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times. Input Specification: A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). Output Specification: Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. Demo Input: ['6 1\n', '6 3\n', '2 2\n'] Demo Output: ['3.500000000000\n', '4.958333333333\n', '1.750000000000\n'] Note: Consider the third test example. If you've made two tosses: 1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2. The probability of each outcome is 0.25, that is expectation equals to: You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
```python faces,vezes = [int(s) for s in input().split(' ')] total = 0 last = 0 for i in range(1, faces+1): aux = (i/faces)**vezes total += (aux-last)*i last = aux print(total) ```
3
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "4\n82 46 8 44", "output": "3 1\n4 2" }, { "input": "2\n35 50", "output": "1 2" }, { "input": "8\n24 39 49 38 44 64 44 50", "output": "1 6\n4 8\n2 3\n5 7" }, { "input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14", "output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15" }, { "input": "12\n22 83 2 67 55 12 40 93 83 73 12 28", "output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5" }, { "input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43", "output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7" }, { "input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58", "output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16" }, { "input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62", "output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12" }, { "input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76", "output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3" }, { "input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8", "output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5" }, { "input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41", "output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36" }, { "input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55", "output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12" }, { "input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25", "output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27" }, { "input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30", "output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10" }, { "input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39", "output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32" }, { "input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26", "output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54" }, { "input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30", "output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10" }, { "input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18", "output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34" }, { "input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65", "output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53" }, { "input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50", "output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14" }, { "input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57", "output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7" }, { "input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49", "output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24" }, { "input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69", "output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9" }, { "input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57", "output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20" }, { "input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34", "output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11" }, { "input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43", "output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3" }, { "input": "4\n100 100 1 1", "output": "3 2\n4 1" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51" }, { "input": "4\n3 4 4 5", "output": "1 4\n2 3" }, { "input": "4\n1 1 2 2", "output": "1 4\n2 3" }, { "input": "4\n1 2 3 4", "output": "1 4\n2 3" } ]
1,615,611,801
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
307,200
n = int(input()) arr = list(map(int,input().split())) s = sum(arr)//n s *= 2 memo = {i:False for i in range(n)} for i in range(n): if memo[i] == False: for j in range(i+1, n): if memo[j] == False and arr[j] == s - arr[i]: memo[j] = True memo[i] = True break print(i+1,j+1)
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible. Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. Output Specification: Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them. Demo Input: ['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n'] Demo Output: ['1 3\n6 2\n4 5\n', '1 2\n3 4\n'] Note: In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
```python n = int(input()) arr = list(map(int,input().split())) s = sum(arr)//n s *= 2 memo = {i:False for i in range(n)} for i in range(n): if memo[i] == False: for j in range(i+1, n): if memo[j] == False and arr[j] == s - arr[i]: memo[j] = True memo[i] = True break print(i+1,j+1) ```
0
221
A
Little Elephant and Function
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists.
[ "1\n", "2\n" ]
[ "1 ", "2 1 " ]
none
500
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "2 1 " }, { "input": "3", "output": "3 1 2 " }, { "input": "4", "output": "4 1 2 3 " }, { "input": "5", "output": "5 1 2 3 4 " }, { "input": "6", "output": "6 1 2 3 4 5 " }, { "input": "7", "output": "7 1 2 3 4 5 6 " }, { "input": "1000", "output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "999", "output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "998", "output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "997", "output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "900", "output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "101", "output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "3", "output": "3 1 2 " }, { "input": "67", "output": "67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 " }, { "input": "779", "output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "195", "output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "907", "output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "971", "output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "683", "output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "99", "output": "99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 " }, { "input": "811", "output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "875", "output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "291", "output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3", "output": "3 1 2 " }, { "input": "419", "output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "779", "output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "195", "output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "907", "output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "21", "output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 " }, { "input": "22", "output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 " }, { "input": "23", "output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 " }, { "input": "24", "output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 " }, { "input": "25", "output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 " } ]
1,597,778,722
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
n = int(input()) x = [] for i in range(2, n+1): x.append(i) x.append(1) for i in x: print(i, end = " ")
Title: Little Elephant and Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. Output Specification: In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Demo Input: ['1\n', '2\n'] Demo Output: ['1 ', '2 1 '] Note: none
```python n = int(input()) x = [] for i in range(2, n+1): x.append(i) x.append(1) for i in x: print(i, end = " ") ```
0
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work.
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "52870" }, { "input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245", "output": "46995" }, { "input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434", "output": "85540" }, { "input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357", "output": "67147" }, { "input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422", "output": "85876" }, { "input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282", "output": "38570" }, { "input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431", "output": "11134" }, { "input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424", "output": "59043" }, { "input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369", "output": "53608" }, { "input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438", "output": "84067" }, { "input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439", "output": "79844" }, { "input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437", "output": "82686" }, { "input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437", "output": "92356" }, { "input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434", "output": "107490" }, { "input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401", "output": "25258" }, { "input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419", "output": "23992" } ]
1,592,410,109
2,147,483,647
PyPy 3
OK
TESTS
30
310
0
n, p1, p2, p3, t1, t2 = map(int, input().split()) lastR = -1 total = 0 for i in range(n): l, r = map(int, input().split()) if lastR != -1: gap = l - lastR if gap > t1: if gap > t1 + t2: total += (gap - t1 - t2) * p3 total += t2 * p2 total += t1 * p1 else: total += (gap - t1) * p2 total += t1 * p1 else: total += gap * p1 total += (r - l) * p1 lastR = r print(total)
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. Input Specification: The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work. Output Specification: Output the answer to the problem. Demo Input: ['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n'] Demo Output: ['30', '570'] Note: none
```python n, p1, p2, p3, t1, t2 = map(int, input().split()) lastR = -1 total = 0 for i in range(n): l, r = map(int, input().split()) if lastR != -1: gap = l - lastR if gap > t1: if gap > t1 + t2: total += (gap - t1 - t2) * p3 total += t2 * p2 total += t1 * p1 else: total += (gap - t1) * p2 total += t1 * p1 else: total += gap * p1 total += (r - l) * p1 lastR = r print(total) ```
3.845
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" }, { "input": "lwzjp\ninjit", "output": "-1" }, { "input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "output": "eodnlemiicdedmkcgavqbnqmm" }, { "input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "output": "-1" }, { "input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf" }, { "input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen", "output": "-1" }, { "input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb" }, { "input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym", "output": "-1" }, { "input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib" }, { "input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew", "output": "-1" }, { "input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv" }, { "input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns", "output": "-1" }, { "input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf" }, { "input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp", "output": "-1" }, { "input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp" }, { "input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej", "output": "-1" }, { "input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe" }, { "input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang", "output": "-1" }, { "input": "ftfr\nftfr", "output": "ftfr" }, { "input": "ftr\nftr", "output": "ftr" }, { "input": "shftr\nshftr", "output": "shftr" }, { "input": "vkvkkv\nvkvkkv", "output": "vkvkkv" }, { "input": "ftrd\nftrd", "output": "ftrd" }, { "input": "fztr\nfztr", "output": "fztr" }, { "input": "frtr\nfrtr", "output": "frtr" }, { "input": "shdftr\nshdftr", "output": "shdftr" }, { "input": "zzz\nzzz", "output": "zzz" }, { "input": "shtr\nshtr", "output": "shtr" }, { "input": "aaaaa\nzzzzz", "output": "-1" }, { "input": "efr\nefr", "output": "efr" } ]
1,492,588,282
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
x = input() y = input() alf = 'abcdefghijklmnopqrstuvwxyz' z = '' for i in range(len(X)): if y[i] == x[i]: z += x[i] elif alf.find(x[i]) < alf.find(y[i]): z += y[i] elif alf.find(x[i]) > alf.find(y[i]): return -1 return z
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. Input Specification: The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. Output Specification: If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. Demo Input: ['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n'] Demo Output: ['ba\n', 'xiyez\n', '-1\n'] Note: The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
```python x = input() y = input() alf = 'abcdefghijklmnopqrstuvwxyz' z = '' for i in range(len(X)): if y[i] == x[i]: z += x[i] elif alf.find(x[i]) < alf.find(y[i]): z += y[i] elif alf.find(x[i]) > alf.find(y[i]): return -1 return z ```
-1
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,544,620,909
2,147,483,647
Python 3
OK
TESTS
79
124
0
l, r, a = map(int, input().split()) if min(l,r)+a <= max(l, r): print(2 * (min(l,r)+a)) elif l == r == a or l == r and a == 0: if sum([l,r,a]) % 2 == 0: print(sum([l,r,a])) else: print(sum([l,r,a])-1) elif min(l, r) == 0 and a == 0: print(0) else: if sum([l,r,a]) % 2 == 0: print(sum([l,r,a])) else: print(sum([l,r,a])-1)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python l, r, a = map(int, input().split()) if min(l,r)+a <= max(l, r): print(2 * (min(l,r)+a)) elif l == r == a or l == r and a == 0: if sum([l,r,a]) % 2 == 0: print(sum([l,r,a])) else: print(sum([l,r,a])-1) elif min(l, r) == 0 and a == 0: print(0) else: if sum([l,r,a]) % 2 == 0: print(sum([l,r,a])) else: print(sum([l,r,a])-1) ```
3
697
B
Barnicle
PROGRAMMING
1,400
[ "brute force", "implementation", "math", "strings" ]
null
null
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number *x* is the notation of form *AeB*, where *A* is a real number and *B* is an integer and *x*<==<=*A*<=×<=10*B* is true. In our case *A* is between 0 and 9 and *B* is non-negative. Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.
The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=&lt;<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value. *a* and *b* contain no leading zeros and *d* contains no trailing zeros (but may be equal to 0). Also, *b* can not be non-zero if *a* is zero.
Print the only real number *x* (the desired distance value) in the only line in its decimal notation. Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroes (but may be equal to zero), and *q* is an integer that have no trailing zeroes (and may not be equal to zero).
[ "8.549e2\n", "8.549e3\n", "0.33e0\n" ]
[ "854.9\n", "8549\n", "0.33\n" ]
none
1,000
[ { "input": "8.549e2", "output": "854.9" }, { "input": "8.549e3", "output": "8549" }, { "input": "0.33e0", "output": "0.33" }, { "input": "1.31e1", "output": "13.1" }, { "input": "1.038e0", "output": "1.038" }, { "input": "8.25983e5", "output": "825983" }, { "input": "8.77056e6", "output": "8770560" }, { "input": "4.28522890224373996236468418851564462623381500262405e30", "output": "4285228902243739962364684188515.64462623381500262405" }, { "input": "4.09336275522154223604344399571355118601483591618747e85", "output": "40933627552215422360434439957135511860148359161874700000000000000000000000000000000000" }, { "input": "2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85", "output": "20629094807595491132306264747042243928486303384791951220362096240931158821630792563855.724946791054152" }, { "input": "0.7e0", "output": "0.7" }, { "input": "0.75e0", "output": "0.75" }, { "input": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451e0", "output": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451" }, { "input": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197e0", "output": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197" }, { "input": "1.7282220592677586155528202123627915992640276211396528871e0", "output": "1.7282220592677586155528202123627915992640276211396528871" }, { "input": "1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89", "output": "191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251" }, { "input": "7.0e100", "output": "70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1.7390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051e100", "output": "17390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051" }, { "input": "4.6329496401734172195e50", "output": "463294964017341721950000000000000000000000000000000" }, { "input": "2.806303180541991592302230754797823269634e39", "output": "2806303180541991592302230754797823269634" }, { "input": "5.8743505652112692964508303637002e64", "output": "58743505652112692964508303637002000000000000000000000000000000000" }, { "input": "6.8778661934058405217475274375560252344373481358834598914724956711e31", "output": "68778661934058405217475274375560.252344373481358834598914724956711" }, { "input": "9.4e100", "output": "94000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3.2371070627618799335840070613481911588919091676203766004638236894609230433739617153911544972468224113e50", "output": "323710706276187993358400706134819115889190916762037.66004638236894609230433739617153911544972468224113" }, { "input": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929e0", "output": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929" }, { "input": "7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1", "output": "77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625" }, { "input": "8.1089882894234341219420177467603732503076124872188628349726911362800974096687340341040683238197289136e31", "output": "81089882894234341219420177467603.732503076124872188628349726911362800974096687340341040683238197289136" }, { "input": "9.6576660076120385279859051742522204516365367878315639937449558670629833997839913220859648564428655877e99", "output": "9657666007612038527985905174252220451636536787831563993744955867062983399783991322085964856442865587.7" }, { "input": "0.0e0", "output": "0" }, { "input": "1.0e0", "output": "1" }, { "input": "8.0e0", "output": "8" }, { "input": "3.0e0", "output": "3" }, { "input": "4.0e0", "output": "4" }, { "input": "2.0e0", "output": "2" }, { "input": "9.0e0", "output": "9" }, { "input": "0.888888e0", "output": "0.888888" }, { "input": "9.99999999999999999999999999999999999999999999999999999999999999999999999999999999e100", "output": "99999999999999999999999999999999999999999999999999999999999999999999999999999999900000000000000000000" }, { "input": "5.0e0", "output": "5" }, { "input": "1.0e10", "output": "10000000000" }, { "input": "1.0e5", "output": "100000" }, { "input": "6.0e0", "output": "6" }, { "input": "1.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e1", "output": "11.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" } ]
1,558,979,833
2,533
Python 3
WRONG_ANSWER
TESTS
7
108
0
s = input() x =(eval(s)) if (int(x)) == x: print(int(x)) else: print(x)
Title: Barnicle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number *x* is the notation of form *AeB*, where *A* is a real number and *B* is an integer and *x*<==<=*A*<=×<=10*B* is true. In our case *A* is between 0 and 9 and *B* is non-negative. Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding. Input Specification: The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=&lt;<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value. *a* and *b* contain no leading zeros and *d* contains no trailing zeros (but may be equal to 0). Also, *b* can not be non-zero if *a* is zero. Output Specification: Print the only real number *x* (the desired distance value) in the only line in its decimal notation. Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroes (but may be equal to zero), and *q* is an integer that have no trailing zeroes (and may not be equal to zero). Demo Input: ['8.549e2\n', '8.549e3\n', '0.33e0\n'] Demo Output: ['854.9\n', '8549\n', '0.33\n'] Note: none
```python s = input() x =(eval(s)) if (int(x)) == x: print(int(x)) else: print(x) ```
0
354
A
Vasya and Robot
PROGRAMMING
1,500
[ "brute force", "greedy", "math" ]
null
null
Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 1. Take the leftmost item with the left hand and spend *w**i*<=·<=*l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 1. Take the rightmost item with the right hand and spend *w**j*<=·<=*r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
The first line contains five integers *n*,<=*l*,<=*r*,<=*Q**l*,<=*Q**r* (1<=≤<=*n*<=≤<=105;<=1<=≤<=*l*,<=*r*<=≤<=100;<=1<=≤<=*Q**l*,<=*Q**r*<=≤<=104). The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=100).
In the single line print a single number — the answer to the problem.
[ "3 4 4 19 1\n42 3 99\n", "4 7 2 3 9\n1 2 3 4\n" ]
[ "576\n", "34\n" ]
Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
500
[ { "input": "3 4 4 19 1\n42 3 99", "output": "576" }, { "input": "4 7 2 3 9\n1 2 3 4", "output": "34" }, { "input": "2 100 100 10000 10000\n100 100", "output": "20000" }, { "input": "2 3 4 5 6\n1 2", "output": "11" }, { "input": "1 78 94 369 10000\n93", "output": "7254" }, { "input": "1 94 78 369 10000\n93", "output": "7254" }, { "input": "5 1 100 1 10000\n1 2 3 4 5", "output": "19" }, { "input": "5 100 1 10000 1\n1 2 3 4 5", "output": "19" }, { "input": "5 1 100 10000 1\n1 2 3 4 5", "output": "906" }, { "input": "5 100 1 1 10000\n1 2 3 4 5", "output": "312" }, { "input": "6 32 47 965 897\n7 4 1 3 5 4", "output": "948" }, { "input": "7 3 13 30 978\n1 2 3 4 5 1 7", "output": "199" }, { "input": "7 13 3 978 30\n7 1 5 4 3 2 1", "output": "199" } ]
1,664,362,353
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
0
46
268,390,400
import sys sys.setrecursionlimit(10**6) n,l,r,q1,q2 = [int(i) for i in input().split()] arr = list(map(int,input().split())) dp = {} def solve(i,j,l1,r1): if i > j: return 0 if (i,j,l1,r1) in dp: return dp[(i,j,l1,r1)] if l1: left = ((arr[i] * l) + q1) + solve(i+1 , j , 1 , 0) else: left = ((arr[i] * l)) + solve(i+1 , j , 1 , 0) if r1: right = ((arr[j] * r) + q2) + solve(i , j-1 , 0 , 1) else: right = ((arr[j] * r)) + solve(i , j-1 , 0 , 1) dp[(i,j,l1,r1)] = min(left , right) return dp[(i,j,l1,r1)] print(solve(0 , n-1 , 0 , 0))
Title: Vasya and Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 1. Take the leftmost item with the left hand and spend *w**i*<=·<=*l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 1. Take the rightmost item with the right hand and spend *w**j*<=·<=*r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items. Input Specification: The first line contains five integers *n*,<=*l*,<=*r*,<=*Q**l*,<=*Q**r* (1<=≤<=*n*<=≤<=105;<=1<=≤<=*l*,<=*r*<=≤<=100;<=1<=≤<=*Q**l*,<=*Q**r*<=≤<=104). The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=100). Output Specification: In the single line print a single number — the answer to the problem. Demo Input: ['3 4 4 19 1\n42 3 99\n', '4 7 2 3 9\n1 2 3 4\n'] Demo Output: ['576\n', '34\n'] Note: Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
```python import sys sys.setrecursionlimit(10**6) n,l,r,q1,q2 = [int(i) for i in input().split()] arr = list(map(int,input().split())) dp = {} def solve(i,j,l1,r1): if i > j: return 0 if (i,j,l1,r1) in dp: return dp[(i,j,l1,r1)] if l1: left = ((arr[i] * l) + q1) + solve(i+1 , j , 1 , 0) else: left = ((arr[i] * l)) + solve(i+1 , j , 1 , 0) if r1: right = ((arr[j] * r) + q2) + solve(i , j-1 , 0 , 1) else: right = ((arr[j] * r)) + solve(i , j-1 , 0 , 1) dp[(i,j,l1,r1)] = min(left , right) return dp[(i,j,l1,r1)] print(solve(0 , n-1 , 0 , 0)) ```
0
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,688,451,023
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
26,521,600
if __name__=='__main__': nums = [int(i) for i in input().split(' ')] n = nums[0] q = nums[1] nums = [int(i) for i in input().split(' ')] nums = sorted(nums) indices = [0]*n while q: pos = [int(i) for i in input().split(' ')] l = pos[0]-1 r = pos[1]-1 for i in range(l, r+1): indices[i]+=1 q-=1 ret_ind = sorted(range(len(indices)), key=lambda index: indices[index]) sum = 0 for i in range(n): sum+=nums[i]*indices[ret_ind[i]] print(sum)
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python if __name__=='__main__': nums = [int(i) for i in input().split(' ')] n = nums[0] q = nums[1] nums = [int(i) for i in input().split(' ')] nums = sorted(nums) indices = [0]*n while q: pos = [int(i) for i in input().split(' ')] l = pos[0]-1 r = pos[1]-1 for i in range(l, r+1): indices[i]+=1 q-=1 ret_ind = sorted(range(len(indices)), key=lambda index: indices[index]) sum = 0 for i in range(n): sum+=nums[i]*indices[ret_ind[i]] print(sum) ```
0
306
A
Candies
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible. For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one.
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
[ "12 3\n", "15 4\n", "18 7\n" ]
[ "4 4 4 ", "3 4 4 4 ", "2 2 2 3 3 3 3 " ]
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
500
[ { "input": "12 4", "output": "3 3 3 3 " }, { "input": "15 6", "output": "2 2 2 3 3 3 " }, { "input": "18 8", "output": "2 2 2 2 2 2 3 3 " }, { "input": "1 1", "output": "1 " }, { "input": "2 1", "output": "2 " }, { "input": "100 1", "output": "100 " }, { "input": "100 100", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "100 10", "output": "10 10 10 10 10 10 10 10 10 10 " }, { "input": "64 8", "output": "8 8 8 8 8 8 8 8 " }, { "input": "81 27", "output": "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " }, { "input": "100 99", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 " }, { "input": "100 51", "output": "1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100 49", "output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 " }, { "input": "100 13", "output": "7 7 7 7 8 8 8 8 8 8 8 8 8 " }, { "input": "97 11", "output": "8 8 9 9 9 9 9 9 9 9 9 " }, { "input": "19 3", "output": "6 6 7 " }, { "input": "99 10", "output": "9 10 10 10 10 10 10 10 10 10 " }, { "input": "88 5", "output": "17 17 18 18 18 " }, { "input": "87 34", "output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " }, { "input": "97 55", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " } ]
1,596,967,724
2,147,483,647
PyPy 3
OK
TESTS
20
248
20,172,800
#In the name of God a = [] n, m = map(int, (input()).split()) q = n // m for i in range(m): if (i < n % m): a.append(q + 1) else: a.append(q) for i in a: print(i, end = ' ')
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible. For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one. Input Specification: The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. Output Specification: Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. Demo Input: ['12 3\n', '15 4\n', '18 7\n'] Demo Output: ['4 4 4 ', '3 4 4 4 ', '2 2 2 3 3 3 3 '] Note: Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
```python #In the name of God a = [] n, m = map(int, (input()).split()) q = n // m for i in range(m): if (i < n % m): a.append(q + 1) else: a.append(q) for i in a: print(i, end = ' ') ```
3
961
A
Tetris
PROGRAMMING
900
[ "implementation" ]
null
null
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive.
The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear.
Print one integer — the amount of points you will receive.
[ "3 9\n1 1 2 2 2 3 1 2 3\n" ]
[ "2\n" ]
In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$. So the answer will be equal to $2$.
0
[ { "input": "3 9\n1 1 2 2 2 3 1 2 3", "output": "2" }, { "input": "1 7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "3 5\n1 1 1 2 3", "output": "1" }, { "input": "4 6\n4 4 4 4 4 4", "output": "0" }, { "input": "4 6\n2 3 4 4 4 4", "output": "0" }, { "input": "3 12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "4" }, { "input": "8 8\n2 2 3 4 5 6 7 8", "output": "0" }, { "input": "100 1\n50", "output": "0" }, { "input": "2 1\n2", "output": "0" }, { "input": "2 1\n1", "output": "0" }, { "input": "2 4\n1 2 1 1", "output": "1" }, { "input": "3 4\n3 2 2 2", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "2 5\n2 1 1 2 1", "output": "2" }, { "input": "15 3\n13 14 15", "output": "0" }, { "input": "4 9\n1 2 3 1 2 3 1 2 3", "output": "0" }, { "input": "100 3\n1 2 3", "output": "0" }, { "input": "1000 10\n999 999 998 34 454 546 343 35 34 1000", "output": "0" }, { "input": "4 2\n1 2", "output": "0" } ]
1,670,485,584
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n = list(map(int,input().split())) lst = list(map(int,input().split())) dic = {y:0 for y in lst } for i in lst: dic[i]+=1 score = 0 for i in dic: score += dic[i]//3 print(score)
Title: Tetris Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive. Input Specification: The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. Output Specification: Print one integer — the amount of points you will receive. Demo Input: ['3 9\n1 1 2 2 2 3 1 2 3\n'] Demo Output: ['2\n'] Note: In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$. So the answer will be equal to $2$.
```python n = list(map(int,input().split())) lst = list(map(int,input().split())) dic = {y:0 for y in lst } for i in lst: dic[i]+=1 score = 0 for i in dic: score += dic[i]//3 print(score) ```
0
0
none
none
none
0
[ "none" ]
null
null
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence *a*1,<=*a*2,<=...,<=*a**n*. Little Tommy is among them. He would like to choose an interval [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), then reverse *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r* so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices *p*1,<=*p*2,<=...,<=*p**k*, such that *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* and *a**p*1<=≤<=*a**p*2<=≤<=...<=≤<=*a**p**k*. The length of the subsequence is *k*.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence. The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*).
Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence.
[ "4\n1 2 1 2\n", "10\n1 1 2 2 2 1 1 2 2 1\n" ]
[ "4\n", "9\n" ]
In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
0
[ { "input": "4\n1 2 1 2", "output": "4" }, { "input": "10\n1 1 2 2 2 1 1 2 2 1", "output": "9" }, { "input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 2 2", "output": "116" }, { "input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "200" }, { "input": "1\n2", "output": "1" }, { "input": "2\n1 2", "output": "2" }, { "input": "2\n2 1", "output": "2" }, { "input": "3\n2 1 2", "output": "3" }, { "input": "3\n1 2 1", "output": "3" }, { "input": "100\n1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "89" }, { "input": "100\n1 2 1 2 2 2 1 1 2 2 2 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 1 2 2 1 1 1 1 1 1 1 2 2 2 1 1 2 2 1 2 2 1 1 1 2 2 1 1 1 1", "output": "60" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 2 1 1 1 1 1 1 2 2", "output": "91" }, { "input": "100\n2 2 2 2 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 1 1 2 1 1 2 2 1 1 1 1 2 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 2 2 1 1 1 2 2", "output": "63" }, { "input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2", "output": "187" }, { "input": "200\n1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 2 1 2 1 1 2 2 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 2 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 2 1 2 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 2 1 1 1 1 2 2 2 1 2 1 2 2 1 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 1 2 2 1 2 1 1 2", "output": "131" }, { "input": "200\n1 2 2 1 2 1 1 1 1 1 2 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 1 1 2 2 1 1 1 2 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 2 2 2 1 2 1 1 2 2 1 2 1 1 1 2 2 1 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 2 2 2 2 2 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 1 1 1 2 2 2 1 2 2 1 1 1 2 2 2 1 1 2 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 1 2 2 1 1 1 2 2 2 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 2 1 1 1 2 2 2 2 1 1 2 2 2 2", "output": "118" }, { "input": "20\n1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 2 1 1 2 1", "output": "16" }, { "input": "200\n2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "191" }, { "input": "10\n2 2 2 2 2 2 2 2 2 1", "output": "10" }, { "input": "6\n2 2 2 1 1 1", "output": "6" } ]
1,518,788,414
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
5,632,000
n=int(input()) a=[int(k)-1 for k in input().split(" ")] nbmax= [0,0,0,0] #print(a) for k in a: #print("k is:",k) p#rint("a is:",a) if k: nbmax[1]=max(nbmax[1]+1,nbmax[0]+1) nbmax[3]=max(nbmax[3]+1,nbmax[2]+1) #print("nbmax upper:", nbmax) else: nbmax[0]+=1 nbmax[2]=max(nbmax[1]+1,nbmax[2]+1) #print("nbmax lower:", nbmax) print (max(nbmax)) ''' #include <bits/stdc++.h> using namespace std; int main() { int n, a, num[4] = {0}; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a); if(a == 1) { num[0]++; num[2] = max(num[2], num[1]) + 1; } else { num[1] = max(num[1], num[0]) + 1; num[3] = max(num[3], num[2]) + 1; } } int ans = 0; for(int i = 0; i < 4; i++) ans = max(ans, num[i]); printf("%d\n", ans); return 0; }'''
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence *a*1,<=*a*2,<=...,<=*a**n*. Little Tommy is among them. He would like to choose an interval [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), then reverse *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r* so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices *p*1,<=*p*2,<=...,<=*p**k*, such that *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* and *a**p*1<=≤<=*a**p*2<=≤<=...<=≤<=*a**p**k*. The length of the subsequence is *k*. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence. The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*). Output Specification: Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Demo Input: ['4\n1 2 1 2\n', '10\n1 1 2 2 2 1 1 2 2 1\n'] Demo Output: ['4\n', '9\n'] Note: In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
```python n=int(input()) a=[int(k)-1 for k in input().split(" ")] nbmax= [0,0,0,0] #print(a) for k in a: #print("k is:",k) p#rint("a is:",a) if k: nbmax[1]=max(nbmax[1]+1,nbmax[0]+1) nbmax[3]=max(nbmax[3]+1,nbmax[2]+1) #print("nbmax upper:", nbmax) else: nbmax[0]+=1 nbmax[2]=max(nbmax[1]+1,nbmax[2]+1) #print("nbmax lower:", nbmax) print (max(nbmax)) ''' #include <bits/stdc++.h> using namespace std; int main() { int n, a, num[4] = {0}; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a); if(a == 1) { num[0]++; num[2] = max(num[2], num[1]) + 1; } else { num[1] = max(num[1], num[0]) + 1; num[3] = max(num[3], num[2]) + 1; } } int ans = 0; for(int i = 0; i < 4; i++) ans = max(ans, num[i]); printf("%d\n", ans); return 0; }''' ```
-1
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,697,553,011
2,147,483,647
Python 3
OK
TESTS
25
46
102,400
# Read input n = int(input()) results = input() # Count the number of 'A' and 'D' in the results anton_wins = results.count('A') danik_wins = results.count('D') # Determine the winner if anton_wins > danik_wins: print("Anton") elif anton_wins < danik_wins: print("Danik") else: print("Friendship")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python # Read input n = int(input()) results = input() # Count the number of 'A' and 'D' in the results anton_wins = results.count('A') danik_wins = results.count('D') # Determine the winner if anton_wins > danik_wins: print("Anton") elif anton_wins < danik_wins: print("Danik") else: print("Friendship") ```
3
322
A
Ciel and Dancing
PROGRAMMING
1,000
[ "greedy" ]
null
null
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: - either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); - or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room.
In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*.
[ "2 1\n", "2 2\n" ]
[ "2\n1 1\n2 1\n", "3\n1 1\n1 2\n2 2\n" ]
In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song). And in test case 2, we have 2 boys with 2 girls, the answer is 3.
500
[ { "input": "2 1", "output": "2\n1 1\n2 1" }, { "input": "2 2", "output": "3\n1 1\n1 2\n2 2" }, { "input": "1 1", "output": "1\n1 1" }, { "input": "2 3", "output": "4\n1 1\n1 2\n1 3\n2 3" }, { "input": "4 4", "output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4" }, { "input": "1 12", "output": "12\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12" }, { "input": "12 1", "output": "12\n1 1\n12 1\n11 1\n10 1\n9 1\n8 1\n7 1\n6 1\n5 1\n4 1\n3 1\n2 1" }, { "input": "100 100", "output": "199\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "24 6", "output": "29\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n24 6\n23 6\n22 6\n21 6\n20 6\n19 6\n18 6\n17 6\n16 6\n15 6\n14 6\n13 6\n12 6\n11 6\n10 6\n9 6\n8 6\n7 6\n6 6\n5 6\n4 6\n3 6\n2 6" }, { "input": "7 59", "output": "65\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n7 59\n6 59\n5 59\n4 59\n3 59\n2 59" }, { "input": "26 75", "output": "100\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n26 75\n25 75\n24 75\n23 75\n22 75\n21 75\n20 75\n19 75\n18 75\n17..." }, { "input": "32 87", "output": "118\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "42 51", "output": "92\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n42 51\n41 51\n40 51\n39 51\n38 51\n37 51\n36 51\n35 51\n34 51\n33 51\n32 51\n31 51\n30 51\n29 51\n28 51\n27 51\n26 51\n25 51\n24 51\n23 51\n22 51\n21 51\n20 51\n19 51\n18 51\n17 51\n16 51\n15 51\n14 51\n13 51\n..." }, { "input": "4 63", "output": "66\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n4 63\n3 63\n2 63" }, { "input": "10 79", "output": "88\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n10 79\n9 79\n8 79\n7 79\n6 79\n5 79\n4 79\n..." }, { "input": "20 95", "output": "114\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "35 55", "output": "89\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n35 55\n34 55\n33 55\n32 55\n31 55\n30 55\n29 55\n28 55\n27 55\n26 55\n25 55\n24 55\n23 55\n22 55\n21 55\n20 55\n19 55\n18 55\n17 55\n16 55\n15 55\n14 55\n13 55\n12 55\n11 55\n10 55\n9 55..." }, { "input": "45 71", "output": "115\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n45 71\n44 71\n43 71\n42 71\n41 71\n40 71\n39 71\n38 71\n37 71\n36 71\n35 71\n34 71\n33 71..." }, { "input": "7 83", "output": "89\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n7 83\n6 83\n5 83\n..." }, { "input": "32 100", "output": "131\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "42 17", "output": "58\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n42 17\n41 17\n40 17\n39 17\n38 17\n37 17\n36 17\n35 17\n34 17\n33 17\n32 17\n31 17\n30 17\n29 17\n28 17\n27 17\n26 17\n25 17\n24 17\n23 17\n22 17\n21 17\n20 17\n19 17\n18 17\n17 17\n16 17\n15 17\n14 17\n13 17\n12 17\n11 17\n10 17\n9 17\n8 17\n7 17\n6 17\n5 17\n4 17\n3 17\n2 17" }, { "input": "1 77", "output": "77\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77" }, { "input": "19 93", "output": "111\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "25 5", "output": "29\n1 1\n1 2\n1 3\n1 4\n1 5\n25 5\n24 5\n23 5\n22 5\n21 5\n20 5\n19 5\n18 5\n17 5\n16 5\n15 5\n14 5\n13 5\n12 5\n11 5\n10 5\n9 5\n8 5\n7 5\n6 5\n5 5\n4 5\n3 5\n2 5" }, { "input": "35 21", "output": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n35 21\n34 21\n33 21\n32 21\n31 21\n30 21\n29 21\n28 21\n27 21\n26 21\n25 21\n24 21\n23 21\n22 21\n21 21\n20 21\n19 21\n18 21\n17 21\n16 21\n15 21\n14 21\n13 21\n12 21\n11 21\n10 21\n9 21\n8 21\n7 21\n6 21\n5 21\n4 21\n3 21\n2 21" }, { "input": "99 99", "output": "197\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "99 100", "output": "198\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "100 99", "output": "198\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." } ]
1,551,118,487
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
216
0
n,m=map(int,input().split()) l=[];count=0;j,i=1,1 print(n+m-1) if(n<=m): while(count!=n+m-1): print(i,j) count+=1 if(count%2==0): i+=1 else: j+=1 else: while (count != n + m - 1): print(i, j) count += 1 if (count % 2 == 0): j += 1 else: i += 1
Title: Ciel and Dancing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: - either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); - or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. Output Specification: In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. Demo Input: ['2 1\n', '2 2\n'] Demo Output: ['2\n1 1\n2 1\n', '3\n1 1\n1 2\n2 2\n'] Note: In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song). And in test case 2, we have 2 boys with 2 girls, the answer is 3.
```python n,m=map(int,input().split()) l=[];count=0;j,i=1,1 print(n+m-1) if(n<=m): while(count!=n+m-1): print(i,j) count+=1 if(count%2==0): i+=1 else: j+=1 else: while (count != n + m - 1): print(i, j) count += 1 if (count % 2 == 0): j += 1 else: i += 1 ```
0
304
A
Pythagorean Theorem II
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation: where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides. Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Print a single integer — the answer to the problem.
[ "5\n", "74\n" ]
[ "1\n", "35\n" ]
none
500
[ { "input": "5", "output": "1" }, { "input": "74", "output": "35" }, { "input": "1000", "output": "881" }, { "input": "586", "output": "472" }, { "input": "2", "output": "0" }, { "input": "362", "output": "258" }, { "input": "778", "output": "653" }, { "input": "194", "output": "120" }, { "input": "906", "output": "786" }, { "input": "659", "output": "535" }, { "input": "75", "output": "37" }, { "input": "787", "output": "664" }, { "input": "851", "output": "730" }, { "input": "563", "output": "446" }, { "input": "979", "output": "862" }, { "input": "395", "output": "291" }, { "input": "755", "output": "634" }, { "input": "171", "output": "103" }, { "input": "883", "output": "759" }, { "input": "400", "output": "294" }, { "input": "817", "output": "693" }, { "input": "177", "output": "107" }, { "input": "593", "output": "476" }, { "input": "305", "output": "214" }, { "input": "721", "output": "595" }, { "input": "785", "output": "664" }, { "input": "497", "output": "383" }, { "input": "913", "output": "791" }, { "input": "625", "output": "507" }, { "input": "334", "output": "236" }, { "input": "10000", "output": "12471" }, { "input": "9999", "output": "12467" } ]
1,685,227,326
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
122
0
n=int(input()) a=0 for i in range (1,n+1): for j in range (i+1,n+1): c=j**2-i**2 p=c**.5 if p-int(p)==0: a+=1 print (a/2)
Title: Pythagorean Theorem II Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation: where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides. Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. Input Specification: The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['5\n', '74\n'] Demo Output: ['1\n', '35\n'] Note: none
```python n=int(input()) a=0 for i in range (1,n+1): for j in range (i+1,n+1): c=j**2-i**2 p=c**.5 if p-int(p)==0: a+=1 print (a/2) ```
0
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,692,815,375
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n=int(input()) m=input() na=m.count('A') nd=m.count('D') if na>nd:print("Anton") if nd>na:print("Danik") else:print("Friendship")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python n=int(input()) m=input() na=m.count('A') nd=m.count('D') if na>nd:print("Anton") if nd>na:print("Danik") else:print("Friendship") ```
0
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 6" }, { "input": "5\n1 1 1 1 1", "output": "0 10" }, { "input": "5\n2 2 2 2 2", "output": "0 10" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0 45" }, { "input": "3\n2 2 2", "output": "0 3" }, { "input": "3\n3 3 3", "output": "0 3" }, { "input": "2\n10000000 100000000", "output": "90000000 1" }, { "input": "5\n5 5 5 5 5", "output": "0 10" }, { "input": "5\n3 3 3 3 3", "output": "0 10" }, { "input": "6\n1 1 1 1 1 1", "output": "0 15" }, { "input": "2\n5 6", "output": "1 1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0 45" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0 45" }, { "input": "4\n4 4 4 4", "output": "0 6" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0 21" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "0 55" }, { "input": "8\n8 8 8 8 8 8 8 8", "output": "0 28" }, { "input": "2\n3 2", "output": "1 1" } ]
1,683,386,593
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
108
20,070,400
n = int(input()) a = list(map(int, input().split())) a.sort() print(a[-1] - a[0], end=" ") if a[0] == a[-1]: print(n * (n - 1) / 2) exit() mi = a[0] ma = a[-1] kmi = 0 kma = 0 for i in range(n): if a[i] == mi: kmi += 1 elif a[i] == ma: kma += 1 print(kmi * kma)
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). Output Specification: The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. Demo Input: ['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n'] Demo Output: ['1 1', '4 1', '2 4'] Note: In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
```python n = int(input()) a = list(map(int, input().split())) a.sort() print(a[-1] - a[0], end=" ") if a[0] == a[-1]: print(n * (n - 1) / 2) exit() mi = a[0] ma = a[-1] kmi = 0 kma = 0 for i in range(n): if a[i] == mi: kmi += 1 elif a[i] == ma: kma += 1 print(kmi * kma) ```
0
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 13 4 3 2", "output": "36" }, { "input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "output": "55" }, { "input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "output": "36" }, { "input": "6\n1000 1 2000 1 3000 1", "output": "11995" }, { "input": "1\n0", "output": "0" }, { "input": "5\n1000000000 1 1000000000 1 1000000000", "output": "4999999996" }, { "input": "5\n1000000000 0 1000000000 0 1000000000", "output": "5000000000" }, { "input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0", "output": "10000000000" }, { "input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "19000000000" }, { "input": "7\n0 1000000000 0 1000000000 0 1000000000 0", "output": "6000000000" }, { "input": "4\n1000000000 -1000000000 1000000000 -1000000000", "output": "7000000000" }, { "input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "39000000000" }, { "input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000", "output": "11000000000" }, { "input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "9000000000" }, { "input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "43000000000" } ]
1,447,726,348
2,147,483,647
Python 3
OK
TESTS
76
295
14,438,400
n=int(input()) l=input().split() m,s=0,0 def dif(a,b): if(a>b): return a-b return b-a for i in range(n): x=int(l[i]) s+=dif(x,m) if(x>m): m+=dif(x,m) elif(x<m): m-=dif(x,m) print(s)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). Output Specification: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Demo Input: ['5\n1 2 3 4 5\n', '4\n1 2 2 1\n'] Demo Output: ['5', '3'] Note: In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
```python n=int(input()) l=input().split() m,s=0,0 def dif(a,b): if(a>b): return a-b return b-a for i in range(n): x=int(l[i]) s+=dif(x,m) if(x>m): m+=dif(x,m) elif(x<m): m-=dif(x,m) print(s) ```
3
129
B
Students and Shoelaces
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one. To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student. Determine how many groups of students will be kicked out of the club.
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Print the single number — the number of groups of students that will be kicked out from the club.
[ "3 3\n1 2\n2 3\n3 1\n", "6 3\n1 2\n2 3\n3 4\n", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club. In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
1,000
[ { "input": "3 3\n1 2\n2 3\n3 1", "output": "0" }, { "input": "6 3\n1 2\n2 3\n3 4", "output": "2" }, { "input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4", "output": "1" }, { "input": "100 0", "output": "0" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "0" }, { "input": "5 4\n1 4\n4 3\n4 5\n5 2", "output": "2" }, { "input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11", "output": "4" }, { "input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7", "output": "2" }, { "input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6", "output": "0" }, { "input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3", "output": "0" }, { "input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5", "output": "0" }, { "input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6", "output": "1" }, { "input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4", "output": "0" }, { "input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4", "output": "0" }, { "input": "95 0", "output": "0" }, { "input": "100 0", "output": "0" }, { "input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39", "output": "2" }, { "input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51", "output": "3" }, { "input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41", "output": "3" }, { "input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65", "output": "5" }, { "input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7", "output": "4" }, { "input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35", "output": "4" }, { "input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65", "output": "8" }, { "input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36", "output": "4" }, { "input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70", "output": "4" }, { "input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66", "output": "3" }, { "input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27", "output": "8" }, { "input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51", "output": "4" }, { "input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75", "output": "5" }, { "input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31", "output": "3" }, { "input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35", "output": "8" }, { "input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37", "output": "3" }, { "input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41", "output": "4" }, { "input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53", "output": "5" } ]
1,603,371,760
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
204,800
n,m = list(map(int,input().strip().split(" "))) data = [[0 for i in range(n)] for i in range(n)] for i in range(m): a,b = list(map(int,input().strip().split(" "))) data[i-1][j-1] = 1 data[j-1][i-1] = 1 res = 0 flag = True while(flag): flag = False tmp = [] for i in range(n): if sum(data[i]) == 1: if not flag: res += 1 flag = True data[i][data[i].index(1)] = 0 print(res)
Title: Students and Shoelaces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one. To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student. Determine how many groups of students will be kicked out of the club. Input Specification: The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. Output Specification: Print the single number — the number of groups of students that will be kicked out from the club. Demo Input: ['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club. In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
```python n,m = list(map(int,input().strip().split(" "))) data = [[0 for i in range(n)] for i in range(n)] for i in range(m): a,b = list(map(int,input().strip().split(" "))) data[i-1][j-1] = 1 data[j-1][i-1] = 1 res = 0 flag = True while(flag): flag = False tmp = [] for i in range(n): if sum(data[i]) == 1: if not flag: res += 1 flag = True data[i][data[i].index(1)] = 0 print(res) ```
-1
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,639,298,902
2,147,483,647
PyPy 3-64
OK
TESTS
37
187
3,174,400
n, m = [int(i) for i in input().split()] languages = {} for i in range(m): f, s = input().split() languages[f] = (s, len(f), len(s)) p = input().split() for i in range(n): el = languages[p[i]] if el[2] < el[1]: p[i] = el[0] print(*p)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n, m = [int(i) for i in input().split()] languages = {} for i in range(m): f, s = input().split() languages[f] = (s, len(f), len(s)) p = input().split() for i in range(n): el = languages[p[i]] if el[2] < el[1]: p[i] = el[0] print(*p) ```
3
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, { "input": "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ", "output": "contest" }, { "input": "10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\nPVO->DMN\nDMN->PVO", "output": "home" }, { "input": "11\nIAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU", "output": "contest" }, { "input": "10\nHPN\nDFI->HPN\nHPN->KAB\nHPN->DFI\nVSO->HPN\nHPN->KZX\nHPN->VSO\nKZX->HPN\nLDW->HPN\nKAB->HPN\nHPN->LDW", "output": "home" }, { "input": "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE->FGH\nFGH->KQK\nFGH->QRE\nKQK->FGH\nFGH->UBK\nBRZ->FGH\nFGH->ALX\nALX->FGH\nFGH->KQK", "output": "contest" }, { "input": "50\nPFH\nJFV->PFH\nBVP->PFH\nPFH->BVP\nPFH->JFV\nPFH->ETQ\nPFH->LQJ\nZTO->PFH\nPFH->BVP\nPFH->RXO\nPFH->ZTO\nHWL->PFH\nPFH->HIV\nPFH->AFP\nPFH->HWL\nOBB->PFH\nHIV->PFH\nPFH->LSR\nAFP->PFH\nLQJ->PFH\nHWL->PFH\nETQ->PFH\nPFH->HWL\nLSR->PFH\nWBR->PFH\nBNZ->PFH\nHQR->PFH\nZTO->PFH\nPFH->WBR\nPFH->BYJ\nRXO->PFH\nFHZ->PFH\nFHZ->PFH\nPFN->PFH\nPFH->GMB\nPFH->JFV\nJFV->PFH\nGNZ->PFH\nPFH->BNZ\nPFH->GNZ\nPFH->HQR\nBYJ->PFH\nGMB->PFH\nPFH->FHZ\nPFH->FHZ\nPFH->ZTO\nPFH->UGD\nBVP->PFH\nUGD->PFH\nPFH->PFN\nPFH->OBB", "output": "home" }, { "input": "1\nAAK\nAAK->ABA", "output": "contest" }, { "input": "1\nXYZ\nXYZ->XYR", "output": "contest" } ]
1,487,062,646
3,146
Python 3
OK
TESTS
23
62
5,120,000
#Rohan Bojja #[email protected] from collections import defaultdict ####################################### c=1 cases=1 while(c<=cases): n=int(input()) home=input() iten=defaultdict(list) for i in range(0,n): cur=input().split("->") iten[cur[0]].append(cur[1]) ans="home" cur=home while(True): #print(cur,iten) if(cur in iten): if(cur!=home and home in iten[cur]): del iten[cur][iten[cur].index(home)] cur=home elif(cur!=home): ans="contest" break elif(cur==home and len(iten[cur])>0): cur2=iten[cur][0] iten[cur].pop(0) cur=cur2 elif(cur==home): break else: ans="contest" break #print(cur,iten) print(ans) c=c+1
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location! Input Specification: In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. Output Specification: If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". Demo Input: ['4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n', '3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n'] Demo Output: ['home\n', 'contest\n'] Note: In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
```python #Rohan Bojja #[email protected] from collections import defaultdict ####################################### c=1 cases=1 while(c<=cases): n=int(input()) home=input() iten=defaultdict(list) for i in range(0,n): cur=input().split("->") iten[cur[0]].append(cur[1]) ans="home" cur=home while(True): #print(cur,iten) if(cur in iten): if(cur!=home and home in iten[cur]): del iten[cur][iten[cur].index(home)] cur=home elif(cur!=home): ans="contest" break elif(cur==home and len(iten[cur])>0): cur2=iten[cur][0] iten[cur].pop(0) cur=cur2 elif(cur==home): break else: ans="contest" break #print(cur,iten) print(ans) c=c+1 ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,640,710,041
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
46
0
string = input() arr = [] arr.append(string.find('h')) arr.append(string.find('e', arr[0]+1)) arr.append(string.find('l', arr[1]+1)) arr.append(string.find('l', arr[2]+1)) arr.append(string.find('o', arr[3]+1)) # print(arr) if arr == sorted(arr): print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python string = input() arr = [] arr.append(string.find('h')) arr.append(string.find('e', arr[0]+1)) arr.append(string.find('l', arr[1]+1)) arr.append(string.find('l', arr[2]+1)) arr.append(string.find('o', arr[3]+1)) # print(arr) if arr == sorted(arr): print("YES") else: print("NO") ```
0
0
none
none
none
0
[ "none" ]
null
null
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*.
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
[ "4\n1 9\n3 1\n6 1\n7 4\n", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n" ]
[ "1\n", "3\n" ]
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
0
[ { "input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3" }, { "input": "1\n0 1", "output": "0" }, { "input": "1\n0 1000000", "output": "0" }, { "input": "1\n1000000 1000000", "output": "0" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7", "output": "4" }, { "input": "5\n1 1\n3 1\n5 1\n7 10\n8 10", "output": "2" }, { "input": "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1", "output": "4" } ]
1,521,774,664
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
7,475,200
import copy n, w, h = [int(x) for x in input().split()] class Envelope: def __init__(self, width, height, index): self.width = width self.height = height self.index = index def __str__(self): return "(" + str(self.width) + ", " + str(self.height) + ")" envelopes = set() for i in range(n): width, height = [int(x) for x in input().split()] envelopes.add(Envelope(width, height, i + 1)) cache = {} def get_envelope_chain(envelope, available_envelopes): # caching if envelope in cache: # print("Reading cache for", envelope.index) # print("For cached envelope", envelope.index, "chain =", [str(x.index) for x in cache[envelope]]) return cache[envelope] # if envelope != None: # if len(available_envelopes) == 0 or (envelope.width <= w or envelope.height <= h): # return [envelope] # print("Available envelopes (prev chosen=" + str(envelope) +"):", [str(x) for x in available_envelopes]) taken_out = [] for env in available_envelopes: if envelope != None and (env.width > envelope.width or env.height > envelope.height): taken_out.append(env) for env in taken_out: available_envelopes.remove(env) max_chain_size = -1 chosen_chain = [] for env in available_envelopes: # print("Checking env", str(env), envelope) if envelope == None or (env.width < envelope.width and env.height < envelope.height): if env.width > w and env.height > h: available_envelopes.remove(env) # new_available_envelopes = available_envelopes.copy() # new_available_envelopes.remove(env) chain = get_envelope_chain(env, available_envelopes) # print("For env", env.index, "found chain", [str(x) for x in chain]) available_envelopes.add(env) if len(chain) > max_chain_size: max_chain_size = len(chain) chosen_chain = chain for env in taken_out: available_envelopes.add(env) # test if envelope != None: chosen_chain = list(chosen_chain) chosen_chain.append(envelope) # print("chosen_chain:", [str(x) for x in chosen_chain]) # if envelope and envelope.index == 5: # print("hey") # print("Caching chosen_chain:", [x.index for x in chosen_chain]) # if envelope and envelope.index == 5: # print("CHOSEN_CHAIN 5", [x.index for x in chosen_chain]) cache[envelope] = chosen_chain return chosen_chain found_chain = get_envelope_chain(None, envelopes) #print([str(x) for x in found_chain]) print(len(found_chain)) print(" ".join([str(env.index) for env in found_chain])) # f(envelope) = next_envelope = f(envelope_(e-1))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*. Output Specification: Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. Demo Input: ['4\n1 9\n3 1\n6 1\n7 4\n', '7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n'] Demo Output: ['1\n', '3\n'] Note: For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
```python import copy n, w, h = [int(x) for x in input().split()] class Envelope: def __init__(self, width, height, index): self.width = width self.height = height self.index = index def __str__(self): return "(" + str(self.width) + ", " + str(self.height) + ")" envelopes = set() for i in range(n): width, height = [int(x) for x in input().split()] envelopes.add(Envelope(width, height, i + 1)) cache = {} def get_envelope_chain(envelope, available_envelopes): # caching if envelope in cache: # print("Reading cache for", envelope.index) # print("For cached envelope", envelope.index, "chain =", [str(x.index) for x in cache[envelope]]) return cache[envelope] # if envelope != None: # if len(available_envelopes) == 0 or (envelope.width <= w or envelope.height <= h): # return [envelope] # print("Available envelopes (prev chosen=" + str(envelope) +"):", [str(x) for x in available_envelopes]) taken_out = [] for env in available_envelopes: if envelope != None and (env.width > envelope.width or env.height > envelope.height): taken_out.append(env) for env in taken_out: available_envelopes.remove(env) max_chain_size = -1 chosen_chain = [] for env in available_envelopes: # print("Checking env", str(env), envelope) if envelope == None or (env.width < envelope.width and env.height < envelope.height): if env.width > w and env.height > h: available_envelopes.remove(env) # new_available_envelopes = available_envelopes.copy() # new_available_envelopes.remove(env) chain = get_envelope_chain(env, available_envelopes) # print("For env", env.index, "found chain", [str(x) for x in chain]) available_envelopes.add(env) if len(chain) > max_chain_size: max_chain_size = len(chain) chosen_chain = chain for env in taken_out: available_envelopes.add(env) # test if envelope != None: chosen_chain = list(chosen_chain) chosen_chain.append(envelope) # print("chosen_chain:", [str(x) for x in chosen_chain]) # if envelope and envelope.index == 5: # print("hey") # print("Caching chosen_chain:", [x.index for x in chosen_chain]) # if envelope and envelope.index == 5: # print("CHOSEN_CHAIN 5", [x.index for x in chosen_chain]) cache[envelope] = chosen_chain return chosen_chain found_chain = get_envelope_chain(None, envelopes) #print([str(x) for x in found_chain]) print(len(found_chain)) print(" ".join([str(env.index) for env in found_chain])) # f(envelope) = next_envelope = f(envelope_(e-1)) ```
-1
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "output": "67" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU", "output": "99" }, { "input": "3\nRUR", "output": "2" }, { "input": "1\nR", "output": "1" }, { "input": "5\nRURUU", "output": "3" }, { "input": "1\nU", "output": "1" }, { "input": "2\nUR", "output": "1" }, { "input": "23\nUUUUUUUUUUUUUUUUUUUUUUU", "output": "23" } ]
1,692,021,539
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
n = input() str = input() str1 = str.replace('UR', 'D') str2 = str1.replace('RU', 'D') len1 = len(str2) str3 = str.replace('RU', 'D') str4 = str.replace('UR', 'D') len2 = len(str4) print(min(len1,len2))
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. Output Specification: Print the minimum possible length of the sequence of moves after all replacements are done. Demo Input: ['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n'] Demo Output: ['3\n', '13\n'] Note: In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
```python n = input() str = input() str1 = str.replace('UR', 'D') str2 = str1.replace('RU', 'D') len1 = len(str2) str3 = str.replace('RU', 'D') str4 = str.replace('UR', 'D') len2 = len(str4) print(min(len1,len2)) ```
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,545,377
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
num1, num2 = map(int, input().split()) def findGCD(num1, num2): if num2 == 0: return num1 return findGCD(num2, num1 % num2) print(findGCD(num1, num2))
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 num1, num2 = map(int, input().split()) def findGCD(num1, num2): if num2 == 0: return num1 return findGCD(num2, num1 % num2) print(findGCD(num1, num2)) ```
0
676
B
Pyramid of Glasses
PROGRAMMING
1,500
[ "implementation", "math", "math" ]
null
null
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is *n*. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of *n* glasses. Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid. Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in *t* seconds. Pictures below illustrate the pyramid consisting of three levels.
The only line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=10,<=0<=≤<=*t*<=≤<=10<=000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle.
Print the single integer — the number of completely full glasses after *t* seconds.
[ "3 5\n", "4 8\n" ]
[ "4\n", "6\n" ]
In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty.
1,000
[ { "input": "3 5", "output": "4" }, { "input": "4 8", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "10 10000", "output": "55" }, { "input": "1 10000", "output": "1" }, { "input": "10 1", "output": "1" }, { "input": "1 0", "output": "0" }, { "input": "10 0", "output": "0" }, { "input": "10 1022", "output": "53" }, { "input": "10 1023", "output": "55" }, { "input": "10 1024", "output": "55" }, { "input": "1 2", "output": "1" }, { "input": "1 200", "output": "1" }, { "input": "7 128", "output": "28" }, { "input": "8 198", "output": "34" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "3" }, { "input": "2 4", "output": "3" }, { "input": "2 100", "output": "3" }, { "input": "2 10000", "output": "3" }, { "input": "3 7", "output": "6" }, { "input": "3 6", "output": "4" }, { "input": "3 8", "output": "6" }, { "input": "3 12", "output": "6" }, { "input": "3 1", "output": "1" }, { "input": "4 15", "output": "10" }, { "input": "4 14", "output": "8" }, { "input": "4 10", "output": "8" }, { "input": "4 16", "output": "10" }, { "input": "4 999", "output": "10" }, { "input": "4 9", "output": "8" }, { "input": "5 31", "output": "15" }, { "input": "5 30", "output": "13" }, { "input": "5 28", "output": "13" }, { "input": "5 25", "output": "13" }, { "input": "5 15", "output": "13" }, { "input": "5 32", "output": "15" }, { "input": "5 9999", "output": "15" }, { "input": "5 4", "output": "3" }, { "input": "5 9", "output": "8" }, { "input": "5 14", "output": "11" }, { "input": "6 63", "output": "21" }, { "input": "6 62", "output": "19" }, { "input": "6 61", "output": "19" }, { "input": "6 52", "output": "19" }, { "input": "6 31", "output": "19" }, { "input": "6 32", "output": "19" }, { "input": "6 39", "output": "19" }, { "input": "6 15", "output": "13" }, { "input": "6 14", "output": "11" }, { "input": "6 10", "output": "8" }, { "input": "6 4", "output": "3" }, { "input": "6 7653", "output": "21" }, { "input": "7 127", "output": "28" }, { "input": "6 64", "output": "21" }, { "input": "7 126", "output": "26" }, { "input": "7 125", "output": "26" }, { "input": "7 120", "output": "26" }, { "input": "7 98", "output": "26" }, { "input": "7 110", "output": "26" }, { "input": "7 65", "output": "26" }, { "input": "7 63", "output": "26" }, { "input": "7 15", "output": "13" }, { "input": "7 3", "output": "3" }, { "input": "7 1", "output": "1" }, { "input": "7 83", "output": "26" }, { "input": "7 214", "output": "28" }, { "input": "8 2555", "output": "36" }, { "input": "8 257", "output": "36" }, { "input": "8 256", "output": "36" }, { "input": "8 255", "output": "36" }, { "input": "8 254", "output": "34" }, { "input": "8 253", "output": "34" }, { "input": "8 251", "output": "34" }, { "input": "8 240", "output": "34" }, { "input": "8 128", "output": "34" }, { "input": "8 127", "output": "34" }, { "input": "8 100", "output": "32" }, { "input": "8 1", "output": "1" }, { "input": "8 0", "output": "0" }, { "input": "8 10000", "output": "36" }, { "input": "8 94", "output": "32" }, { "input": "8 33", "output": "26" }, { "input": "9 10000", "output": "45" }, { "input": "9 513", "output": "45" }, { "input": "9 512", "output": "45" }, { "input": "9 511", "output": "45" }, { "input": "9 510", "output": "43" }, { "input": "9 255", "output": "43" }, { "input": "9 256", "output": "43" }, { "input": "9 254", "output": "41" }, { "input": "9 253", "output": "41" }, { "input": "9 200", "output": "41" }, { "input": "9 100", "output": "37" }, { "input": "9 150", "output": "41" }, { "input": "10 9999", "output": "55" }, { "input": "10 1025", "output": "55" }, { "input": "10 1021", "output": "53" }, { "input": "10 512", "output": "53" }, { "input": "10 689", "output": "53" }, { "input": "10 754", "output": "53" }, { "input": "10 985", "output": "53" }, { "input": "10 255", "output": "51" }, { "input": "10 256", "output": "51" }, { "input": "10 254", "output": "49" }, { "input": "10 153", "output": "47" }, { "input": "10 2", "output": "1" }, { "input": "10 3", "output": "3" }, { "input": "10 5", "output": "4" }, { "input": "10 63", "output": "41" }, { "input": "10 64", "output": "41" }, { "input": "10 126", "output": "45" }, { "input": "10 127", "output": "47" }, { "input": "10 128", "output": "47" }, { "input": "10 55", "output": "37" }, { "input": "10 9", "output": "8" }, { "input": "10 37", "output": "33" }, { "input": "10 68", "output": "41" }, { "input": "3 4", "output": "3" }, { "input": "7 23", "output": "20" }, { "input": "1 3", "output": "1" } ]
1,586,427,915
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
82
155
0
n, t = list(map(int, input().split())) cups = [[0 for i in range(j)] for j in range(1, n+1)] cups[0][0] = 1 for i in range(1, n): for j in range(len(cups[i])): if j == 0: cups[i][j] += 0.5*cups[i-1][j] elif j == i: cups[i][j] += 0.5*cups[i-1][j-1] else: cups[i][j] += 0.5*(cups[i-1][j] + cups[i-1][j-1]) tf = [[0 for i in range(j)] for j in range(1, n+1)] tf[0][0] = 1 for i in range(1, n): for j in range(len(cups[i])): if j == 0: tf[i][j] = tf[i-1][j] + int(1/cups[i][j]) elif j == i: tf[i][j] = tf[i-1][j-1] + int(1/cups[i][j]) else: if cups[i-1][j] > cups[i-1][j-1]: tf[i][j] = min(tf[i-1][j], tf[i-1][j-1]) + (2 + (cups[i-1][j-1]*abs(tf[i-1][j] - tf[i-1][j-1])))/(cups[i-1][j] + cups[i-1][j-1]) elif cups[i-1][j] < cups[i-1][j-1]: tf[i][j] = min(tf[i-1][j], tf[i-1][j-1]) + (2 + (cups[i-1][j]*abs(tf[i-1][j] - tf[i-1][j-1])))/(cups[i-1][j] + cups[i-1][j-1]) else: tf[i][j] = tf[i-1][j] + (2 + (cups[i-1][j]*abs(tf[i-1][j] - tf[i-1][j-1])))/(2*cups[i-1][j]) ans = 0 for i in range(n): for j in range(len(tf[i])): if tf[i][j] <= t: ans += 1 print(ans)
Title: Pyramid of Glasses Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is *n*. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of *n* glasses. Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid. Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in *t* seconds. Pictures below illustrate the pyramid consisting of three levels. Input Specification: The only line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=10,<=0<=≤<=*t*<=≤<=10<=000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle. Output Specification: Print the single integer — the number of completely full glasses after *t* seconds. Demo Input: ['3 5\n', '4 8\n'] Demo Output: ['4\n', '6\n'] Note: In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty.
```python n, t = list(map(int, input().split())) cups = [[0 for i in range(j)] for j in range(1, n+1)] cups[0][0] = 1 for i in range(1, n): for j in range(len(cups[i])): if j == 0: cups[i][j] += 0.5*cups[i-1][j] elif j == i: cups[i][j] += 0.5*cups[i-1][j-1] else: cups[i][j] += 0.5*(cups[i-1][j] + cups[i-1][j-1]) tf = [[0 for i in range(j)] for j in range(1, n+1)] tf[0][0] = 1 for i in range(1, n): for j in range(len(cups[i])): if j == 0: tf[i][j] = tf[i-1][j] + int(1/cups[i][j]) elif j == i: tf[i][j] = tf[i-1][j-1] + int(1/cups[i][j]) else: if cups[i-1][j] > cups[i-1][j-1]: tf[i][j] = min(tf[i-1][j], tf[i-1][j-1]) + (2 + (cups[i-1][j-1]*abs(tf[i-1][j] - tf[i-1][j-1])))/(cups[i-1][j] + cups[i-1][j-1]) elif cups[i-1][j] < cups[i-1][j-1]: tf[i][j] = min(tf[i-1][j], tf[i-1][j-1]) + (2 + (cups[i-1][j]*abs(tf[i-1][j] - tf[i-1][j-1])))/(cups[i-1][j] + cups[i-1][j-1]) else: tf[i][j] = tf[i-1][j] + (2 + (cups[i-1][j]*abs(tf[i-1][j] - tf[i-1][j-1])))/(2*cups[i-1][j]) ans = 0 for i in range(n): for j in range(len(tf[i])): if tf[i][j] <= t: ans += 1 print(ans) ```
0
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712", "output": "NO" }, { "input": "190492", "output": "YES" }, { "input": "5722367", "output": "NO" }, { "input": "816761542", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "NO" }, { "input": "9", "output": "YES" }, { "input": "10", "output": "NO" }, { "input": "12", "output": "YES" }, { "input": "13", "output": "YES" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "16", "output": "YES" }, { "input": "17", "output": "NO" }, { "input": "18", "output": "YES" }, { "input": "19", "output": "NO" }, { "input": "20", "output": "YES" }, { "input": "41", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "69", "output": "YES" }, { "input": "82", "output": "NO" }, { "input": "85", "output": "NO" }, { "input": "736", "output": "NO" }, { "input": "895", "output": "YES" }, { "input": "934", "output": "YES" }, { "input": "6213", "output": "YES" }, { "input": "7405", "output": "NO" }, { "input": "9919", "output": "NO" }, { "input": "40942", "output": "YES" }, { "input": "41992", "output": "NO" }, { "input": "68535", "output": "NO" }, { "input": "405718", "output": "NO" }, { "input": "1046146", "output": "YES" }, { "input": "3761248", "output": "YES" }, { "input": "6195181", "output": "YES" }, { "input": "35354345", "output": "NO" }, { "input": "81282830", "output": "NO" }, { "input": "187719774", "output": "NO" }, { "input": "296798673", "output": "NO" }, { "input": "938938476", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "999887464", "output": "YES" }, { "input": "999111944", "output": "NO" }, { "input": "999966520", "output": "YES" }, { "input": "999912080", "output": "NO" }, { "input": "999992017", "output": "YES" }, { "input": "999990474", "output": "NO" }, { "input": "999999190", "output": "YES" }, { "input": "999999125", "output": "NO" }, { "input": "999999940", "output": "YES" }, { "input": "999999995", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "83495494", "output": "NO" }, { "input": "968022000", "output": "YES" }, { "input": "399980000", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "999999998", "output": "NO" } ]
1,591,457,820
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
0
from math import sqrt n=int(input()) status="NO" for i in range(int(2*sqrt(n))): for j in range(2*int(sqrt(n))): if (i*(i+1)/2)+(j*(j+1)/2)==n: status="YES" print(status)
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! Input Specification: The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Demo Input: ['256\n', '512\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
```python from math import sqrt n=int(input()) status="NO" for i in range(int(2*sqrt(n))): for j in range(2*int(sqrt(n))): if (i*(i+1)/2)+(j*(j+1)/2)==n: status="YES" print(status) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "10000220" }, { "input": ".", "output": "0" }, { "input": "-.", "output": "1" }, { "input": "--", "output": "2" }, { "input": "..", "output": "00" }, { "input": "--.", "output": "20" }, { "input": ".--.", "output": "020" }, { "input": ".-.-..", "output": "0110" }, { "input": "----.-.", "output": "2201" }, { "input": "-..--.-.", "output": "10201" }, { "input": "..--..--.", "output": "0020020" }, { "input": "-.-.---.--..-..-.-.-..-..-.--.", "output": "112120010111010120" }, { "input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "output": "21112220010101011012011011221011" }, { "input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------", "output": "11020111110111222212021020002022111100201121222020012022110010222" }, { "input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..", "output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110" }, { "input": ".-..-.-.---.-----.--.---...-.--.-.-....-..", "output": "01011212212021001201100010" }, { "input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..", "output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210" }, { "input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.", "output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220" }, { "input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----", "output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122" }, { "input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..", "output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110" }, { "input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.", "output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020" }, { "input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..", "output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200" }, { "input": "-.---...----...--.--...-.--.----", "output": "121002200020200012022" }, { "input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.", "output": "202020212012111010201021100001021221200011222112012201012220" } ]
1,693,305,517
2,147,483,647
Python 3
OK
TESTS
30
92
0
n=input() s="" i=0 while i<len(n): if(n[i]=="."): s+="0" elif i!= (len(n)-1): if (n[i+1]=="."): s+="1" else: s+="2" i+=1 i=i+1 print(s)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python n=input() s="" i=0 while i<len(n): if(n[i]=="."): s+="0" elif i!= (len(n)-1): if (n[i+1]=="."): s+="1" else: s+="2" i+=1 i=i+1 print(s) ```
3.977
441
A
Valera and Antique Items
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
[ "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n" ]
[ "3\n1 2 3\n", "0\n\n" ]
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
500
[ { "input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3" }, { "input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0" }, { "input": "2 100001\n1 895737\n1 541571", "output": "0" }, { "input": "1 1000000\n1 1000000", "output": "0" }, { "input": "1 1000000\n1 561774", "output": "1\n1" }, { "input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "2\n1 2" }, { "input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000", "output": "0" }, { "input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236", "output": "3\n1 2 3" }, { "input": "1 50001\n1 50000", "output": "1\n1" } ]
1,587,280,478
2,147,483,647
PyPy 3
OK
TESTS
26
140
1,433,600
n , v = input().split() n , v = int(n), int(v) st = set() for i in range(n): m = i+1 lt = [int(x) for x in input().split()] #print(lt) for p in lt[1:]: if p<v: st.add(m) #print(st) print(len(st)) if len(st)!=0: print(*st)
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 = input().split() n , v = int(n), int(v) st = set() for i in range(n): m = i+1 lt = [int(x) for x in input().split()] #print(lt) for p in lt[1:]: if p<v: st.add(m) #print(st) print(len(st)) if len(st)!=0: print(*st) ```
3
513
B1
Permutations
PROGRAMMING
1,400
[ "brute force" ]
null
null
You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum: Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*).
The single line of input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*cnt**n*), where *cnt**n* is the number of permutations of length *n* with maximum possible value of *f*(*p*). The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. - In subproblem B1 (3 points), the constraint 1<=≤<=*n*<=≤<=8 will hold. - In subproblem B2 (4 points), the constraint 1<=≤<=*n*<=≤<=50 will hold.
Output *n* number forming the required permutation.
[ "2 2\n", "3 2\n" ]
[ "2 1 \n", "1 3 2 \n" ]
In the first example, both permutations of numbers {1, 2} yield maximum possible *f*(*p*) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.
3
[ { "input": "2 2", "output": "2 1 " }, { "input": "3 2", "output": "1 3 2 " }, { "input": "1 1", "output": "1 " }, { "input": "3 1", "output": "1 2 3 " }, { "input": "3 3", "output": "2 3 1 " }, { "input": "3 4", "output": "3 2 1 " }, { "input": "4 1", "output": "1 2 3 4 " }, { "input": "4 3", "output": "1 3 4 2 " }, { "input": "4 4", "output": "1 4 3 2 " }, { "input": "4 8", "output": "4 3 2 1 " }, { "input": "5 2", "output": "1 2 3 5 4 " }, { "input": "5 7", "output": "1 4 5 3 2 " }, { "input": "5 15", "output": "4 5 3 2 1 " }, { "input": "6 23", "output": "2 5 6 4 3 1 " }, { "input": "7 7", "output": "1 2 3 6 7 5 4 " }, { "input": "7 44", "output": "2 4 7 6 5 3 1 " }, { "input": "8 1", "output": "1 2 3 4 5 6 7 8 " }, { "input": "8 127", "output": "7 8 6 5 4 3 2 1 " }, { "input": "8 128", "output": "8 7 6 5 4 3 2 1 " } ]
1,423,329,843
1,443
Python 3
TIME_LIMIT_EXCEEDED
TESTS1
16
2,000
0
#!/usr/bin/python3 n, t = map(int, input().split()) A = [i + 1 for i in range(n)] mx_sum = 0 for B in __import__("itertools").permutations(A): s = 0 for i in range(n): for j in range(i, n): m = 10 for k in range(i, j + 1): m = min(m, B[k]) s += m mx_sum = max(mx_sum, s) cnt = 0 for B in __import__("itertools").permutations(A): s = 0 for i in range(n): for j in range(i, n): m = 10 for k in range(i, j + 1): m = min(m, B[k]) s += m if s == mx_sum: cnt += 1 if cnt == t: print(" ".join(map(str, B))) exit(0)
Title: Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum: Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*). Input Specification: The single line of input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*cnt**n*), where *cnt**n* is the number of permutations of length *n* with maximum possible value of *f*(*p*). The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. - In subproblem B1 (3 points), the constraint 1<=≤<=*n*<=≤<=8 will hold. - In subproblem B2 (4 points), the constraint 1<=≤<=*n*<=≤<=50 will hold. Output Specification: Output *n* number forming the required permutation. Demo Input: ['2 2\n', '3 2\n'] Demo Output: ['2 1 \n', '1 3 2 \n'] Note: In the first example, both permutations of numbers {1, 2} yield maximum possible *f*(*p*) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.
```python #!/usr/bin/python3 n, t = map(int, input().split()) A = [i + 1 for i in range(n)] mx_sum = 0 for B in __import__("itertools").permutations(A): s = 0 for i in range(n): for j in range(i, n): m = 10 for k in range(i, j + 1): m = min(m, B[k]) s += m mx_sum = max(mx_sum, s) cnt = 0 for B in __import__("itertools").permutations(A): s = 0 for i in range(n): for j in range(i, n): m = 10 for k in range(i, j + 1): m = min(m, B[k]) s += m if s == mx_sum: cnt += 1 if cnt == t: print(" ".join(map(str, B))) exit(0) ```
0
448
D
Multiplication Table
PROGRAMMING
1,800
[ "binary search", "brute force" ]
null
null
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the *k*-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success? Consider the given multiplication table. If you write out all *n*·*m* numbers from the table in the non-decreasing order, then the *k*-th number you write out is called the *k*-th largest number.
The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*).
Print the *k*-th largest number in a *n*<=×<=*m* multiplication table.
[ "2 2 2\n", "2 3 4\n", "1 10 5\n" ]
[ "2\n", "3\n", "5\n" ]
A 2 × 3 multiplication table looks like this:
2,000
[ { "input": "2 2 2", "output": "2" }, { "input": "2 3 4", "output": "3" }, { "input": "1 10 5", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "10 1 7", "output": "7" }, { "input": "10 10 33", "output": "14" }, { "input": "500000 500000 1", "output": "1" }, { "input": "500000 500000 250000000000", "output": "250000000000" }, { "input": "3 3 1", "output": "1" }, { "input": "3 3 2", "output": "2" }, { "input": "3 3 3", "output": "2" }, { "input": "3 3 5", "output": "3" }, { "input": "3 3 8", "output": "6" }, { "input": "3 3 9", "output": "9" }, { "input": "1 500000 74747", "output": "74747" }, { "input": "500000 1 47474", "output": "47474" }, { "input": "499975 499981 12345", "output": "1634" }, { "input": "499997 499989 248758432143", "output": "225563648440" }, { "input": "5 1 2", "output": "2" }, { "input": "2 2 4", "output": "4" }, { "input": "1 2 1", "output": "1" }, { "input": "2 44 36", "output": "24" }, { "input": "2 28 49", "output": "42" }, { "input": "3 48 30", "output": "17" }, { "input": "5 385 1296", "output": "711" }, { "input": "1 454 340", "output": "340" }, { "input": "1 450 399", "output": "399" }, { "input": "1 3304 218", "output": "218" }, { "input": "3 4175 661", "output": "361" }, { "input": "4 1796 2564", "output": "1232" }, { "input": "2 33975 17369", "output": "11580" }, { "input": "4 25555 45556", "output": "21868" }, { "input": "5 17136 9220", "output": "4039" }, { "input": "3 355632 94220", "output": "51393" }, { "input": "5 353491 107977", "output": "47290" }, { "input": "4 194790 114613", "output": "55015" }, { "input": "47 5 157", "output": "87" }, { "input": "26 5 79", "output": "42" }, { "input": "40 2 3", "output": "2" }, { "input": "12 28 127", "output": "49" }, { "input": "32 12 132", "output": "50" }, { "input": "48 40 937", "output": "364" }, { "input": "45 317 6079", "output": "2160" }, { "input": "18 459 7733", "output": "5684" }, { "input": "38 127 1330", "output": "404" }, { "input": "25 1155 9981", "output": "3318" }, { "input": "41 4600 39636", "output": "10865" }, { "input": "20 2222 11312", "output": "3502" }, { "input": "32 11568 36460", "output": "8988" }, { "input": "48 33111 5809", "output": "1308" }, { "input": "27 24692 71714", "output": "18432" }, { "input": "46 356143 2399416", "output": "598032" }, { "input": "25 127045 1458997", "output": "548779" }, { "input": "41 246624 2596292", "output": "751716" }, { "input": "264 3 775", "output": "741" }, { "input": "495 3 17", "output": "10" }, { "input": "252 5 672", "output": "328" }, { "input": "314 32 3903", "output": "1345" }, { "input": "472 15 932", "output": "283" }, { "input": "302 39 4623", "output": "1589" }, { "input": "318 440 57023", "output": "19203" }, { "input": "403 363 932", "output": "175" }, { "input": "306 433 25754", "output": "6500" }, { "input": "143 1735 246128", "output": "218316" }, { "input": "447 4446 802918", "output": "268036" }, { "input": "132 3890 439379", "output": "265096" }, { "input": "366 45769 5885721", "output": "1841004" }, { "input": "123 37349 4224986", "output": "2895390" }, { "input": "427 46704 7152399", "output": "2256408" }, { "input": "357 184324 28748161", "output": "9992350" }, { "input": "187 425625 25103321", "output": "7534560" }, { "input": "345 423483 40390152", "output": "11441760" }, { "input": "4775 3 7798", "output": "4254" }, { "input": "1035 2 2055", "output": "2040" }, { "input": "3119 3 7305", "output": "5024" }, { "input": "1140 18 11371", "output": "4830" }, { "input": "4313 40 86640", "output": "33496" }, { "input": "2396 24 55229", "output": "43102" }, { "input": "2115 384 385536", "output": "140250" }, { "input": "2376 308 665957", "output": "445248" }, { "input": "4460 377 1197310", "output": "581462" }, { "input": "2315 1673 225263", "output": "40950" }, { "input": "1487 3295 736705", "output": "169290" }, { "input": "3571 3828 7070865", "output": "2696688" }, { "input": "3082 23173 68350097", "output": "51543000" }, { "input": "1165 34678 7211566", "output": "1745254" }, { "input": "1426 26259 37212278", "output": "33359110" }, { "input": "2930 491026 923941798", "output": "409544625" }, { "input": "3191 454046 718852491", "output": "267275676" }, { "input": "1274 295345 301511265", "output": "165699050" }, { "input": "10657 3 9816", "output": "5355" }, { "input": "38939 3 6757", "output": "3686" }, { "input": "37107 4 28350", "output": "13608" }, { "input": "19618 16 313726", "output": "311296" }, { "input": "27824 40 906786", "output": "518185" }, { "input": "46068 31 424079", "output": "131352" }, { "input": "40716 482 14569037", "output": "7363656" }, { "input": "48922 150 653002", "output": "135716" }, { "input": "37203 219 2355222", "output": "681502" }, { "input": "23808 3322 48603931", "output": "20824476" }, { "input": "12090 2766 12261436", "output": "3894264" }, { "input": "20296 4388 29300901", "output": "8862304" }, { "input": "29699 38801 37684232", "output": "6032628" }, { "input": "17980 28231 221639883", "output": "76707084" }, { "input": "16148 39736 239320912", "output": "76569666" }, { "input": "35531 340928 9207622511", "output": "4761654318" }, { "input": "43737 111829 865416726", "output": "208223208" }, { "input": "21980 353130 2233068545", "output": "638445948" }, { "input": "339697 4 1259155", "output": "993876" }, { "input": "404625 2 132619", "output": "88413" }, { "input": "226111 2 359116", "output": "266010" }, { "input": "318377 38 7214261", "output": "3108710" }, { "input": "139863 21 1834174", "output": "833220" }, { "input": "204791 41 8382971", "output": "8020256" }, { "input": "149281 382 51428462", "output": "33762615" }, { "input": "370768 123 15161219", "output": "4677246" }, { "input": "313975 448 85041752", "output": "36070940" }, { "input": "136614 3211 364472869", "output": "209750632" }, { "input": "201542 4833 512478332", "output": "197440230" }, { "input": "423029 1365 126620483", "output": "32780826" }, { "input": "110941 47433 2098952903", "output": "693548595" }, { "input": "175869 39014 3201917805", "output": "1148848775" }, { "input": "397356 10518 874806404", "output": "222468766" }, { "input": "118728 168631 16269281609", "output": "9092195490" }, { "input": "183656 409931 42943608085", "output": "17438143800" }, { "input": "283422 407789 73398688052", "output": "32237937640" }, { "input": "500000 500000 888888", "output": "77856" } ]
1,696,659,809
2,147,483,647
PyPy 3-64
OK
TESTS
127
358
6,144,000
import sys, threading input = sys.stdin.readline from collections import defaultdict input = sys.stdin.readline # returns the first number where key becomes true for a given delegate type key def bs(low=1, high=1, key = lambda x: True): while low <= high: mid = (low + high)//2 if key(mid): high = mid-1 else: low = mid+1 return low def good(x, n, m): res = 0 x -= 1 for i in range(1, n + 1): res += min(m, x // i) return res def main(): n,m, k = map(int, input().split()) low, high = 1, n * m + 1 print(bs(low, high, lambda x: good(x, n, m) >= k)-1) main()
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the *k*-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success? Consider the given multiplication table. If you write out all *n*·*m* numbers from the table in the non-decreasing order, then the *k*-th number you write out is called the *k*-th largest number. Input Specification: The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*). Output Specification: Print the *k*-th largest number in a *n*<=×<=*m* multiplication table. Demo Input: ['2 2 2\n', '2 3 4\n', '1 10 5\n'] Demo Output: ['2\n', '3\n', '5\n'] Note: A 2 × 3 multiplication table looks like this:
```python import sys, threading input = sys.stdin.readline from collections import defaultdict input = sys.stdin.readline # returns the first number where key becomes true for a given delegate type key def bs(low=1, high=1, key = lambda x: True): while low <= high: mid = (low + high)//2 if key(mid): high = mid-1 else: low = mid+1 return low def good(x, n, m): res = 0 x -= 1 for i in range(1, n + 1): res += min(m, x // i) return res def main(): n,m, k = map(int, input().split()) low, high = 1, n * m + 1 print(bs(low, high, lambda x: good(x, n, m) >= k)-1) main() ```
3
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,692,171,701
2,147,483,647
Python 3
OK
TESTS
71
92
0
m = int(input()) n = 0 s = 0 while m: a,b= map(int, input().split()) s=s+b-a if s >n: n = s m=m-1 print(n)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python m = int(input()) n = 0 s = 0 while m: a,b= map(int, input().split()) s=s+b-a if s >n: n = s m=m-1 print(n) ```
3
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
1,542,440,493
2,147,483,647
Python 3
OK
TESTS
36
436
20,172,800
def main(): n = int(input()) a = sorted([int(c) for c in input().split()]) s = sum(a) mn = score = i = 0 while i < n: score += s + mn mn = a[i] i += 1 s -= mn print(score) if __name__ == '__main__': main()
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. Output Specification: Print a single integer — the largest possible score. Demo Input: ['3\n3 1 5\n', '1\n10\n'] Demo Output: ['26\n', '10\n'] Note: Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
```python def main(): n = int(input()) a = sorted([int(c) for c in input().split()]) s = sum(a) mn = score = i = 0 while i < n: score += s + mn mn = a[i] i += 1 s -= mn print(score) if __name__ == '__main__': main() ```
3
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": "8" }, { "input": "6", "output": "4" }, { "input": "999999999", "output": "2" }, { "input": "1378", "output": "4" }, { "input": "13781378", "output": "4" }, { "input": "51202278", "output": "4" }, { "input": "999999998", "output": "4" }, { "input": "999999997", "output": "8" }, { "input": "12193721", "output": "8" }, { "input": "0", "output": "1" }, { "input": "989898989", "output": "8" }, { "input": "7", "output": "2" }, { "input": "8", "output": "6" }, { "input": "9", "output": "8" }, { "input": "10", "output": "4" }, { "input": "11", "output": "2" }, { "input": "12", "output": "6" }, { "input": "13", "output": "8" }, { "input": "14", "output": "4" }, { "input": "15", "output": "2" }, { "input": "16", "output": "6" }, { "input": "999999996", "output": "6" }, { "input": "999999995", "output": "2" }, { "input": "999999994", "output": "4" } ]
1,692,516,089
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) print(str(1378**(n%4))[-1])
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. Input Specification: The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). Output Specification: Print single integer — the last digit of 1378*n*. Demo Input: ['1\n', '2\n'] Demo Output: ['8', '4'] Note: In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
```python n = int(input()) print(str(1378**(n%4))[-1]) ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,680,188,424
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n= int(input()) l=[] for i in range (n) : l.append(int(input())) l.sort() s=0 p=0 for i in range (0,n,2) : s+=l[i] for i in range (1,n,2) : p+=l[i] print(s) print(p)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n= int(input()) l=[] for i in range (n) : l.append(int(input())) l.sort() s=0 p=0 for i in range (0,n,2) : s+=l[i] for i in range (1,n,2) : p+=l[i] print(s) print(p) ```
-1
508
D
Tanya and Password
PROGRAMMING
2,500
[ "dfs and similar", "graphs" ]
null
null
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of *n*<=+<=2 characters. She has written all the possible *n* three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password out. Each three-letter substring was written the number of times it occurred in the password. Thus, Tanya ended up with *n* pieces of paper. Then Tanya realized that dad will be upset to learn about her game and decided to restore the password or at least any string corresponding to the final set of three-letter strings. You have to help her in this difficult task. We know that dad's password consisted of lowercase and uppercase letters of the Latin alphabet and digits. Uppercase and lowercase letters of the Latin alphabet are considered distinct.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105), the number of three-letter substrings Tanya got. Next *n* lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit.
If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO". If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option.
[ "5\naca\naba\naba\ncab\nbac\n", "4\nabc\nbCb\ncb1\nb13\n", "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa\n" ]
[ "YES\nabacaba\n", "NO\n", "YES\naaaaaaaaa\n" ]
none
2,000
[ { "input": "5\naca\naba\naba\ncab\nbac", "output": "YES\nabacaba" }, { "input": "4\nabc\nbCb\ncb1\nb13", "output": "NO" }, { "input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa", "output": "YES\naaaaaaaaa" }, { "input": "1\nabc", "output": "YES\nabc" }, { "input": "2\nbba\nabb", "output": "YES\nabba" }, { "input": "3\naaa\naaa\naab", "output": "YES\naaaab" }, { "input": "2\naba\nbab", "output": "YES\nbaba" }, { "input": "2\nabc\nbga", "output": "NO" }, { "input": "4\naba\nbab\ncdc\ndcd", "output": "NO" }, { "input": "4\nbaa\ncaa\naax\naay", "output": "NO" }, { "input": "2\naba\naba", "output": "NO" }, { "input": "5\n123\n234\n345\n456\n567", "output": "YES\n1234567" }, { "input": "3\n42y\n2ya\nya6", "output": "YES\n42ya6" }, { "input": "8\nzHW\ncwx\nxmo\nWcw\nox1\nwxm\nmox\nHWc", "output": "YES\nzHWcwxmox1" }, { "input": "98\nuOK\nI0I\n7Ql\nqT6\nYux\nnGb\nXuh\nNZ4\nzrV\ntlm\nRMm\nWyO\nOCX\nq2q\nTpY\nukr\nRuO\njr7\nRjv\nxBW\nBWy\n1nG\n7Tp\n4NQ\nrI0\nepN\nZfB\nUzz\n6PR\nzFC\nIKN\nlR1\nQiq\nD2U\nV1h\niZf\nr7T\nuOt\nyOC\nNTe\njaN\nlmN\n2Uz\nZ4N\nuxB\nvuk\nAu1\nVQG\nT6P\nNQi\nfBy\nnr7\npYu\n0IK\nCXu\nZja\nhZj\nKNn\nu1n\neoj\nQGR\nmvu\njv3\npNi\nv3i\nmNT\nMmv\nr7Q\nFCu\n2qT\nkrI\nCuO\nKbR\nOtl\nR1z\nBxA\nGbV\n1zr\nojr\nPRu\nhD2\n3iZ\nNnr\niq2\nbRM\nOKb\n1hD\nNiB\nzzF\nuhZ\nbV1\nrVQ\niBx\nQlR\nxAu\nTeo\nGRj\naNZ", "output": "YES\nepNiBxAu1nGbV1hD2UzzFCuOKbRMmvukrI0IKNnr7TpYuxBWyOCXuhZjaNZ4NQiq2qT6PRuOtlmNTeojr7QlR1zrVQGRjv3iZfBy" }, { "input": "100\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa", "output": "YES\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "98\n229\nB2p\npBp\np9T\np9B\nB9T\nB9p\nB2T\n22T\nTBB\np2B\n29B\n9B9\nBTT\n929\n9pB\nT92\nppB\nB92\nBpT\nB9p\n29B\nT9B\n9B2\nTB9\np99\nT2T\n9TT\n9B2\nTp9\n2pB\npTB\nBp9\n92p\nBTB\n9Tp\nTBB\nTTp\n9B9\nTp2\nTBT\n9BT\n9BT\npT9\npBp\npB2\np9B\npBB\nBpB\n9pB\nBTB\n992\n2T9\n2TT\nT9p\nBTp\nBTB\n9pT\nT29\nTT9\n2B2\n2BT\nTT2\nTTT\n922\nB2B\np22\n9pT\nB2p\npBp\nB9B\nBTp\npT2\n9B9\nBBp\n2p2\nBpT\nTB2\n92B\nBB2\nTp9\n2BT\nB9B\nBB9\n2BT\n292\nTp9\np9p\nTpp\n292\nB2T\n2Tp\n2p9\nB2B\n2TB\n929\npT9\nBB9", "output": "YES\nBB9B9BTB2BTp9pT2922TBTBB9pT9pBB2Tp9BTB92p9B9pB2p229B2BTTT2TT9B2T929B9Tp2B2pBpBpTBBp9TTp99292BTppBpT9" }, { "input": "99\naaJ\nJx9\naLL\nrCx\nllJ\naja\nxxr\nLal\nv9C\njrL\nLvL\nJLl\nxlJ\nLja\nLLC\njvL\n9CJ\nvrJ\nlJJ\nlCC\nlxC\njxl\nLaJ\nLxJ\nrjr\nxvv\n9jC\nLxL\nvvr\nCCa\nJJr\nxJL\nxCj\nvv9\nLJJ\nx9J\nxx9\nrCx\nJLa\nrLv\nJrC\nvLx\njCv\nr9J\n9Cj\nv9C\naJL\nJrC\nCJx\nJJv\nJxx\nLCr\nLlx\nrJL\nx9L\naJx\nJxv\nxvv\nLLr\nLrC\nCv9\nCja\nxjv\n9Jj\nCjL\njvL\nC9j\nJLx\njaa\nxLJ\nlxv\n9LL\nJlC\nCxx\nJLa\njaj\nWRX\njJl\nljv\n9Jx\nall\nLlj\njaL\naJl\nvlx\nCr9\nCaJ\nCxj\nrC9\nJlJ\nlJL\njLl\nlJr\nvLj\njvl\nvjx\nJjv\nxrj\nJvj", "output": "NO" }, { "input": "5\ndip\nBQd\nipB\npBQ\nQdi", "output": "YES\nQdipBQd" } ]
1,668,819,710
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
483
9,011,200
from collections import Counter, defaultdict c = Counter() silbid = defaultdict(list) len_words = int(input()) for _ in range(len_words): word = input() first_two, last_two = word[:2], word[-2:] c[first_two] += 1 c[last_two] -= 1 silbid[first_two] += [last_two] z, start = 0, None answer = [] for _, ends in c.items(): if ends == -1: z+=1 if z > 1: print('NO') exit() if ends == 1: start = _ if not start: start = _ def rec(item): while silbid[item]: #print(1, item) #print(2, silbid[item]) new = silbid[item].pop() #print(3, new) rec(new) answer.insert(0, item) #print(4, answer) #print(c, silbid) rec(start) #print(answer) for enum, item in enumerate(answer[1:], 1): answer[enum] = item[1] print('YES') print(''.join(answer))
Title: Tanya and Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of *n*<=+<=2 characters. She has written all the possible *n* three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password out. Each three-letter substring was written the number of times it occurred in the password. Thus, Tanya ended up with *n* pieces of paper. Then Tanya realized that dad will be upset to learn about her game and decided to restore the password or at least any string corresponding to the final set of three-letter strings. You have to help her in this difficult task. We know that dad's password consisted of lowercase and uppercase letters of the Latin alphabet and digits. Uppercase and lowercase letters of the Latin alphabet are considered distinct. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105), the number of three-letter substrings Tanya got. Next *n* lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit. Output Specification: If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO". If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option. Demo Input: ['5\naca\naba\naba\ncab\nbac\n', '4\nabc\nbCb\ncb1\nb13\n', '7\naaa\naaa\naaa\naaa\naaa\naaa\naaa\n'] Demo Output: ['YES\nabacaba\n', 'NO\n', 'YES\naaaaaaaaa\n'] Note: none
```python from collections import Counter, defaultdict c = Counter() silbid = defaultdict(list) len_words = int(input()) for _ in range(len_words): word = input() first_two, last_two = word[:2], word[-2:] c[first_two] += 1 c[last_two] -= 1 silbid[first_two] += [last_two] z, start = 0, None answer = [] for _, ends in c.items(): if ends == -1: z+=1 if z > 1: print('NO') exit() if ends == 1: start = _ if not start: start = _ def rec(item): while silbid[item]: #print(1, item) #print(2, silbid[item]) new = silbid[item].pop() #print(3, new) rec(new) answer.insert(0, item) #print(4, answer) #print(c, silbid) rec(start) #print(answer) for enum, item in enumerate(answer[1:], 1): answer[enum] = item[1] print('YES') print(''.join(answer)) ```
-1
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,697,054,088
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
input_ = input().split() k, r = int(input_[0]), int(input_[1]) n = 1 while True: if k % 5 == 0: break if ((k%10)*n)%10 == r: print(n) break n += 1
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python input_ = input().split() k, r = int(input_[0]), int(input_[1]) n = 1 while True: if k % 5 == 0: break if ((k%10)*n)%10 == r: print(n) break n += 1 ```
0