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
552
C
Vanya and Scales
PROGRAMMING
1,900
[ "brute force", "dp", "greedy", "math", "meet-in-the-middle", "number theory" ]
null
null
Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass *m* and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
The first line contains two integers *w*,<=*m* (2<=≤<=*w*<=≤<=109, 1<=≤<=*m*<=≤<=109) — the number defining the masses of the weights and the mass of the item.
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
[ "3 7\n", "100 99\n", "100 50\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
1,500
[ { "input": "3 7", "output": "YES" }, { "input": "100 99", "output": "YES" }, { "input": "100 50", "output": "NO" }, { "input": "1000000000 1", "output": "YES" }, { "input": "100 10002", "output": "NO" }, { "input": "4 7", "output": "NO" }, { "input": "4 11", "output": "YES" }, { "input": "5 781", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "5077 5988", "output": "NO" }, { "input": "2 9596", "output": "YES" }, { "input": "4 1069", "output": "YES" }, { "input": "4 7134", "output": "NO" }, { "input": "4 9083", "output": "NO" }, { "input": "4 7927", "output": "NO" }, { "input": "4 6772", "output": "NO" }, { "input": "5 782", "output": "NO" }, { "input": "4 1000000000", "output": "NO" }, { "input": "4 357913941", "output": "YES" }, { "input": "4 357918037", "output": "NO" }, { "input": "5 12207031", "output": "YES" }, { "input": "5 41503906", "output": "YES" }, { "input": "5 90332031", "output": "NO" }, { "input": "11 1786324", "output": "YES" }, { "input": "10 999", "output": "YES" }, { "input": "8 28087", "output": "YES" }, { "input": "8 28598", "output": "NO" }, { "input": "32 33586176", "output": "YES" }, { "input": "87 56631258", "output": "YES" }, { "input": "19 20", "output": "YES" }, { "input": "58 11316496", "output": "YES" }, { "input": "89 89", "output": "YES" }, { "input": "21 85756882", "output": "YES" }, { "input": "56 540897225", "output": "YES" }, { "input": "91 8189", "output": "YES" }, { "input": "27 14329927", "output": "YES" }, { "input": "58 198535", "output": "YES" }, { "input": "939 938", "output": "YES" }, { "input": "27463 754243832", "output": "YES" }, { "input": "21427 459137757", "output": "YES" }, { "input": "26045 26045", "output": "YES" }, { "input": "25336 25336", "output": "YES" }, { "input": "24627 24626", "output": "YES" }, { "input": "29245 855299270", "output": "YES" }, { "input": "28536 814274759", "output": "YES" }, { "input": "33154 33155", "output": "YES" }, { "input": "27118 27119", "output": "YES" }, { "input": "70 338171", "output": "YES" }, { "input": "24 346226", "output": "NO" }, { "input": "41 2966964", "output": "NO" }, { "input": "31 29792", "output": "YES" }, { "input": "48 2402", "output": "NO" }, { "input": "65 4159", "output": "YES" }, { "input": "20 67376840", "output": "NO" }, { "input": "72 5111", "output": "YES" }, { "input": "27 14349609", "output": "YES" }, { "input": "44 89146", "output": "NO" }, { "input": "22787 519292944", "output": "NO" }, { "input": "24525 601475624", "output": "YES" }, { "input": "3716 13816089", "output": "NO" }, { "input": "4020 4020", "output": "YES" }, { "input": "13766 13767", "output": "YES" }, { "input": "23512 23511", "output": "YES" }, { "input": "23816 567225671", "output": "YES" }, { "input": "33562 33564", "output": "NO" }, { "input": "33866 33866", "output": "YES" }, { "input": "13057 13059", "output": "NO" }, { "input": "441890232 441890232", "output": "YES" }, { "input": "401739553 401739553", "output": "YES" }, { "input": "285681920 285681919", "output": "YES" }, { "input": "464591587 464591588", "output": "YES" }, { "input": "703722884 703722884", "output": "YES" }, { "input": "982276216 982276216", "output": "YES" }, { "input": "867871061 867871062", "output": "YES" }, { "input": "48433217 48433216", "output": "YES" }, { "input": "8 324818663", "output": "NO" }, { "input": "7 898367507", "output": "NO" }, { "input": "6 471916351", "output": "NO" }, { "input": "5 45465196", "output": "NO" }, { "input": "9 768757144", "output": "NO" }, { "input": "8 342305988", "output": "NO" }, { "input": "6 114457122", "output": "NO" }, { "input": "6 688005966", "output": "NO" }, { "input": "4 556522107", "output": "NO" }, { "input": "3 130070951", "output": "YES" }, { "input": "6 558395604", "output": "NO" }, { "input": "5 131944448", "output": "NO" }, { "input": "2 1000000", "output": "YES" }, { "input": "2 22222222", "output": "YES" }, { "input": "3 100000000", "output": "YES" }, { "input": "3 100000001", "output": "YES" }, { "input": "3 100000002", "output": "YES" }, { "input": "3 100000003", "output": "YES" }, { "input": "3 100000004", "output": "YES" }, { "input": "2 1", "output": "YES" }, { "input": "2 1000000000", "output": "YES" }, { "input": "3 1000000000", "output": "YES" }, { "input": "99999 1000000000", "output": "NO" }, { "input": "10 1000000000", "output": "YES" }, { "input": "1000 1000000000", "output": "YES" }, { "input": "10 999999999", "output": "YES" }, { "input": "100 99999999", "output": "YES" }, { "input": "1000 999999999", "output": "YES" }, { "input": "1000 999999998", "output": "NO" }, { "input": "2 536870912", "output": "YES" }, { "input": "10 99", "output": "YES" }, { "input": "10 8", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "3 26", "output": "YES" }, { "input": "10 8888", "output": "NO" }, { "input": "3 8", "output": "YES" }, { "input": "3 984742145", "output": "YES" }, { "input": "4 43", "output": "YES" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "4194304 4194305", "output": "YES" }, { "input": "10 899", "output": "YES" }, { "input": "4 47", "output": "YES" }, { "input": "4 822083581", "output": "YES" }, { "input": "3 999987989", "output": "YES" }, { "input": "4 31", "output": "NO" }, { "input": "4 15", "output": "YES" }, { "input": "100000000 100000001", "output": "YES" } ]
1,622,976,279
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
218
0
import sys input=sys.stdin.readline w,m=map(int,input().split()) c=[1]*101 i=0 while m>0: r=m%w if r==1 and c[i]==1: c[i]=0 elif r==w-1 and c[i]==1 and c[i+1]==1: c[i]=0 c[i+1]=0 else: print("NO") exit() i+=1 m//=w print("YES")
Title: Vanya and Scales Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass *m* and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. Input Specification: The first line contains two integers *w*,<=*m* (2<=≤<=*w*<=≤<=109, 1<=≤<=*m*<=≤<=109) — the number defining the masses of the weights and the mass of the item. Output Specification: Print word 'YES' if the item can be weighted and 'NO' if it cannot. Demo Input: ['3 7\n', '100 99\n', '100 50\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
```python import sys input=sys.stdin.readline w,m=map(int,input().split()) c=[1]*101 i=0 while m>0: r=m%w if r==1 and c[i]==1: c[i]=0 elif r==w-1 and c[i]==1 and c[i+1]==1: c[i]=0 c[i+1]=0 else: print("NO") exit() i+=1 m//=w print("YES") ```
0
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" }, { "input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761", "output": "YES" }, { "input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974", "output": "YES" }, { "input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291", "output": "NO" }, { "input": "3\n1 1000000000 1000000000", "output": "YES" }, { "input": "4\n1 1000000000 1000000000 1000000000", "output": "YES" }, { "input": "3\n1 1000000000 1", "output": "NO" }, { "input": "5\n1 2 3 5 2", "output": "YES" }, { "input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431", "output": "NO" }, { "input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159", "output": "YES" }, { "input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023", "output": "YES" }, { "input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015", "output": "YES" }, { "input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14", "output": "YES" }, { "input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368", "output": "NO" }, { "input": "3\n1 1000000000 999999999", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "YES" }, { "input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000", "output": "NO" }, { "input": "5\n2 3 4 10 20", "output": "YES" }, { "input": "6\n18 23 40 80 160 161", "output": "YES" }, { "input": "4\n5 6 7 888", "output": "YES" }, { "input": "9\n1 1 2 2 4 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 900 4 500 1500 5", "output": "YES" }, { "input": "3\n2 2 3", "output": "YES" }, { "input": "7\n1 2 100 200 250 1000000 2000000", "output": "YES" }, { "input": "8\n2 3 5 5 5 6 6 13", "output": "YES" }, { "input": "3\n2 3 4", "output": "YES" }, { "input": "6\n1 1 1 4 5 100", "output": "YES" }, { "input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377", "output": "YES" }, { "input": "4\n2 3 4 8", "output": "YES" }, { "input": "3\n5 6 7", "output": "YES" }, { "input": "5\n1 4 5 6 1000000", "output": "YES" }, { "input": "4\n5 6 7 20", "output": "YES" }, { "input": "6\n1 1 1 1 1 65", "output": "YES" }, { "input": "4\n3 4 5 100", "output": "YES" }, { "input": "3\n2 4 5", "output": "YES" }, { "input": "7\n1 1 1 1 1 10 1000", "output": "YES" }, { "input": "4\n1 1 2 3", "output": "NO" }, { "input": "11\n1 2 5 6 7 8 9 17 18 19 100", "output": "YES" }, { "input": "4\n5 16 20 200", "output": "YES" }, { "input": "5\n17 6 3 3 1", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "6\n1 1 1 2 3 5", "output": "YES" }, { "input": "4\n2 4 6 6", "output": "YES" }, { "input": "9\n1 2 4 4 4 4 7 8 20", "output": "YES" }, { "input": "9\n1 1 2 5 5 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 600 4 1700 6000 5", "output": "YES" }, { "input": "5\n5761 20966 27841 28800 29399", "output": "YES" }, { "input": "9\n1 2 3 6 7 10 11 12 24", "output": "YES" }, { "input": "4\n1 2 1 1", "output": "YES" }, { "input": "5\n1 1 2 3 4", "output": "YES" } ]
1,651,058,864
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
3
1,232
268,390,400
from itertools import permutations n=int(input()) l=list(map(int,input().split())) B=list(permutations(l,3)) cc=0 for i in B: a=i[0] b=i[1] c=i[2] if a+b>c and b+c>a and a+c>b: print("YES") cc=1 break if cc==0: print("NO")
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area. Input Specification: The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. Output Specification: In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. Demo Input: ['5\n1 5 3 2 4\n', '3\n4 1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
```python from itertools import permutations n=int(input()) l=list(map(int,input().split())) B=list(permutations(l,3)) cc=0 for i in B: a=i[0] b=i[1] c=i[2] if a+b>c and b+c>a and a+c>b: print("YES") cc=1 break if cc==0: print("NO") ```
0
0
none
none
none
0
[ "none" ]
null
null
Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: - A BC - B AC - C AB - AAA empty string Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.
The first line contains a string *S* (1<=≤<=|*S*|<=≤<=105). The second line contains a string *T* (1<=≤<=|*T*|<=≤<=105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'. The third line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The following *Q* lines describe queries. The *i*-th of these lines contains four space separated integers *a**i*, *b**i*, *c**i*, *d**i*. These represent the *i*-th query: is it possible to create *T*[*c**i*..*d**i*] from *S*[*a**i*..*b**i*] by applying the above transitions finite amount of times? Here, *U*[*x*..*y*] is a substring of *U* that begins at index *x* (indexed from 1) and ends at index *y*. In particular, *U*[1..|*U*|] is the whole string *U*. It is guaranteed that 1<=≤<=*a*<=≤<=*b*<=≤<=|*S*| and 1<=≤<=*c*<=≤<=*d*<=≤<=|*T*|.
Print a string of *Q* characters, where the *i*-th character is '1' if the answer to the *i*-th query is positive, and '0' otherwise.
[ "AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3\n" ]
[ "10011\n" ]
In the first query we can achieve the result, for instance, by using transitions <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2c164f8b6e335aa51b97bbd019ca0d7326927314.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.
0
[]
1,520,702,555
6,455
Python 3
WRONG_ANSWER
PRETESTS
1
46
5,632,000
x = input() y = input() s = [] bc = 0 a = 0 for l in x: if l in 'BC': bc += 1 a = 0 else: a += 1 s.append((bc,a)) t = [] bc = 0 a = 0 for l in y: if l in 'BC': bc += 1 a = 0 else: a += 1 t.append((bc,a)) q = int(input()) for i in range(q): ls,rs,lt,rt = map(int, input().split()) lens = rs - ls + 1 lent = rt - lt + 1 sbc = s[rs-1][0] - s[ls-1][0] tbc = t[rt-1][0] - t[lt-1][0] sa = s[rs-1][1] ta = t[rt-1][1] if sa > lens: sa = lens if ta > lent: ta = lent if sa != ta: sbc += 2 a = ta - sa if a < 0 or a % 2 != 0: print('0', end = '') else: print('1', end = '')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: - A BC - B AC - C AB - AAA empty string Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source. Input Specification: The first line contains a string *S* (1<=≤<=|*S*|<=≤<=105). The second line contains a string *T* (1<=≤<=|*T*|<=≤<=105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'. The third line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The following *Q* lines describe queries. The *i*-th of these lines contains four space separated integers *a**i*, *b**i*, *c**i*, *d**i*. These represent the *i*-th query: is it possible to create *T*[*c**i*..*d**i*] from *S*[*a**i*..*b**i*] by applying the above transitions finite amount of times? Here, *U*[*x*..*y*] is a substring of *U* that begins at index *x* (indexed from 1) and ends at index *y*. In particular, *U*[1..|*U*|] is the whole string *U*. It is guaranteed that 1<=≤<=*a*<=≤<=*b*<=≤<=|*S*| and 1<=≤<=*c*<=≤<=*d*<=≤<=|*T*|. Output Specification: Print a string of *Q* characters, where the *i*-th character is '1' if the answer to the *i*-th query is positive, and '0' otherwise. Demo Input: ['AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3\n'] Demo Output: ['10011\n'] Note: In the first query we can achieve the result, for instance, by using transitions <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2c164f8b6e335aa51b97bbd019ca0d7326927314.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.
```python x = input() y = input() s = [] bc = 0 a = 0 for l in x: if l in 'BC': bc += 1 a = 0 else: a += 1 s.append((bc,a)) t = [] bc = 0 a = 0 for l in y: if l in 'BC': bc += 1 a = 0 else: a += 1 t.append((bc,a)) q = int(input()) for i in range(q): ls,rs,lt,rt = map(int, input().split()) lens = rs - ls + 1 lent = rt - lt + 1 sbc = s[rs-1][0] - s[ls-1][0] tbc = t[rt-1][0] - t[lt-1][0] sa = s[rs-1][1] ta = t[rt-1][1] if sa > lens: sa = lens if ta > lent: ta = lent if sa != ta: sbc += 2 a = ta - sa if a < 0 or a % 2 != 0: print('0', end = '') else: print('1', end = '') ```
0
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307", "output": "22258199.5000000000" }, { "input": "2 1000000000\n0 1000000000", "output": "500000000.0000000000" }, { "input": "2 555\n200 300", "output": "255.0000000000" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n0", "output": "1.0000000000" }, { "input": "1 1000000000\n0", "output": "1000000000.0000000000" }, { "input": "1 1000000000\n1000000000", "output": "1000000000.0000000000" }, { "input": "1 999999999\n499999999", "output": "500000000.0000000000" }, { "input": "4 700\n0 250 475 700", "output": "125.0000000000" }, { "input": "4 700\n0 225 450 700", "output": "125.0000000000" }, { "input": "5 1000\n0 250 500 750 1000", "output": "125.0000000000" }, { "input": "5 2000\n1001 1001 1001 1001 1001", "output": "1001.0000000000" }, { "input": "1 999\n501", "output": "501.0000000000" }, { "input": "2 1000\n400 600", "output": "400.0000000000" }, { "input": "4 15\n1 3 9 11", "output": "4.0000000000" }, { "input": "1 5\n2", "output": "3.0000000000" } ]
1,689,907,416
2,147,483,647
Python 3
OK
TESTS
32
46
0
n,d=map(int,input().split()) li=[int(i) for i in input().split()] li.sort() maxx=0 for i in range(n-1): if li[i+1]-li[i]>maxx: maxx=li[i+1]-li[i] maxx=maxx/2 left=li[0] right=d-li[n-1] maxx=max(left,right,maxx) print(maxx)
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? Input Specification: The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. Output Specification: Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. Demo Input: ['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n'] Demo Output: ['2.5000000000\n', '2.0000000000\n'] Note: Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
```python n,d=map(int,input().split()) li=[int(i) for i in input().split()] li.sort() maxx=0 for i in range(n-1): if li[i+1]-li[i]>maxx: maxx=li[i+1]-li[i] maxx=maxx/2 left=li[0] right=d-li[n-1] maxx=max(left,right,maxx) print(maxx) ```
3
810
B
Summer sell-off
PROGRAMMING
1,300
[ "greedy", "sortings" ]
null
null
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem.
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day.
Print a single integer denoting the maximal number of products that shop can sell.
[ "4 2\n2 1\n3 5\n2 3\n1 5\n", "4 1\n0 2\n0 3\n3 5\n0 6\n" ]
[ "10", "5" ]
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
1,000
[ { "input": "4 2\n2 1\n3 5\n2 3\n1 5", "output": "10" }, { "input": "4 1\n0 2\n0 3\n3 5\n0 6", "output": "5" }, { "input": "1 1\n5 8", "output": "8" }, { "input": "2 1\n8 12\n6 11", "output": "19" }, { "input": "2 1\n6 7\n5 7", "output": "13" }, { "input": "2 1\n5 7\n6 7", "output": "13" }, { "input": "2 1\n7 8\n3 6", "output": "13" }, { "input": "2 1\n9 10\n5 8", "output": "17" }, { "input": "2 1\n3 6\n7 8", "output": "13" }, { "input": "1 0\n10 20", "output": "10" }, { "input": "2 1\n99 100\n3 6", "output": "105" }, { "input": "4 2\n2 10\n3 10\n9 9\n5 10", "output": "27" }, { "input": "2 1\n3 4\n2 8", "output": "7" }, { "input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2", "output": "1889" }, { "input": "2 1\n10 5\n2 4", "output": "9" }, { "input": "2 1\n50 51\n30 40", "output": "90" }, { "input": "3 2\n5 10\n5 10\n7 9", "output": "27" }, { "input": "3 1\n1000 1000\n50 100\n2 2", "output": "1102" }, { "input": "2 1\n2 4\n12 12", "output": "16" }, { "input": "2 1\n4 4\n1 2", "output": "6" }, { "input": "2 1\n4000 4000\n1 2", "output": "4002" }, { "input": "2 1\n5 6\n2 4", "output": "9" }, { "input": "3 2\n10 10\n10 10\n1 2", "output": "22" }, { "input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4", "output": "25" }, { "input": "2 1\n30 30\n10 20", "output": "50" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "2 1\n10 2\n2 10", "output": "6" }, { "input": "2 1\n4 5\n3 9", "output": "10" }, { "input": "2 1\n100 100\n5 10", "output": "110" }, { "input": "2 1\n14 28\n15 28", "output": "43" }, { "input": "2 1\n100 1\n20 40", "output": "41" }, { "input": "2 1\n5 10\n6 10", "output": "16" }, { "input": "2 1\n29 30\n10 20", "output": "49" }, { "input": "1 0\n12 12", "output": "12" }, { "input": "2 1\n7 8\n4 7", "output": "14" }, { "input": "2 1\n5 5\n2 4", "output": "9" }, { "input": "2 1\n1 2\n228 2", "output": "4" }, { "input": "2 1\n5 10\n100 20", "output": "30" }, { "input": "2 1\n1000 1001\n2 4", "output": "1004" }, { "input": "2 1\n3 9\n7 7", "output": "13" }, { "input": "2 0\n1 1\n1 1", "output": "2" }, { "input": "4 1\n10 10\n10 10\n10 10\n4 6", "output": "36" }, { "input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64", "output": "772" }, { "input": "2 1\n10 18\n17 19", "output": "35" }, { "input": "3 0\n1 1\n1 1\n1 1", "output": "3" }, { "input": "2 1\n4 7\n8 9", "output": "15" }, { "input": "4 2\n2 10\n3 10\n9 10\n5 10", "output": "27" }, { "input": "2 1\n5 7\n3 6", "output": "11" }, { "input": "2 1\n3 4\n12 12", "output": "16" }, { "input": "2 1\n10 11\n9 20", "output": "28" }, { "input": "2 1\n7 8\n2 4", "output": "11" }, { "input": "2 1\n5 10\n7 10", "output": "17" }, { "input": "4 2\n2 10\n3 10\n5 10\n9 10", "output": "27" }, { "input": "2 1\n99 100\n5 10", "output": "109" }, { "input": "4 2\n2 10\n3 10\n5 10\n9 9", "output": "27" }, { "input": "2 1\n3 7\n5 7", "output": "11" }, { "input": "2 1\n10 10\n3 6", "output": "16" }, { "input": "2 1\n100 1\n2 4", "output": "5" }, { "input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "5" }, { "input": "3 1\n3 7\n4 5\n2 3", "output": "12" }, { "input": "2 1\n3 9\n7 8", "output": "13" }, { "input": "2 1\n10 2\n3 4", "output": "6" }, { "input": "2 1\n40 40\n3 5", "output": "45" }, { "input": "2 1\n5 3\n1 2", "output": "5" }, { "input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4", "output": "45" }, { "input": "3 1\n1 5\n1 5\n4 4", "output": "7" }, { "input": "4 0\n1 1\n1 1\n1 1\n1 1", "output": "4" }, { "input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2", "output": "2005" }, { "input": "2 1\n15 30\n50 59", "output": "80" }, { "input": "2 1\n8 8\n3 5", "output": "13" }, { "input": "2 1\n4 5\n2 5", "output": "8" }, { "input": "3 2\n3 3\n1 2\n1 2", "output": "7" }, { "input": "3 1\n2 5\n2 5\n4 4", "output": "10" }, { "input": "2 1\n3 10\n50 51", "output": "56" }, { "input": "4 2\n2 4\n2 4\n9 10\n9 10", "output": "26" }, { "input": "2 1\n3 5\n8 8", "output": "13" }, { "input": "2 1\n100 150\n70 150", "output": "240" }, { "input": "2 1\n4 5\n3 6", "output": "10" }, { "input": "2 1\n20 10\n3 5", "output": "15" }, { "input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533", "output": "435467000" }, { "input": "2 1\n8 7\n3 6", "output": "13" }, { "input": "2 1\n7 8\n3 5", "output": "12" }, { "input": "2 1\n10 10\n1 3", "output": "12" }, { "input": "2 1\n9 10\n2 4", "output": "13" }, { "input": "3 1\n10 11\n12 13\n8 10", "output": "32" }, { "input": "2 1\n5 10\n7 7", "output": "17" }, { "input": "4 2\n90 91\n2 10\n2 10\n2 10", "output": "100" }, { "input": "2 1\n2 4\n4 4", "output": "8" }, { "input": "2 1\n2 3\n4 3", "output": "6" }, { "input": "2 1\n40 45\n50 52", "output": "95" }, { "input": "3 1\n1 4\n2 4\n3 4", "output": "8" }, { "input": "2 1\n1 2\n1000 1000", "output": "1002" }, { "input": "2 1\n80 100\n70 95", "output": "175" } ]
1,497,698,685
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
n,f=list(map(int,input().split())) k,l=[0 for i in range(n)],[0 for i in range(n)] for i in range(n): k[i],l[i]=list(map(int,input().split())) p=[max(k[i],l[i]) for i in range(n)] q=[max(2*k[i],l[i]) for i in range(n)] r=[q[i]-p[i] for i in range(n)] r.sort() print(sum(a)+sum(r[:f]))
Title: Summer sell-off Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input Specification: The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day. Output Specification: Print a single integer denoting the maximal number of products that shop can sell. Demo Input: ['4 2\n2 1\n3 5\n2 3\n1 5\n', '4 1\n0 2\n0 3\n3 5\n0 6\n'] Demo Output: ['10', '5'] Note: In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
```python n,f=list(map(int,input().split())) k,l=[0 for i in range(n)],[0 for i in range(n)] for i in range(n): k[i],l[i]=list(map(int,input().split())) p=[max(k[i],l[i]) for i in range(n)] q=[max(2*k[i],l[i]) for i in range(n)] r=[q[i]-p[i] for i in range(n)] r.sort() print(sum(a)+sum(r[:f])) ```
-1
754
B
Ilya and tic-tac-toe game
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
[ "xx..\n.oo.\nx...\noox.\n", "x.ox\nox..\nx.o.\noo.x\n", "x..x\n..oo\no...\nx.xo\n", "o.x.\no...\n.x..\nooxx\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row. In the second example it wasn't possible to win by making single turn. In the third example Ilya could have won by placing X in the last row between two existing Xs. In the fourth example it wasn't possible to win by making single turn.
1,000
[ { "input": "xx..\n.oo.\nx...\noox.", "output": "YES" }, { "input": "x.ox\nox..\nx.o.\noo.x", "output": "NO" }, { "input": "x..x\n..oo\no...\nx.xo", "output": "YES" }, { "input": "o.x.\no...\n.x..\nooxx", "output": "NO" }, { "input": ".xox\no.x.\nx.o.\n..o.", "output": "YES" }, { "input": "o.oo\n.x.o\nx.x.\n.x..", "output": "YES" }, { "input": "xxox\no.x.\nx.oo\nxo.o", "output": "YES" }, { "input": ".xox\n.x..\nxoo.\noox.", "output": "NO" }, { "input": "...x\n.x.o\n.o..\n.x.o", "output": "NO" }, { "input": "oo.x\nxo.o\no.xx\n.oxx", "output": "YES" }, { "input": ".x.o\n..o.\n..ox\nxox.", "output": "NO" }, { "input": "....\n.x..\nx...\n..oo", "output": "YES" }, { "input": "....\n....\n.x.o\n..xo", "output": "YES" }, { "input": "o..o\nx..x\n.o.x\nxo..", "output": "YES" }, { "input": "ox.o\nx..x\nx..o\noo.x", "output": "NO" }, { "input": ".xox\n.x.o\nooxo\n..x.", "output": "YES" }, { "input": "x..o\no..o\n..x.\nx.xo", "output": "YES" }, { "input": "xxoo\no.oo\n...x\nx..x", "output": "NO" }, { "input": "xoox\n.xx.\no..o\n..xo", "output": "YES" }, { "input": "..o.\nxxox\n....\n.oxo", "output": "YES" }, { "input": "xoox\nxxox\noo..\n.ox.", "output": "YES" }, { "input": "..ox\n.o..\nx..o\n.oxx", "output": "NO" }, { "input": ".oo.\n.x..\nx...\nox..", "output": "YES" }, { "input": "o.xx\nxo.o\n...o\n..x.", "output": "YES" }, { "input": "x...\n.ox.\n.oo.\n.xox", "output": "NO" }, { "input": "xoxx\n..x.\no.oo\nx.o.", "output": "YES" }, { "input": ".x.x\n.o.o\no.xx\nx.oo", "output": "YES" }, { "input": "...o\nxo.x\n.x..\nxoo.", "output": "YES" }, { "input": "o...\n...o\noxx.\n.xxo", "output": "YES" }, { "input": "xxox\no..o\nx..o\noxox", "output": "NO" }, { "input": "x.x.\nox.o\n.o.o\nxox.", "output": "YES" }, { "input": "xxo.\n...x\nooxx\n.o.o", "output": "YES" }, { "input": "xoxo\no..x\n.xo.\nox..", "output": "YES" }, { "input": ".o..\nox..\n.o.x\n.x..", "output": "NO" }, { "input": ".oxo\nx...\n.o..\n.xox", "output": "NO" }, { "input": ".oxx\n..o.\n.o.x\n.ox.", "output": "YES" }, { "input": ".xxo\n...o\n..ox\nox..", "output": "YES" }, { "input": "x...\nxo..\noxo.\n..ox", "output": "NO" }, { "input": "xoxo\nx.ox\n....\noxo.", "output": "YES" }, { "input": "x..o\nxo.x\no.xo\nxoox", "output": "NO" }, { "input": ".x..\no..x\n.oo.\nxox.", "output": "NO" }, { "input": "xxox\no.x.\nxo.o\nxo.o", "output": "NO" }, { "input": ".xo.\nx.oo\n...x\n.o.x", "output": "NO" }, { "input": "ox.o\n...x\n..oo\nxxox", "output": "NO" }, { "input": "oox.\nxoo.\no.x.\nx..x", "output": "NO" }, { "input": "oxox\nx.oo\nooxx\nxxo.", "output": "NO" }, { "input": "....\nxo.x\n..x.\noo..", "output": "NO" }, { "input": ".ox.\nx..o\nxo.x\noxo.", "output": "YES" }, { "input": ".xox\nxo..\n..oo\n.x..", "output": "NO" }, { "input": "xxo.\n.oo.\n..x.\n..xo", "output": "NO" }, { "input": "ox..\n..oo\n..x.\nxxo.", "output": "NO" }, { "input": "xxo.\nx..x\noo.o\noxox", "output": "YES" }, { "input": "xx..\noxxo\nxo.o\noox.", "output": "YES" }, { "input": "x..o\no..o\no..x\nxxox", "output": "NO" }, { "input": "oxo.\nxx.x\nooxx\n.o.o", "output": "YES" }, { "input": ".o.x\no..o\nx..x\n..xo", "output": "NO" }, { "input": "xo..\n....\nx...\n..o.", "output": "YES" }, { "input": ".x..\no...\n...x\n.o..", "output": "YES" }, { "input": "...x\n....\n.x.o\n..o.", "output": "YES" }, { "input": "o..x\n....\n...x\n..o.", "output": "YES" }, { "input": ".oo.\nx...\n....\n..x.", "output": "YES" }, { "input": ".o..\n.x..\n..o.\n.x..", "output": "YES" }, { "input": "..o.\n.x..\n....\no..x", "output": "YES" }, { "input": "..o.\n..x.\n....\n.ox.", "output": "YES" }, { "input": ".o..\no..x\n....\n.x..", "output": "YES" }, { "input": "....\n..ox\n....\n.o.x", "output": "YES" }, { "input": ".o..\n....\no...\nx.x.", "output": "YES" }, { "input": "....\n.o..\n....\nox.x", "output": "YES" }, { "input": "oxo.\nxxox\noo.o\nxoxx", "output": "YES" }, { "input": ".xx.\n...x\noo.o\no..x", "output": "YES" }, { "input": "x...\n.x..\n....\noo..", "output": "YES" }, { "input": "oxox\n..ox\nxoxo\nxoxo", "output": "YES" }, { "input": "....\n...x\n...x\noo..", "output": "YES" } ]
1,660,964,556
2,147,483,647
Python 3
OK
TESTS
95
46
0
def check_if_won(matrix): for row in matrix: row_str = ''.join(str(x) for x in row) if 'xxx' in row_str: return True for j in range(len(matrix[0])): col_str = '' col_str += matrix[0][j] col_str += matrix[1][j] col_str += matrix[2][j] col_str += matrix[3][j] if 'xxx' in col_str: return True # diagonais dig1 = '' dig1 += matrix[0][0] dig1 += matrix[1][1] dig1 += matrix[2][2] dig1 += matrix[3][3] if 'xxx' in dig1: return True dig2 = '' dig2 += matrix[1][0] dig2 += matrix[2][1] dig2 += matrix[3][2] if 'xxx' in dig2: return True dig3 = '' dig3 += matrix[0][1] dig3 += matrix[1][2] dig3 += matrix[2][3] if 'xxx' in dig3: return True dig_inv1 = '' dig_inv1 += matrix[0][3] dig_inv1 += matrix[1][2] dig_inv1 += matrix[2][1] dig_inv1 += matrix[3][0] if 'xxx' in dig_inv1: return True dig_inv2 = '' dig_inv2 += matrix[0][2] dig_inv2 += matrix[1][1] dig_inv2 += matrix[2][0] if 'xxx' in dig_inv2: return True dig_inv3 = '' dig_inv3 += matrix[1][3] dig_inv3 += matrix[2][2] dig_inv3 += matrix[3][1] if 'xxx' in dig_inv3: return True return False str1 = str(input()) str2 = str(input()) str3 = str(input()) str4 = str(input()) l1 = [c for c in str1] l2 = [c for c in str2] l3 = [c for c in str3] l4 = [c for c in str4] m = [] m.append(l1) m.append(l2) m.append(l3) m.append(l4) for i in range(len(m)): for j in range(len(l1)): if m[i][j] == '.': m[i][j] = 'x' won = check_if_won(m) if won: print('YES') exit() else: m[i][j] = '.' print('NO')
Title: Ilya and tic-tac-toe game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal). Input Specification: The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn. Output Specification: Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise. Demo Input: ['xx..\n.oo.\nx...\noox.\n', 'x.ox\nox..\nx.o.\noo.x\n', 'x..x\n..oo\no...\nx.xo\n', 'o.x.\no...\n.x..\nooxx\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n'] Note: In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row. In the second example it wasn't possible to win by making single turn. In the third example Ilya could have won by placing X in the last row between two existing Xs. In the fourth example it wasn't possible to win by making single turn.
```python def check_if_won(matrix): for row in matrix: row_str = ''.join(str(x) for x in row) if 'xxx' in row_str: return True for j in range(len(matrix[0])): col_str = '' col_str += matrix[0][j] col_str += matrix[1][j] col_str += matrix[2][j] col_str += matrix[3][j] if 'xxx' in col_str: return True # diagonais dig1 = '' dig1 += matrix[0][0] dig1 += matrix[1][1] dig1 += matrix[2][2] dig1 += matrix[3][3] if 'xxx' in dig1: return True dig2 = '' dig2 += matrix[1][0] dig2 += matrix[2][1] dig2 += matrix[3][2] if 'xxx' in dig2: return True dig3 = '' dig3 += matrix[0][1] dig3 += matrix[1][2] dig3 += matrix[2][3] if 'xxx' in dig3: return True dig_inv1 = '' dig_inv1 += matrix[0][3] dig_inv1 += matrix[1][2] dig_inv1 += matrix[2][1] dig_inv1 += matrix[3][0] if 'xxx' in dig_inv1: return True dig_inv2 = '' dig_inv2 += matrix[0][2] dig_inv2 += matrix[1][1] dig_inv2 += matrix[2][0] if 'xxx' in dig_inv2: return True dig_inv3 = '' dig_inv3 += matrix[1][3] dig_inv3 += matrix[2][2] dig_inv3 += matrix[3][1] if 'xxx' in dig_inv3: return True return False str1 = str(input()) str2 = str(input()) str3 = str(input()) str4 = str(input()) l1 = [c for c in str1] l2 = [c for c in str2] l3 = [c for c in str3] l4 = [c for c in str4] m = [] m.append(l1) m.append(l2) m.append(l3) m.append(l4) for i in range(len(m)): for j in range(len(l1)): if m[i][j] == '.': m[i][j] = 'x' won = check_if_won(m) if won: print('YES') exit() else: m[i][j] = '.' print('NO') ```
3
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "output": "NO" }, { "input": "3 3\n1 1\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n1 2\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n2 2\n1 2 3\n1 2 3", "output": "NO" }, { "input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49", "output": "YES" }, { "input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100", "output": "YES" }, { "input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99", "output": "YES" }, { "input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81", "output": "YES" }, { "input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10", "output": "NO" }, { "input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "1 1\n1 1\n-1000000000\n30", "output": "YES" }, { "input": "3 3\n1 3\n1 3 3\n3 3 3", "output": "YES" }, { "input": "3 3\n1 1\n3 3 3\n2 2 2", "output": "NO" }, { "input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7", "output": "NO" }, { "input": "3 4\n2 2\n5 6 7\n1 2 3 4", "output": "NO" }, { "input": "3 3\n3 3\n1 2 3\n4 5 6", "output": "YES" }, { "input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9", "output": "YES" } ]
1,600,249,092
2,147,483,647
Python 3
OK
TESTS
52
187
10,854,400
a = list(map(int,input().split())) b= list(map(int,input().split())) c=list(map(int,input().split())) d=list(map(int,input().split())) e = 0 f = b[1] for i in range(len(c)): if d[-f] > c[i]: e+=1 if e>=b[0]: print('Yes') else: print('NO')
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. Input Specification: The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. Output Specification: Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). Demo Input: ['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a = list(map(int,input().split())) b= list(map(int,input().split())) c=list(map(int,input().split())) d=list(map(int,input().split())) e = 0 f = b[1] for i in range(len(c)): if d[-f] > c[i]: e+=1 if e>=b[0]: print('Yes') else: print('NO') ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,682,269,055
2,147,483,647
Python 3
OK
TESTS
20
61
0
n = int(input()) # Read input n # Iterate over n words for i in range(n): word = input() # Read input word if len(word) > 10: # Check if word is too long abb = word[0] + str(len(word)-2) + word[-1] # Create abbreviation print(abb) # Print abbreviation else: print(word) # Print word as is
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()) # Read input n # Iterate over n words for i in range(n): word = input() # Read input word if len(word) > 10: # Check if word is too long abb = word[0] + str(len(word)-2) + word[-1] # Create abbreviation print(abb) # Print abbreviation else: print(word) # Print word as is ```
3.9695
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,596,258,911
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
6,963,200
n=int(raw_input()) x=0 final=[] while 4*x<=n: if (n-4*x)%7==0: y=(n-4*x)/7 final.append([x,y]) x+=1 if not final: print -1 else: k=min(final,key=lambda k:k[0]+k[1]) print ("4"*(k[0])+"7"*(k[1]))
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python n=int(raw_input()) x=0 final=[] while 4*x<=n: if (n-4*x)%7==0: y=(n-4*x)/7 final.append([x,y]) x+=1 if not final: print -1 else: k=min(final,key=lambda k:k[0]+k[1]) print ("4"*(k[0])+"7"*(k[1])) ```
-1
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,581,351,453
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
218
307,200
#!/usr/bin/env python # coding: utf-8 # In[1]: n=input() # In[4]: i=0 st=[] while i<len(n)-1: if n[i]=='-' and n[i+1]=='-': st.append('2') i+=2 elif n[i]=='-' and n[i+1]=='.': st.append('1') i+=2 else: st.append('0') i+=1 if n[-1]=='.': st.append('0') s=''.join(st) # In[5]: print(s) # In[ ]:
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 #!/usr/bin/env python # coding: utf-8 # In[1]: n=input() # In[4]: i=0 st=[] while i<len(n)-1: if n[i]=='-' and n[i+1]=='-': st.append('2') i+=2 elif n[i]=='-' and n[i+1]=='.': st.append('1') i+=2 else: st.append('0') i+=1 if n[-1]=='.': st.append('0') s=''.join(st) # In[5]: print(s) # In[ ]: ```
0
981
E
Addition on Segments
PROGRAMMING
2,200
[ "bitmasks", "data structures", "divide and conquer", "dp" ]
null
null
Grisha come to a contest and faced the following problem. You are given an array of size $n$, initially consisting of zeros. The elements of the array are enumerated from $1$ to $n$. You perform $q$ operations on the array. The $i$-th operation is described with three integers $l_i$, $r_i$ and $x_i$ ($1 \leq l_i \leq r_i \leq n$, $1 \leq x_i \leq n$) and means that you should add $x_i$ to each of the elements with indices $l_i, l_i + 1, \ldots, r_i$. After all operations you should find the maximum in the array. Grisha is clever, so he solved the problem quickly. However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?" Help Grisha, find all integers $y$ between $1$ and $n$ such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to $y$.
The first line contains two integers $n$ and $q$ ($1 \leq n, q \leq 10^{4}$) — the length of the array and the number of queries in the initial problem. The following $q$ lines contain queries, one per line. The $i$-th of these lines contains three integers $l_i$, $r_i$ and $x_i$ ($1 \leq l_i \leq r_i \leq n$, $1 \leq x_i \leq n$), denoting a query of adding $x_i$ to the segment from $l_i$-th to $r_i$-th elements of the array, inclusive.
In the first line print the only integer $k$, denoting the number of integers from $1$ to $n$, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations. In the next line print these $k$ integers from $1$ to $n$ — the possible values of the maximum. Print these integers in increasing order.
[ "4 3\n1 3 1\n2 4 2\n3 4 4\n", "7 2\n1 5 1\n3 7 2\n", "10 3\n1 1 2\n1 1 3\n1 1 6\n" ]
[ "4\n1 2 3 4 \n", "3\n1 2 3 \n", "6\n2 3 5 6 8 9 \n" ]
Consider the first example. If you consider the subset only of the first query, the maximum is equal to $1$. If you take only the second query, the maximum equals to $2$. If you take the first two queries, the maximum becomes $3$. If you take only the fourth query, the maximum becomes $4$. If you take the fourth query and something more, the maximum becomes greater that $n$, so you shouldn't print it. In the second example you can take the first query to obtain $1$. You can take only the second query to obtain $2$. You can take all queries to obtain $3$. In the third example you can obtain the following maximums: - You can achieve the maximim of $2$ by using queries: $(1)$. - You can achieve the maximim of $3$ by using queries: $(2)$. - You can achieve the maximim of $5$ by using queries: $(1, 2)$. - You can achieve the maximim of $6$ by using queries: $(3)$. - You can achieve the maximim of $8$ by using queries: $(1, 3)$. - You can achieve the maximim of $9$ by using queries: $(2, 3)$.
2,250
[ { "input": "4 3\n1 3 1\n2 4 2\n3 4 4", "output": "4\n1 2 3 4 " }, { "input": "7 2\n1 5 1\n3 7 2", "output": "3\n1 2 3 " }, { "input": "10 3\n1 1 2\n1 1 3\n1 1 6", "output": "6\n2 3 5 6 8 9 " }, { "input": "45 5\n37 38 16\n5 7 34\n1 42 31\n8 27 19\n15 28 39", "output": "5\n16 19 31 34 39 " }, { "input": "7010 10\n1467 2828 4742\n560 3268 3751\n1180 5370 6723\n907 3766 1380\n4610 5672 5430\n4867 5179 4868\n1890 3860 1037\n253 4853 5056\n480 5139 5329\n3764 4677 4777", "output": "22\n1037 1380 2417 3751 4742 4777 4788 4868 5056 5131 5329 5430 5779 5814 6093 6122 6157 6168 6366 6436 6709 6723 " }, { "input": "1 1\n1 1 1", "output": "1\n1 " }, { "input": "1010 10\n5 615 290\n146 940 131\n8 306 381\n387 478 417\n236 290 182\n258 288 117\n343 431 831\n766 775 199\n102 857 520\n216 913 687", "output": "63\n117 131 182 199 248 290 299 313 330 381 407 417 421 430 472 498 512 520 538 548 563 589 603 629 637 651 671 680 687 694 702 707 719 720 768 788 802 804 810 811 818 819 831 833 838 850 853 869 886 901 919 927 935 937 941 950 962 970 977 984 986 992 1000 " }, { "input": "4010 10\n909 1610 2428\n744 1380 2029\n658 781 1696\n2427 3132 2364\n2631 3975 3741\n1033 3693 1038\n117 3110 3815\n1962 2104 699\n454 2041 624\n2738 3231 3490", "output": "22\n624 699 1038 1323 1662 1696 1737 2029 2320 2361 2364 2428 2653 3052 3067 3402 3466 3490 3691 3725 3741 3815 " }, { "input": "10000 10\n2001 3111 6776\n2635 6081 3143\n5925 9279 4959\n6326 7610 2701\n5210 5461 8141\n2922 9252 7377\n6705 8478 597\n5556 7112 911\n652 9817 4874\n1832 8653 4209", "output": "49\n597 911 1508 2701 3143 3298 3612 4054 4209 4806 4874 4959 5120 5471 5556 5717 5785 5870 6382 6467 6776 6910 7352 7377 7507 7575 7660 7821 7974 8017 8102 8141 8172 8257 8263 8288 8418 8486 8571 8885 8928 9013 9083 9168 9680 9765 9833 9919 9994 " }, { "input": "6010 10\n38 2837 4404\n515 5033 887\n2419 3000 3320\n4422 5834 551\n220 1474 2206\n638 5884 224\n1549 1949 5525\n52 4891 420\n4503 4718 1495\n1300 4400 3233", "output": "69\n224 420 551 644 775 887 971 1111 1195 1307 1438 1495 1531 1662 1719 1858 1915 2046 2082 2139 2206 2270 2382 2430 2466 2606 2626 2690 2802 2850 2933 3026 3093 3157 3233 3317 3320 3353 3457 3513 3544 3577 3653 3737 3740 3877 3964 4120 4207 4344 4404 4431 4540 4627 4628 4764 4824 4851 5048 5291 5439 5515 5525 5663 5711 5749 5859 5935 5945 " }, { "input": "10 10\n1 9 7\n2 6 4\n7 8 1\n3 10 10\n3 5 7\n1 6 10\n6 6 3\n3 7 6\n2 2 9\n4 9 1", "output": "10\n1 2 3 4 5 6 7 8 9 10 " }, { "input": "9010 10\n2861 7587 7658\n1740 4549 8685\n7214 7667 6405\n1895 8261 2184\n2015 3497 5088\n1279 3095 1684\n32 7651 189\n7203 7950 2556\n2566 7868 1754\n2228 8147 5246", "output": "57\n189 1684 1754 1873 1943 2184 2373 2556 2745 3438 3627 3868 3938 4057 4127 4310 4499 4740 4929 5088 5246 5277 5435 5622 5811 6405 6494 6594 6683 6772 6842 6930 6961 7000 7031 7119 7189 7272 7430 7461 7619 7658 7802 7847 7991 8159 8348 8526 8589 8684 8685 8715 8778 8873 8874 8956 8961 " }, { "input": "5010 10\n1948 4159 3465\n2513 4745 4772\n1237 3781 1549\n497 1777 4549\n955 3065 3813\n184 4048 538\n439 2305 3771\n414 1654 484\n2543 4334 4528\n215 1500 1916", "output": "26\n484 538 1022 1549 1916 2033 2087 2400 2454 2571 2938 3465 3771 3813 3949 4003 4255 4297 4309 4351 4487 4528 4549 4772 4793 4835 " }, { "input": "3010 10\n1404 1948 2739\n227 505 2345\n1587 2035 765\n585 1673 2969\n89 379 2479\n989 1330 924\n1858 2968 29\n233 2335 1613\n1948 2351 2927\n2131 2292 360", "output": "20\n29 360 389 765 794 924 1613 1642 1973 2002 2345 2378 2407 2479 2537 2739 2768 2927 2956 2969 " }, { "input": "2010 10\n876 1434 1469\n1239 1389 600\n636 853 504\n242 1533 4\n1068 1256 823\n127 995 1468\n26 348 1967\n1016 1951 257\n13 924 45\n8 849 1463", "output": "39\n4 45 49 257 261 504 508 549 553 600 604 823 827 857 861 1080 1084 1423 1427 1463 1467 1468 1469 1472 1473 1508 1512 1513 1514 1517 1518 1680 1684 1726 1730 1967 1971 1972 1976 " }, { "input": "8010 10\n509 3546 5695\n383 511 2786\n4540 6912 6764\n1362 3766 4791\n571 2160 5836\n742 4553 1424\n836 7944 5373\n376 3547 4762\n4313 7876 3868\n539 1383 7182", "output": "17\n1424 2786 3868 4762 4791 5292 5373 5695 5836 6186 6215 6764 6797 7119 7182 7260 7548 " } ]
1,691,892,946
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
46
3,072,000
nmax = 10010 inf = 1e9 mod = 1e9 + 7 n, q = map(int, input().split()) ok = [0] * (nmax + 1) dp = [0] * (nmax + 1) v = [] def add(x): for i in range(n, x - 1, -1): dp[i] += dp[i - x] dp[i] %= mod ok[i] |= dp[i] > 0 def remove(x): for i in range(x, n + 1): dp[i] -= dp[i - x] dp[i] += mod dp[i] %= mod dp[0] = 1 for i in range(q): l, r, x = map(int, input().split()) v.append((l, x)) v.append((r + 1, -x)) v.sort() for i in v: if i[1] < 0: remove(-i[1]) else: add(i[1]) count_ok = sum(1 for i in ok[1:n + 1] if i == 1) print(count_ok + 1) result = [i for i in range(1, n + 1) if ok[i] == 1] print(*result + 1)# 1691892946.2425966
Title: Addition on Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grisha come to a contest and faced the following problem. You are given an array of size $n$, initially consisting of zeros. The elements of the array are enumerated from $1$ to $n$. You perform $q$ operations on the array. The $i$-th operation is described with three integers $l_i$, $r_i$ and $x_i$ ($1 \leq l_i \leq r_i \leq n$, $1 \leq x_i \leq n$) and means that you should add $x_i$ to each of the elements with indices $l_i, l_i + 1, \ldots, r_i$. After all operations you should find the maximum in the array. Grisha is clever, so he solved the problem quickly. However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?" Help Grisha, find all integers $y$ between $1$ and $n$ such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to $y$. Input Specification: The first line contains two integers $n$ and $q$ ($1 \leq n, q \leq 10^{4}$) — the length of the array and the number of queries in the initial problem. The following $q$ lines contain queries, one per line. The $i$-th of these lines contains three integers $l_i$, $r_i$ and $x_i$ ($1 \leq l_i \leq r_i \leq n$, $1 \leq x_i \leq n$), denoting a query of adding $x_i$ to the segment from $l_i$-th to $r_i$-th elements of the array, inclusive. Output Specification: In the first line print the only integer $k$, denoting the number of integers from $1$ to $n$, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations. In the next line print these $k$ integers from $1$ to $n$ — the possible values of the maximum. Print these integers in increasing order. Demo Input: ['4 3\n1 3 1\n2 4 2\n3 4 4\n', '7 2\n1 5 1\n3 7 2\n', '10 3\n1 1 2\n1 1 3\n1 1 6\n'] Demo Output: ['4\n1 2 3 4 \n', '3\n1 2 3 \n', '6\n2 3 5 6 8 9 \n'] Note: Consider the first example. If you consider the subset only of the first query, the maximum is equal to $1$. If you take only the second query, the maximum equals to $2$. If you take the first two queries, the maximum becomes $3$. If you take only the fourth query, the maximum becomes $4$. If you take the fourth query and something more, the maximum becomes greater that $n$, so you shouldn't print it. In the second example you can take the first query to obtain $1$. You can take only the second query to obtain $2$. You can take all queries to obtain $3$. In the third example you can obtain the following maximums: - You can achieve the maximim of $2$ by using queries: $(1)$. - You can achieve the maximim of $3$ by using queries: $(2)$. - You can achieve the maximim of $5$ by using queries: $(1, 2)$. - You can achieve the maximim of $6$ by using queries: $(3)$. - You can achieve the maximim of $8$ by using queries: $(1, 3)$. - You can achieve the maximim of $9$ by using queries: $(2, 3)$.
```python nmax = 10010 inf = 1e9 mod = 1e9 + 7 n, q = map(int, input().split()) ok = [0] * (nmax + 1) dp = [0] * (nmax + 1) v = [] def add(x): for i in range(n, x - 1, -1): dp[i] += dp[i - x] dp[i] %= mod ok[i] |= dp[i] > 0 def remove(x): for i in range(x, n + 1): dp[i] -= dp[i - x] dp[i] += mod dp[i] %= mod dp[0] = 1 for i in range(q): l, r, x = map(int, input().split()) v.append((l, x)) v.append((r + 1, -x)) v.sort() for i in v: if i[1] < 0: remove(-i[1]) else: add(i[1]) count_ok = sum(1 for i in ok[1:n + 1] if i == 1) print(count_ok + 1) result = [i for i in range(1, n + 1) if ok[i] == 1] print(*result + 1)# 1691892946.2425966 ```
-1
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "50 25\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 1 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": "25" }, { "input": "50 25\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 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": "26" }, { "input": "50 25\n2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\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", "output": "0" }, { "input": "50 1\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", "output": "0" }, { "input": "50 50\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", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
1,696,534,271
2,147,483,647
Python 3
OK
TESTS
50
92
0
nk = input() l = nk.split(' ') l = [int(s) for s in l] n = l[0] k = l[1] a = input() lst = a.split(' ') lst = [int(s) for s in lst] kmarks = lst[k-1] count = 0 for i in lst: if i > 0: if i >= kmarks: count += 1 else: break else: break print(count)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). Output Specification: Output the number of participants who advance to the next round. Demo Input: ['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n'] Demo Output: ['6\n', '0\n'] Note: In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
```python nk = input() l = nk.split(' ') l = [int(s) for s in l] n = l[0] k = l[1] a = input() lst = a.split(' ') lst = [int(s) for s in lst] kmarks = lst[k-1] count = 0 for i in lst: if i > 0: if i >= kmarks: count += 1 else: break else: break print(count) ```
3
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,484,378,734
2,147,483,647
Python 3
OK
TESTS
46
93
4,608,000
n, m, k = map(int, input().split()) i = 1 stop = 0 while stop != 1: if (k >= 2 * (i - 1) * m + 1) and (k <= 2 * i * m) : r = i d = 1 + (k - (2 * (i - 1) * m + 1)) // 2 if k % 2 == 0: s = "R" else: s = "L" stop = 1 i += 1 print(r,d,s)
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python n, m, k = map(int, input().split()) i = 1 stop = 0 while stop != 1: if (k >= 2 * (i - 1) * m + 1) and (k <= 2 * i * m) : r = i d = 1 + (k - (2 * (i - 1) * m + 1)) // 2 if k % 2 == 0: s = "R" else: s = "L" stop = 1 i += 1 print(r,d,s) ```
3
975
A
Aramic script
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script. The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$. It is guaranteed that all characters of the strings are small latin letters.
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
[ "5\na aa aaa ab abb\n", "3\namer arem mrea\n" ]
[ "2", "1" ]
In the first test, there are two objects mentioned. The roots that represent them are "a","ab". In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
500
[ { "input": "5\na aa aaa ab abb", "output": "2" }, { "input": "3\namer arem mrea", "output": "1" }, { "input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd", "output": "6" }, { "input": "2\nfhjlqs aceginpr", "output": "2" }, { "input": "2\nbcdfghimn efghijlmo", "output": "2" } ]
1,525,184,957
1,457
Python 3
OK
TESTS
30
343
10,240,000
n = int(input()) A = input().split() final = {} #print(A) for st in A: count = {} for j in st: if count.get(j,0) == 0: count[j] = 1 count = sorted(list(count)) #print(count) key = ''.join(count) if final.get(key,0) == 0: final[key] = 1 print(len(final))
Title: Aramic script Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script? Input Specification: The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script. The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$. It is guaranteed that all characters of the strings are small latin letters. Output Specification: Output one integer — the number of different objects mentioned in the given ancient Aramic script. Demo Input: ['5\na aa aaa ab abb\n', '3\namer arem mrea\n'] Demo Output: ['2', '1'] Note: In the first test, there are two objects mentioned. The roots that represent them are "a","ab". In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
```python n = int(input()) A = input().split() final = {} #print(A) for st in A: count = {} for j in st: if count.get(j,0) == 0: count[j] = 1 count = sorted(list(count)) #print(count) key = ''.join(count) if final.get(key,0) == 0: final[key] = 1 print(len(final)) ```
3
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n1305" }, { "input": "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\n102\n486\n333\n580\n431\n537\n355\n624\n23\n429\n276\n84\n704\n96\n536\n855\n653\n72\n718\n776\n658\n802\n777\n995\n285\n328\n405\n184\n555\n956\n410\n846\n853\n525\n983\n65\n549\n839\n929\n620\n725\n635\n303\n201\n878\n580\n139\n182\n69\n400\n788\n985\n792\n103\n248\n570\n839\n253\n417", "output": "404305\n251782\n0\n227457\n210832\n284857\n462120\n8535\n20605\n392670\n357082\n39164\n172890\n482574\n-1\n1765\n144024\n484545\n449679\n264039\n5206\n29380\n124228\n105469\n31116\n232909\n197350\n320760\n136555\n178254\n498454\n402504\n83644\n23580\n176457\n57631\n295560\n59704\n127756\n298654\n102263\n4999\n117319\n54589\n166444\n92074\n142407\n62168\n192954\n214\n91213\n37204\n3316\n246114\n4402\n141870\n363894\n211485\n2374\n256075\n299430\n214765\n319957\n300207\n493464\n39733\n52934\n81193\n16510\n15..." }, { "input": "1\n16", "output": "74" }, { "input": "60\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457", "output": "144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875..." }, { "input": "13\n1\n19\n31\n19\n19\n92\n74\n69\n32\n32\n91\n42\n73", "output": "-1\n128\n434\n128\n128\n4024\n2521\n2161\n402\n402\n3932\n777\n2447" }, { "input": "1\n16383", "output": "134176770" }, { "input": "16\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100", "output": "5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908" }, { "input": "1\n414234", "output": "85794061921" }, { "input": "1\n414232", "output": "85793233454" }, { "input": "3\n414231\n414231\n414231", "output": "85792819222\n85792819222\n85792819222" }, { "input": "1\n121", "output": "7127" } ]
1,657,366,204
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
1,000
0
n=int(input()) for i in range(n): k=int(input()) t=1 j=1 num=0 while j<=k: if j==t: num-=j t*=2 else: num+=j j+=1 print(num)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. Input Specification: The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the requested sum for each of *t* integers *n* given in the input. Demo Input: ['2\n4\n1000000000\n'] Demo Output: ['-4\n499999998352516354\n'] Note: The answer for the first sample is explained in the statement.
```python n=int(input()) for i in range(n): k=int(input()) t=1 j=1 num=0 while j<=k: if j==t: num-=j t*=2 else: num+=j j+=1 print(num) ```
0
290
E
HQ
PROGRAMMING
2,500
[ "*special", "constructive algorithms" ]
null
null
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
The only line of the input is a string between 1 and 106 characters long.
Output "Yes" or "No".
[ "HHHH\n", "HQHQH\n", "HHQHHQH\n", "HHQQHHQQHH\n" ]
[ "Yes\n", "No\n", "No\n", "Yes\n" ]
The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.
0
[ { "input": "HHHH", "output": "Yes" }, { "input": "HQHQH", "output": "No" }, { "input": "HHQHHQH", "output": "No" }, { "input": "HHQQHHQQHH", "output": "Yes" }, { "input": "Q", "output": "Yes" }, { "input": "HHHHHHHHHHQHHH", "output": "No" }, { "input": "HHQHQQQHHH", "output": "No" }, { "input": "QQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQHQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQ", "output": "Yes" }, { "input": "QHQHHQQQQQQQQQQQHQQHQHQQQQQQHQHQQQQQQQQQQQHQQQQQQQHQQHQQHQQQQQQQQQQQQQQQQQQQQHHQQQQQQQQQQHQQQQHHQHQQHQQQQQHQQQQQQQHQQQQQHQ", "output": "No" }, { "input": "QHQHQQHQQQQHQHHQQHQQHQHQQQQQQQHHQHHQQQHQQQQQQQQHQQQQQHQQHHQQHQQHQQHQQQHQQHQQHQQQQQQQQQHQQQQQQHQHQQQQQHQQQQHHQQQQQQQQQQQQQQQQHQQHQQQQH", "output": "No" }, { "input": "HQQQHQQHQHQQQQHQQQHQHQHQQQHQQQQHQQHHQQQQQHQQQQHQQQQQHQQQQQHQQQQQHHQQQQQHQQQQHHQQHHHQHQQQQQQQQHQHQHQHQQQQQQHHHQQHHQQQHQQQHQQQQQQHHQQQHQHQQHQHHHQQ", "output": "No" }, { "input": "HQQQQQQQHQQQQHQHQQQHHQHHHQQHQQQQHHQHHQHHHHHHQQQQQQQQHHQQQQQHHQQQQHHHQQQQQQQQHQQQHQHQQQQQQHHHQHHQHQHHQQQQQHQQHQHQQQHQHQHHHHQQHQHQQQQQHQQQHQQQHQQHQHQQHQQQQQQ", "output": "No" } ]
1,678,965,880
2,147,483,647
PyPy 3
OK
TESTS
28
1,090
56,320,000
a = input() b = [] h = '' c = 0 for i in a: if i == 'Q': c += 1 if c == 0: print('Yes') exit(0) r = -1 for i in range(1001): if i*i == c: r = i break if r == -1: print('No') exit(0) h = [a.split('Q')[0], a.split('Q')[-1]] c = [len(h[0]), len(h[1])] if c[0] % 2 != 0 or c[1] % 2 != 0: print('No') exit(0) c[0] //= 2 c[1] //= 2 resp = '' i = c[0] while True: if i >= len(a): break if r == 0 and a[i] == 'Q': break resp += a[i] if r == 0 and a[i] == 'H': c[1] -= 1 if c[1] == 0 and r == 0: break if a[i] == 'Q': r -= 1 if r == -1: print('No') exit(0) i += 1 def hq(a): resp = '' for i in a: if i == 'H': resp += 'H' else: resp += a return resp if a == hq(resp): print('Yes') else: print('No')
Title: HQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ... Input Specification: The only line of the input is a string between 1 and 106 characters long. Output Specification: Output "Yes" or "No". Demo Input: ['HHHH\n', 'HQHQH\n', 'HHQHHQH\n', 'HHQQHHQQHH\n'] Demo Output: ['Yes\n', 'No\n', 'No\n', 'Yes\n'] Note: The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.
```python a = input() b = [] h = '' c = 0 for i in a: if i == 'Q': c += 1 if c == 0: print('Yes') exit(0) r = -1 for i in range(1001): if i*i == c: r = i break if r == -1: print('No') exit(0) h = [a.split('Q')[0], a.split('Q')[-1]] c = [len(h[0]), len(h[1])] if c[0] % 2 != 0 or c[1] % 2 != 0: print('No') exit(0) c[0] //= 2 c[1] //= 2 resp = '' i = c[0] while True: if i >= len(a): break if r == 0 and a[i] == 'Q': break resp += a[i] if r == 0 and a[i] == 'H': c[1] -= 1 if c[1] == 0 and r == 0: break if a[i] == 'Q': r -= 1 if r == -1: print('No') exit(0) i += 1 def hq(a): resp = '' for i in a: if i == 'H': resp += 'H' else: resp += a return resp if a == hq(resp): print('Yes') else: print('No') ```
3
879
B
Table Tennis
PROGRAMMING
1,200
[ "data structures", "implementation" ]
null
null
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner. For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
Output a single integer — power of the winner.
[ "2 2\n1 2\n", "4 2\n3 1 2 4\n", "6 2\n6 5 3 1 2 4\n", "2 10000000000\n2 1\n" ]
[ "2 ", "3 ", "6 ", "2\n" ]
Games in the second sample: 3 plays with 1. 3 wins. 1 goes to the end of the line. 3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
1,000
[ { "input": "2 2\n1 2", "output": "2 " }, { "input": "4 2\n3 1 2 4", "output": "3 " }, { "input": "6 2\n6 5 3 1 2 4", "output": "6 " }, { "input": "2 10000000000\n2 1", "output": "2" }, { "input": "4 4\n1 3 4 2", "output": "4 " }, { "input": "2 2147483648\n2 1", "output": "2" }, { "input": "3 2\n1 3 2", "output": "3 " }, { "input": "3 3\n1 2 3", "output": "3 " }, { "input": "5 2\n2 1 3 4 5", "output": "5 " }, { "input": "10 2\n7 10 5 8 9 3 4 6 1 2", "output": "10 " }, { "input": "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98", "output": "70 " }, { "input": "4 10\n2 1 3 4", "output": "4" }, { "input": "10 2\n1 2 3 4 5 6 7 8 9 10", "output": "10 " }, { "input": "10 2\n10 9 8 7 6 5 4 3 2 1", "output": "10 " }, { "input": "4 1000000000000\n3 4 1 2", "output": "4" }, { "input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43", "output": "91 " }, { "input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34", "output": "100 " }, { "input": "2 1000000000000\n1 2", "output": "2" }, { "input": "5 2\n1 4 3 5 2", "output": "4 " }, { "input": "5 2\n1 3 2 4 5", "output": "3 " }, { "input": "4 1000000000000\n3 1 2 4", "output": "4" }, { "input": "4 2\n1 3 2 4", "output": "3 " }, { "input": "10 3\n8 1 9 2 3 10 4 5 6 7", "output": "9 " }, { "input": "5 2\n2 1 4 3 5", "output": "4 " }, { "input": "3 4294967297\n2 1 3", "output": "3" }, { "input": "4 4294967297\n3 2 1 4", "output": "4" }, { "input": "5 4294967298\n3 2 1 4 5", "output": "5" }, { "input": "10 4\n5 4 7 1 2 9 3 6 8 10", "output": "9 " }, { "input": "11 21474836489\n10 1 2 3 4 5 6 7 8 9 11", "output": "11" } ]
1,598,121,584
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
32
171
20,480,000
from collections import deque n, k = [int(p) for p in input().split()] q = deque([int(p) for p in input().split()]) curr = q[0] count = 0 while k > count: p1 = q.popleft() p2 = q.popleft() win = max(p1, p2) los = min(p1, p2) if win == curr: count += 1 else: curr = win count = 0 q.append(los) q.appendleft(win) if win == n: break print(win)
Title: Table Tennis Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner. For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner. Input Specification: The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct. Output Specification: Output a single integer — power of the winner. Demo Input: ['2 2\n1 2\n', '4 2\n3 1 2 4\n', '6 2\n6 5 3 1 2 4\n', '2 10000000000\n2 1\n'] Demo Output: ['2 ', '3 ', '6 ', '2\n'] Note: Games in the second sample: 3 plays with 1. 3 wins. 1 goes to the end of the line. 3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
```python from collections import deque n, k = [int(p) for p in input().split()] q = deque([int(p) for p in input().split()]) curr = q[0] count = 0 while k > count: p1 = q.popleft() p2 = q.popleft() win = max(p1, p2) los = min(p1, p2) if win == curr: count += 1 else: curr = win count = 0 q.append(los) q.appendleft(win) if win == n: break print(win) ```
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,692,065,826
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def can_divide_watermelon(weight): ifweight < = 2 or weight % 2 == 1: return "NO" else: return "YES" W = int(input()) result = can_divide_watermelon(w) print(result) #594
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 can_divide_watermelon(weight): ifweight < = 2 or weight % 2 == 1: return "NO" else: return "YES" W = int(input()) result = can_divide_watermelon(w) print(result) #594 ```
-1
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
1,697,815,642
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
#!/usr/bin/env python # coding: utf-8 # In[7]: n=int(input()) x=0 for i in range(n): i=str(input()) if i=="++X": x+=1 elif i=="--X": x-=1 print(x) # In[ ]:
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python #!/usr/bin/env python # coding: utf-8 # In[7]: n=int(input()) x=0 for i in range(n): i=str(input()) if i=="++X": x+=1 elif i=="--X": x-=1 print(x) # In[ ]: ```
0
620
E
New Year Tree
PROGRAMMING
2,100
[ "bitmasks", "data structures", "trees" ]
null
null
The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree. The New Year tree is an undirected tree with *n* vertices and root in the vertex 1. You should process the queries of the two types: 1. Change the colours of all vertices in the subtree of the vertex *v* to the colour *c*. 1. Find the number of different colours in the subtree of the vertex *v*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=4·105) — the number of vertices in the tree and the number of the queries. The second line contains *n* integers *c**i* (1<=≤<=*c**i*<=≤<=60) — the colour of the *i*-th vertex. Each of the next *n*<=-<=1 lines contains two integers *x**j*,<=*y**j* (1<=≤<=*x**j*,<=*y**j*<=≤<=*n*) — the vertices of the *j*-th edge. It is guaranteed that you are given correct undirected tree. The last *m* lines contains the description of the queries. Each description starts with the integer *t**k* (1<=≤<=*t**k*<=≤<=2) — the type of the *k*-th query. For the queries of the first type then follows two integers *v**k*,<=*c**k* (1<=≤<=*v**k*<=≤<=*n*,<=1<=≤<=*c**k*<=≤<=60) — the number of the vertex whose subtree will be recoloured with the colour *c**k*. For the queries of the second type then follows integer *v**k* (1<=≤<=*v**k*<=≤<=*n*) — the number of the vertex for which subtree you should find the number of different colours.
For each query of the second type print the integer *a* — the number of different colours in the subtree of the vertex given in the query. Each of the numbers should be printed on a separate line in order of query appearing in the input.
[ "7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3\n", "23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n" ]
[ "2\n3\n4\n5\n1\n2\n", "6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3\n" ]
none
0
[ { "input": "7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3", "output": "2\n3\n4\n5\n1\n2" }, { "input": "23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4", "output": "6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3" }, { "input": "1 1\n14\n2 1", "output": "1" }, { "input": "1 1\n36\n2 1", "output": "1" }, { "input": "1 1\n3\n2 1", "output": "1" }, { "input": "1 1\n43\n2 1", "output": "1" }, { "input": "1 1\n41\n2 1", "output": "1" }, { "input": "10 10\n59 59 59 59 59 59 59 59 59 59\n6 8\n6 10\n2 6\n2 5\n7 2\n10 1\n4 2\n7 3\n9 1\n1 8 59\n2 8\n1 3 59\n1 4 59\n1 8 59\n1 2 59\n1 5 59\n1 10 59\n2 2\n2 5", "output": "1\n1\n1" }, { "input": "10 10\n8 8 14 32 14 8 32 8 14 32\n4 5\n4 1\n4 8\n4 9\n7 4\n2 5\n3 5\n4 6\n10 4\n2 2\n1 9 8\n1 1 40\n1 7 32\n1 4 8\n2 8\n1 1 8\n2 2\n2 8\n2 4", "output": "1\n1\n1\n1\n1" }, { "input": "10 10\n39 50 50 7 39 7 46 7 39 7\n10 7\n7 3\n3 5\n3 4\n6 4\n1 4\n1 8\n8 2\n2 9\n2 8\n1 6 50\n2 4\n2 6\n1 7 39\n1 3 39\n2 9\n1 1 15\n2 7\n1 10 7", "output": "3\n4\n1\n1\n1" }, { "input": "10 10\n23 25 23 42 23 53 49 40 28 44\n1 7\n1 2\n2 4\n4 10\n8 10\n6 8\n3 8\n5 3\n9 5\n2 10\n1 6 52\n1 8 43\n2 3\n1 4 39\n1 8 44\n1 9 39\n2 1\n2 4\n1 6 36", "output": "5\n1\n5\n2" }, { "input": "10 10\n16 25 25 27 39 29 29 58 50 30\n8 2\n2 10\n4 2\n2 1\n6 2\n2 3\n9 2\n5 2\n2 7\n2 4\n1 3 31\n2 5\n1 7 27\n1 4 56\n1 4 52\n1 5 25\n1 6 32\n1 6 22\n1 7 42", "output": "1\n1" }, { "input": "10 10\n60 46 56 7 4 27 43 28 4 9\n1 5\n5 8\n10 8\n10 6\n7 6\n2 10\n4 2\n9 4\n9 3\n2 3\n1 9 57\n2 2\n1 6 50\n1 5 34\n1 8 45\n1 9 39\n2 2\n1 10 1\n2 4", "output": "1\n3\n2\n1" }, { "input": "10 10\n15 39 52 24 36 30 46 21 40 24\n5 9\n5 3\n5 10\n1 3\n9 4\n9 8\n9 7\n7 2\n3 6\n1 4 47\n1 7 25\n1 10 42\n2 10\n1 2 18\n1 1 60\n1 7 56\n2 7\n2 9\n2 10", "output": "1\n1\n2\n1" }, { "input": "10 10\n39 28 21 20 11 11 40 30 42 14\n7 1\n10 1\n6 1\n1 9\n5 1\n8 1\n1 3\n1 4\n2 10\n1 7 55\n2 3\n1 8 18\n1 10 48\n2 7\n1 6 26\n2 2\n1 1 4\n2 9\n1 5 31", "output": "1\n1\n1\n1" } ]
1,633,116,851
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
0
61
268,390,400
import sys input = sys.stdin.readline sys.setrecursionlimit(400005) def dfs(node,prev): s[node]=t[0] l[t[0]]=arr[node-1] for child in tree[node]: if child!=prev: t[0]=t[0]+1 dfs(child,node) e[node]=t[0] def update(node,start,end,l,r,val,p): if updt[node][0]!=0: segt[node]=updt[node][0] if start!=end: if updt[2*node][1]<updt[node][1]: updt[2*node][0]=updt[node][0] updt[2*node][1]=updt[node][1] if updt[2*node+1][1]<updt[node][1]: updt[2*node+1][0]=updt[node][0] updt[2*node+1][1]=updt[node][1] updt[node][0]=0 updt[node][1]=0 if start>r or end<l: return if start>=l and end<=r: segt[node]=val if start!=end: updt[2*node][0]=val updt[2*node][1]=p updt[2*node+1][0]=val updt[2*node+1][1]=p return mid=(start+end)//2 left=2*node right=left+1 update(left,start,mid,l,r,val,p) update(right,mid+1,end,l,r,val,p) segt[node]=segt[2*node] | segt[2*node+1] def query(node,start,end,l,r): if updt[node][0]!=0: segt[node]=updt[node][0] if start!=end: if updt[2*node][1]<updt[node][1]: updt[2*node][0]=updt[node][0] updt[2*node][1]=updt[node][1] if updt[2*node+1][1]<updt[node][1]: updt[2*node+1][0]=updt[node][0] updt[2*node+1][1]=updt[node][1] updt[node][0]=0 updt[node][1]=0 if start>r or end<l: return 0 if start>=l and end<=r: return segt[node] mid=(start+end)//2 left=2*node right=left+1 return query(left,start,mid,l,r) | query(right,mid+1,end,l,r) n,m=map(int,input().split()) arr=[int(x) for x in input().split()] tree=[[] for i in range(n+1)] for i in range(n-1): u,v=map(int,input().split()) tree[u].append(v) tree[v].append(u) # print(tree) s=[0]*(n+1) e=[0]*(n+1) l=[0]*(n+1) t=[1] dfs(1,0) # print(s) # print(e) # print(l) segt=[0]*(4*n) updt=[[0,0] for i in range(4*n)] p=1 for i in range(n): update(1,1,n,i+1,i+1,1<<l[i+1],p) p=p+1 for i in range(m): q=[int(x) for x in input().split()] if q[0]==1: update(1,1,n,s[q[1]],e[q[1]],1<<q[2],p) p=p+1 else: x=query(1,1,n,s[q[1]],e[q[1]]) print(bin(x).count("1"))
Title: New Year Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree. The New Year tree is an undirected tree with *n* vertices and root in the vertex 1. You should process the queries of the two types: 1. Change the colours of all vertices in the subtree of the vertex *v* to the colour *c*. 1. Find the number of different colours in the subtree of the vertex *v*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=4·105) — the number of vertices in the tree and the number of the queries. The second line contains *n* integers *c**i* (1<=≤<=*c**i*<=≤<=60) — the colour of the *i*-th vertex. Each of the next *n*<=-<=1 lines contains two integers *x**j*,<=*y**j* (1<=≤<=*x**j*,<=*y**j*<=≤<=*n*) — the vertices of the *j*-th edge. It is guaranteed that you are given correct undirected tree. The last *m* lines contains the description of the queries. Each description starts with the integer *t**k* (1<=≤<=*t**k*<=≤<=2) — the type of the *k*-th query. For the queries of the first type then follows two integers *v**k*,<=*c**k* (1<=≤<=*v**k*<=≤<=*n*,<=1<=≤<=*c**k*<=≤<=60) — the number of the vertex whose subtree will be recoloured with the colour *c**k*. For the queries of the second type then follows integer *v**k* (1<=≤<=*v**k*<=≤<=*n*) — the number of the vertex for which subtree you should find the number of different colours. Output Specification: For each query of the second type print the integer *a* — the number of different colours in the subtree of the vertex given in the query. Each of the numbers should be printed on a separate line in order of query appearing in the input. Demo Input: ['7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3\n', '23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n'] Demo Output: ['2\n3\n4\n5\n1\n2\n', '6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3\n'] Note: none
```python import sys input = sys.stdin.readline sys.setrecursionlimit(400005) def dfs(node,prev): s[node]=t[0] l[t[0]]=arr[node-1] for child in tree[node]: if child!=prev: t[0]=t[0]+1 dfs(child,node) e[node]=t[0] def update(node,start,end,l,r,val,p): if updt[node][0]!=0: segt[node]=updt[node][0] if start!=end: if updt[2*node][1]<updt[node][1]: updt[2*node][0]=updt[node][0] updt[2*node][1]=updt[node][1] if updt[2*node+1][1]<updt[node][1]: updt[2*node+1][0]=updt[node][0] updt[2*node+1][1]=updt[node][1] updt[node][0]=0 updt[node][1]=0 if start>r or end<l: return if start>=l and end<=r: segt[node]=val if start!=end: updt[2*node][0]=val updt[2*node][1]=p updt[2*node+1][0]=val updt[2*node+1][1]=p return mid=(start+end)//2 left=2*node right=left+1 update(left,start,mid,l,r,val,p) update(right,mid+1,end,l,r,val,p) segt[node]=segt[2*node] | segt[2*node+1] def query(node,start,end,l,r): if updt[node][0]!=0: segt[node]=updt[node][0] if start!=end: if updt[2*node][1]<updt[node][1]: updt[2*node][0]=updt[node][0] updt[2*node][1]=updt[node][1] if updt[2*node+1][1]<updt[node][1]: updt[2*node+1][0]=updt[node][0] updt[2*node+1][1]=updt[node][1] updt[node][0]=0 updt[node][1]=0 if start>r or end<l: return 0 if start>=l and end<=r: return segt[node] mid=(start+end)//2 left=2*node right=left+1 return query(left,start,mid,l,r) | query(right,mid+1,end,l,r) n,m=map(int,input().split()) arr=[int(x) for x in input().split()] tree=[[] for i in range(n+1)] for i in range(n-1): u,v=map(int,input().split()) tree[u].append(v) tree[v].append(u) # print(tree) s=[0]*(n+1) e=[0]*(n+1) l=[0]*(n+1) t=[1] dfs(1,0) # print(s) # print(e) # print(l) segt=[0]*(4*n) updt=[[0,0] for i in range(4*n)] p=1 for i in range(n): update(1,1,n,i+1,i+1,1<<l[i+1],p) p=p+1 for i in range(m): q=[int(x) for x in input().split()] if q[0]==1: update(1,1,n,s[q[1]],e[q[1]],1<<q[2],p) p=p+1 else: x=query(1,1,n,s[q[1]],e[q[1]]) print(bin(x).count("1")) ```
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,677,699,666
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import java.util.Arrays; import java.util.Scanner; public class Maze { private static int[] dirX = {1, 0, -1, 0}; private static int[] dirY = {0, 1, 0, -1, 0}; static int dots; static int lvlDfs; static int n, m, s; static String[][] maze; static boolean[][] visited; public static void main(String[] args){ Scanner sc = new Scanner(System.in); String[] lineOne = sc.nextLine().split(" "); n = Integer.parseInt(lineOne[0]); m = Integer.parseInt(lineOne[1]); s = Integer.parseInt(lineOne[2]); maze = new String[n][]; visited = new boolean[n][m]; // System.out.println("boolean val " + Arrays.toString(visited[0])); for(int i =0; i < n; i++){ maze[i] = sc.nextLine().split(""); // System.out.println(Arrays.toString(maze[i])); for (String cell : maze[i]){ dots += cell.equals(".") ? 1 : 0; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (maze[i][j].equals(".")) { dfs(i, j); i = n; break; } } } for (int i = 0; i < n && s > 0; ++i) { for (int j = 0; j < m && s > 0; ++j) { if (maze[i][j].equals(".") && !visited[i][j]) { --s; maze[i][j] = "X"; } } } for (int i = 0; i < n; ++i){ for (String cell : maze[i]){ System.out.print(cell); } System.out.println(); } sc.close(); } static void dfs(int i, int j){ lvlDfs++; visited[i][j] = true; for (int m = 0; m < 4 && lvlDfs < dots - s; ++m) { int x = i + dirX[m]; int y = j + dirY[m]; if (x >= 0 && x < n && y >= 0 && y < m && (maze[x][y]).equals(".") && !visited[x][y]){ dfs(x, y); } } } }
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 import java.util.Arrays; import java.util.Scanner; public class Maze { private static int[] dirX = {1, 0, -1, 0}; private static int[] dirY = {0, 1, 0, -1, 0}; static int dots; static int lvlDfs; static int n, m, s; static String[][] maze; static boolean[][] visited; public static void main(String[] args){ Scanner sc = new Scanner(System.in); String[] lineOne = sc.nextLine().split(" "); n = Integer.parseInt(lineOne[0]); m = Integer.parseInt(lineOne[1]); s = Integer.parseInt(lineOne[2]); maze = new String[n][]; visited = new boolean[n][m]; // System.out.println("boolean val " + Arrays.toString(visited[0])); for(int i =0; i < n; i++){ maze[i] = sc.nextLine().split(""); // System.out.println(Arrays.toString(maze[i])); for (String cell : maze[i]){ dots += cell.equals(".") ? 1 : 0; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (maze[i][j].equals(".")) { dfs(i, j); i = n; break; } } } for (int i = 0; i < n && s > 0; ++i) { for (int j = 0; j < m && s > 0; ++j) { if (maze[i][j].equals(".") && !visited[i][j]) { --s; maze[i][j] = "X"; } } } for (int i = 0; i < n; ++i){ for (String cell : maze[i]){ System.out.print(cell); } System.out.println(); } sc.close(); } static void dfs(int i, int j){ lvlDfs++; visited[i][j] = true; for (int m = 0; m < 4 && lvlDfs < dots - s; ++m) { int x = i + dirX[m]; int y = j + dirY[m]; if (x >= 0 && x < n && y >= 0 && y < m && (maze[x][y]).equals(".") && !visited[x][y]){ dfs(x, y); } } } } ```
-1
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,662,791,238
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
s=input() a=[] sol="helo" for i in s: if(i=="h" or i=="e" or i=="l" or i=="o"): if(i not in a): a.append(i) ss="".join(a) if(ss==sol): print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s=input() a=[] sol="helo" for i in s: if(i=="h" or i=="e" or i=="l" or i=="o"): if(i not in a): a.append(i) ss="".join(a) if(ss==sol): print("YES") else: print("NO") ```
0
237
C
Primes on Interval
PROGRAMMING
1,600
[ "binary search", "number theory", "two pointers" ]
null
null
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers *a*, *a*<=+<=1, ..., *b* (*a*<=≤<=*b*). You want to find the minimum integer *l* (1<=≤<=*l*<=≤<=*b*<=-<=*a*<=+<=1) such that for any integer *x* (*a*<=≤<=*x*<=≤<=*b*<=-<=*l*<=+<=1) among *l* integers *x*, *x*<=+<=1, ..., *x*<=+<=*l*<=-<=1 there are at least *k* prime numbers. Find and print the required minimum *l*. If no value *l* meets the described limitations, print -1.
A single line contains three space-separated integers *a*,<=*b*,<=*k* (1<=≤<=*a*,<=*b*,<=*k*<=≤<=106; *a*<=≤<=*b*).
In a single line print a single integer — the required minimum *l*. If there's no solution, print -1.
[ "2 4 2\n", "6 13 1\n", "1 4 3\n" ]
[ "3\n", "4\n", "-1\n" ]
none
1,500
[ { "input": "2 4 2", "output": "3" }, { "input": "6 13 1", "output": "4" }, { "input": "1 4 3", "output": "-1" }, { "input": "5 8 2", "output": "4" }, { "input": "8 10 3", "output": "-1" }, { "input": "1 5 2", "output": "3" }, { "input": "6 8 3", "output": "-1" }, { "input": "21 29 2", "output": "9" }, { "input": "17 27 3", "output": "11" }, { "input": "1 1000000 10000", "output": "137970" }, { "input": "690059 708971 10000", "output": "-1" }, { "input": "12357 534133 2", "output": "138" }, { "input": "838069 936843 3", "output": "142" }, { "input": "339554 696485 4", "output": "168" }, { "input": "225912 522197 5", "output": "190" }, { "input": "404430 864261 6", "output": "236" }, { "input": "689973 807140 7", "output": "236" }, { "input": "177146 548389 8", "output": "240" }, { "input": "579857 857749 9", "output": "300" }, { "input": "35648 527231 10", "output": "280" }, { "input": "2 1000000 10000", "output": "137970" }, { "input": "1 999999 9999", "output": "137958" }, { "input": "5 5 10", "output": "-1" }, { "input": "11 11 6", "output": "-1" }, { "input": "4 4 95", "output": "-1" }, { "input": "1 1000000 1000000", "output": "-1" }, { "input": "1 1000000 78498", "output": "999999" }, { "input": "1 1000000 78499", "output": "-1" }, { "input": "3459 94738 1", "output": "72" }, { "input": "1 1000000 1", "output": "114" }, { "input": "1 1000000 78498", "output": "999999" }, { "input": "1 1000000 78497", "output": "999998" }, { "input": "1 1000000 78490", "output": "999978" }, { "input": "1000 10000 13", "output": "168" }, { "input": "100000 1000000 7821", "output": "108426" }, { "input": "20 1000000 40000", "output": "539580" }, { "input": "1000 900000 50000", "output": "659334" }, { "input": "10000 1000000 60000", "output": "793662" }, { "input": "9999 99999 8000", "output": "86572" }, { "input": "50 150 20", "output": "100" }, { "input": "999953 999953 1", "output": "1" }, { "input": "999953 999953 2", "output": "-1" }, { "input": "999931 999953 2", "output": "23" }, { "input": "999906 999984 4", "output": "52" }, { "input": "999940 999983 3", "output": "26" }, { "input": "1 1 1", "output": "-1" }, { "input": "1 1 1000000", "output": "-1" }, { "input": "1 2 1", "output": "2" }, { "input": "1 3 1", "output": "2" }, { "input": "1 3 2", "output": "3" }, { "input": "1 4 2", "output": "3" }, { "input": "1 5 2", "output": "3" }, { "input": "1 5 3", "output": "5" }, { "input": "2 5 2", "output": "3" }, { "input": "3 5 1", "output": "2" } ]
1,685,452,305
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
342
48,332,800
from bisect import bisect_left, bisect_right from collections import Counter, deque from functools import lru_cache from math import factorial, comb, sqrt, gcd, lcm, log2 from copy import deepcopy import heapq from sys import stdin, stdout input = stdin.readline def find_prime(n): # 线性筛法 prime = [] # 存储结果 L = [True] * (n + 1) for i in range(2, len(L)): if L[i] is True: # 若 i 为质数,则加入质数结果 prime.append(i) for j in range(len(prime)): if i * prime[j] > n: # 如果筛选的范围超过 n 就退出 break # 将 i 与 i 之前的所有质数相乘, # 得出的这些数一定合数,筛去 L[i * prime[j]] = False if i % prime[j] == 0: # 线性筛的核心在于每个合数只被其最小的质因数筛去 # 如果 prime[j] 是 i 的质因数 # 则对于之后的质数与 i 相乘时,其最小质因数为 prime[j] break return prime def main(): a, b, k = map(int, input().split()) L = [0] + find_prime(2 * 10**6) n = len(L) left_index = 0 right_index = n - 1 while left_index < right_index: middle = (left_index + right_index + 1) // 2 if L[middle] < left_index: left_index = middle else: right_index = middle - 1 start = left_index + 1 if n - start < k or L[start + k - 1] - a > b - a: print(-1) return def check(flag): i = start while L[i - 1] <= b - flag + 1: if n - i < k or L[i + k - 1] - max(L[i - 1] + 1, a) > flag - 1: return False i += 1 return True left = 1 right = b - a + 1 while left < right: middle = (left + right) // 2 if check(middle) is True: right = middle else: left = middle + 1 print(left) if __name__ == "__main__": main()
Title: Primes on Interval Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers *a*, *a*<=+<=1, ..., *b* (*a*<=≤<=*b*). You want to find the minimum integer *l* (1<=≤<=*l*<=≤<=*b*<=-<=*a*<=+<=1) such that for any integer *x* (*a*<=≤<=*x*<=≤<=*b*<=-<=*l*<=+<=1) among *l* integers *x*, *x*<=+<=1, ..., *x*<=+<=*l*<=-<=1 there are at least *k* prime numbers. Find and print the required minimum *l*. If no value *l* meets the described limitations, print -1. Input Specification: A single line contains three space-separated integers *a*,<=*b*,<=*k* (1<=≤<=*a*,<=*b*,<=*k*<=≤<=106; *a*<=≤<=*b*). Output Specification: In a single line print a single integer — the required minimum *l*. If there's no solution, print -1. Demo Input: ['2 4 2\n', '6 13 1\n', '1 4 3\n'] Demo Output: ['3\n', '4\n', '-1\n'] Note: none
```python from bisect import bisect_left, bisect_right from collections import Counter, deque from functools import lru_cache from math import factorial, comb, sqrt, gcd, lcm, log2 from copy import deepcopy import heapq from sys import stdin, stdout input = stdin.readline def find_prime(n): # 线性筛法 prime = [] # 存储结果 L = [True] * (n + 1) for i in range(2, len(L)): if L[i] is True: # 若 i 为质数,则加入质数结果 prime.append(i) for j in range(len(prime)): if i * prime[j] > n: # 如果筛选的范围超过 n 就退出 break # 将 i 与 i 之前的所有质数相乘, # 得出的这些数一定合数,筛去 L[i * prime[j]] = False if i % prime[j] == 0: # 线性筛的核心在于每个合数只被其最小的质因数筛去 # 如果 prime[j] 是 i 的质因数 # 则对于之后的质数与 i 相乘时,其最小质因数为 prime[j] break return prime def main(): a, b, k = map(int, input().split()) L = [0] + find_prime(2 * 10**6) n = len(L) left_index = 0 right_index = n - 1 while left_index < right_index: middle = (left_index + right_index + 1) // 2 if L[middle] < left_index: left_index = middle else: right_index = middle - 1 start = left_index + 1 if n - start < k or L[start + k - 1] - a > b - a: print(-1) return def check(flag): i = start while L[i - 1] <= b - flag + 1: if n - i < k or L[i + k - 1] - max(L[i - 1] + 1, a) > flag - 1: return False i += 1 return True left = 1 right = b - a + 1 while left < right: middle = (left + right) // 2 if check(middle) is True: right = middle else: left = middle + 1 print(left) if __name__ == "__main__": main() ```
0
991
C
Candies
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box.
Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
[ "68\n" ]
[ "3\n" ]
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while Petya — $29$.
1,250
[ { "input": "68", "output": "3" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "1" }, { "input": "43", "output": "2" }, { "input": "756", "output": "29" }, { "input": "999999972", "output": "39259423" }, { "input": "999999973", "output": "39259424" }, { "input": "1000000000000000000", "output": "39259424579862572" }, { "input": "6", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "66", "output": "2" }, { "input": "67", "output": "3" }, { "input": "1000", "output": "39" }, { "input": "10000", "output": "392" }, { "input": "100500", "output": "3945" }, { "input": "1000000", "output": "39259" }, { "input": "10000000", "output": "392594" }, { "input": "100000000", "output": "3925942" }, { "input": "123456789", "output": "4846842" }, { "input": "543212345", "output": "21326204" }, { "input": "505050505", "output": "19827992" }, { "input": "777777777", "output": "30535108" }, { "input": "888888871", "output": "34897266" }, { "input": "1000000000", "output": "39259424" }, { "input": "999999999999999973", "output": "39259424579862572" }, { "input": "999999999999999998", "output": "39259424579862572" }, { "input": "999999999999999999", "output": "39259424579862573" }, { "input": "100000000000000000", "output": "3925942457986257" }, { "input": "540776028375043656", "output": "21230555700587649" }, { "input": "210364830044445976", "output": "8258802179385535" }, { "input": "297107279239074256", "output": "11664260821414605" }, { "input": "773524766411950187", "output": "30368137227605772" }, { "input": "228684941775227220", "output": "8978039224174797" }, { "input": "878782039723446310", "output": "34500477210660436" }, { "input": "615090701338187389", "output": "24148106998961343" }, { "input": "325990422297859188", "output": "12798196397960353" }, { "input": "255163492355051023", "output": "10017571883647466" }, { "input": "276392003308849171", "output": "10850991008380891" }, { "input": "601", "output": "23" }, { "input": "983", "output": "38" }, { "input": "729", "output": "29" }, { "input": "70", "output": "3" }, { "input": "703", "output": "28" }, { "input": "257", "output": "10" }, { "input": "526", "output": "20" }, { "input": "466", "output": "18" }, { "input": "738", "output": "29" }, { "input": "116", "output": "5" }, { "input": "888888888888888887", "output": "34897266293211176" }, { "input": "888888888888888888", "output": "34897266293211176" }, { "input": "888888888888888889", "output": "34897266293211176" }, { "input": "999999999999999969", "output": "39259424579862571" }, { "input": "999999999999999970", "output": "39259424579862571" }, { "input": "999999999999999971", "output": "39259424579862572" }, { "input": "999999999999999943", "output": "39259424579862571" }, { "input": "999999999999999944", "output": "39259424579862570" }, { "input": "999999999999999945", "output": "39259424579862571" }, { "input": "999999999999999917", "output": "39259424579862570" }, { "input": "999999999999999918", "output": "39259424579862569" }, { "input": "999999999999999919", "output": "39259424579862570" }, { "input": "99999999999999957", "output": "3925942457986255" }, { "input": "99999999999999958", "output": "3925942457986255" }, { "input": "99999999999999959", "output": "3925942457986256" }, { "input": "888888888888888853", "output": "34897266293211174" }, { "input": "888888888888888854", "output": "34897266293211174" }, { "input": "888888888888888855", "output": "34897266293211175" } ]
1,602,216,887
2,147,483,647
Python 3
OK
TESTS
69
109
307,200
def f(n, k): vasya = 0 total = n while n > 0: m = min(k, n) n -= m vasya += m n -= (n // 10) if 2 * vasya >= total: return True else: return False n = int(input()) lo = 1 hi = n while lo < hi: mid = (lo + hi) // 2 if f(n, mid): hi = mid else: lo = mid + 1 print(hi)
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. Output Specification: Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. Demo Input: ['68\n'] Demo Output: ['3\n'] Note: In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while Petya — $29$.
```python def f(n, k): vasya = 0 total = n while n > 0: m = min(k, n) n -= m vasya += m n -= (n // 10) if 2 * vasya >= total: return True else: return False n = int(input()) lo = 1 hi = n while lo < hi: mid = (lo + hi) // 2 if f(n, mid): hi = mid else: lo = mid + 1 print(hi) ```
3
334
B
Eight Point Sets
PROGRAMMING
1,400
[ "sortings" ]
null
null
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers *x*1,<=*x*2,<=*x*3 and three more integers *y*1,<=*y*2,<=*y*3, such that *x*1<=&lt;<=*x*2<=&lt;<=*x*3, *y*1<=&lt;<=*y*2<=&lt;<=*y*3 and the eight point set consists of all points (*x**i*,<=*y**j*) (1<=≤<=*i*,<=*j*<=≤<=3), except for point (*x*2,<=*y*2). You have a set of eight points. Find out if Gerald can use this set?
The input consists of eight lines, the *i*-th line contains two space-separated integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106). You do not have any other conditions for these points.
In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.
[ "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n" ]
[ "respectable\n", "ugly\n", "ugly\n" ]
none
1,000
[ { "input": "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2", "output": "respectable" }, { "input": "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0", "output": "ugly" }, { "input": "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2", "output": "ugly" }, { "input": "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "ugly" }, { "input": "1000000 1000000\n1000000 999999\n1000000 999998\n999999 1000000\n999999 999998\n999998 1000000\n999998 999999\n999998 999998", "output": "respectable" }, { "input": "0 0\n1 0\n0 1\n1 1\n0 2\n1 2\n0 3\n1 3", "output": "ugly" }, { "input": "0 0\n2 1\n1 0\n0 2\n2 2\n1 0\n2 1\n0 2", "output": "ugly" }, { "input": "0 0\n2 1\n1 0\n0 2\n2 2\n1 0\n2 1\n0 2", "output": "ugly" }, { "input": "791649 383826\n10864 260573\n504506 185571\n899991 511500\n503197 876976\n688727 569035\n343255 961333\n439355 759581", "output": "ugly" }, { "input": "750592 335292\n226387 434036\n299976 154633\n593197 600998\n62014 689355\n566268 571630\n381455 222817\n50555 288617", "output": "ugly" }, { "input": "716334 42808\n211710 645370\n515258 96837\n14392 766713\n439265 939607\n430602 918570\n845044 187545\n957977 441674", "output": "ugly" }, { "input": "337873 813442\n995185 863182\n375545 263618\n310042 130019\n358572 560779\n305725 729179\n377381 267545\n41376 312626", "output": "ugly" }, { "input": "803784 428886\n995691 328351\n211844 386054\n375491 74073\n692402 660275\n366073 536431\n485832 941417\n96032 356022", "output": "ugly" }, { "input": "999231 584954\n246553 267441\n697080 920011\n173593 403511\n58535 101909\n131124 924182\n779830 204560\n684576 533111", "output": "ugly" }, { "input": "666888 741208\n685852 578759\n211123 826453\n244759 601804\n670436 748132\n976425 387060\n587850 804554\n430242 805528", "output": "ugly" }, { "input": "71768 834717\n13140 834717\n13140 991083\n880763 386898\n71768 386898\n880763 991083\n880763 834717\n13140 386898", "output": "ugly" }, { "input": "941532 913025\n941532 862399\n686271 913025\n686271 862399\n686271 461004\n941532 461004\n908398 862399\n908398 913025", "output": "ugly" }, { "input": "251515 680236\n761697 669947\n251515 669947\n761697 680236\n251515 476629\n761697 476629\n453296 669947\n453296 476629", "output": "ugly" }, { "input": "612573 554036\n195039 655769\n472305 655769\n612573 655769\n195039 160740\n472305 160740\n472305 554036\n612573 160740", "output": "ugly" }, { "input": "343395 788566\n171702 674699\n171702 788566\n971214 788566\n343395 9278\n971214 9278\n343395 674699\n971214 674699", "output": "ugly" }, { "input": "38184 589856\n281207 447136\n281207 42438\n38184 42438\n38184 447136\n880488 589856\n281207 589856\n880488 42438", "output": "ugly" }, { "input": "337499 89260\n337499 565883\n603778 89260\n603778 565883\n234246 89260\n603778 17841\n337499 17841\n234246 17841", "output": "ugly" }, { "input": "180952 311537\n180952 918548\n126568 918548\n180952 268810\n732313 918548\n126568 311537\n126568 268810\n732313 311537", "output": "ugly" }, { "input": "323728 724794\n265581 165113\n323728 146453\n265581 146453\n591097 146453\n265581 724794\n323728 165113\n591097 165113", "output": "ugly" }, { "input": "642921 597358\n922979 597358\n127181 616833\n642921 828316\n922979 828316\n127181 597358\n922979 616833\n127181 828316", "output": "respectable" }, { "input": "69586 260253\n74916 203798\n985457 203798\n74916 943932\n985457 943932\n69586 943932\n985457 260253\n69586 203798", "output": "respectable" }, { "input": "57930 637387\n883991 573\n57930 573\n57930 499963\n399327 573\n399327 637387\n883991 637387\n883991 499963", "output": "respectable" }, { "input": "52820 216139\n52820 999248\n290345 216139\n290345 999248\n308639 216139\n308639 999248\n52820 477113\n308639 477113", "output": "respectable" }, { "input": "581646 464672\n493402 649074\n581646 649074\n214619 649074\n581646 252709\n214619 252709\n214619 464672\n493402 252709", "output": "respectable" }, { "input": "787948 77797\n421941 615742\n421941 77797\n400523 77797\n400523 111679\n787948 615742\n400523 615742\n787948 111679", "output": "respectable" }, { "input": "583956 366985\n759621 567609\n756846 567609\n759621 176020\n583956 567609\n583956 176020\n759621 366985\n756846 176020", "output": "respectable" }, { "input": "0 50000\n0 0\n0 1000000\n50000 0\n50000 1000000\n1000000 0\n1000000 50000\n1000000 1000000", "output": "respectable" }, { "input": "0 8\n0 9\n0 10\n1 8\n3 8\n3 8\n3 9\n3 10", "output": "ugly" }, { "input": "0 1\n0 1\n0 2\n1 1\n1 2\n2 1\n2 1\n2 2", "output": "ugly" }, { "input": "1 2\n1 3\n1 4\n2 2\n2 4\n4 2\n4 2\n4 4", "output": "ugly" }, { "input": "0 0\n0 1\n0 2\n0 0\n1 2\n2 0\n2 1\n2 2", "output": "ugly" }, { "input": "0 0\n0 0\n0 0\n1 1\n1 1\n2 2\n2 2\n2 2", "output": "ugly" }, { "input": "0 0\n0 0\n0 2\n1 1\n1 2\n2 0\n2 1\n2 2", "output": "ugly" }, { "input": "0 0\n0 1\n0 3\n1 0\n1 3\n2 0\n2 2\n2 3", "output": "ugly" }, { "input": "0 0\n0 1\n0 2\n1 0\n1 2\n3 0\n3 1\n3 2", "output": "respectable" }, { "input": "1 1\n1 2\n1 5\n2 1\n2 5\n5 1\n5 2\n5 5", "output": "respectable" }, { "input": "1 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 1\n3 3", "output": "ugly" }, { "input": "0 0\n0 0\n1 0\n0 1\n2 1\n1 2\n2 2\n2 2", "output": "ugly" }, { "input": "1 1\n1 1\n1 3\n2 1\n2 3\n3 2\n3 2\n3 3", "output": "ugly" }, { "input": "1 0\n1 0\n1 0\n2 3\n2 3\n3 4\n3 4\n3 4", "output": "ugly" } ]
1,375,123,519
2,147,483,647
Python 3
OK
TESTS
45
248
0
import sys fin = sys.stdin points = [] for i in range(8): x, y = map(int, fin.readline().split()) points += [(x, y)] def CheckPoints(p): if not p[0][0] == p[1][0] == p[2][0]: return False x1 = p[0][0] if not p[3][0] == p[4][0]: return False x2 = p[3][0] if not p[5][0] == p[6][0] == p[7][0]: return False x3 = p[5][0] if not p[0][1] == p[3][1] == p[5][1]: return False y1 = p[0][1] if not p[1][1] == p[6][1]: return False y2 = p[1][1] if not p[2][1] == p[4][1] == p[7][1]: return False y3 = p[2][1] return x1 < x2 < x3 and y1 < y2 < y3 from itertools import * for p in permutations(points): if CheckPoints(p): print("respectable") break else: print("ugly")
Title: Eight Point Sets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers *x*1,<=*x*2,<=*x*3 and three more integers *y*1,<=*y*2,<=*y*3, such that *x*1<=&lt;<=*x*2<=&lt;<=*x*3, *y*1<=&lt;<=*y*2<=&lt;<=*y*3 and the eight point set consists of all points (*x**i*,<=*y**j*) (1<=≤<=*i*,<=*j*<=≤<=3), except for point (*x*2,<=*y*2). You have a set of eight points. Find out if Gerald can use this set? Input Specification: The input consists of eight lines, the *i*-th line contains two space-separated integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106). You do not have any other conditions for these points. Output Specification: In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. Demo Input: ['0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n', '0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n', '1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n'] Demo Output: ['respectable\n', 'ugly\n', 'ugly\n'] Note: none
```python import sys fin = sys.stdin points = [] for i in range(8): x, y = map(int, fin.readline().split()) points += [(x, y)] def CheckPoints(p): if not p[0][0] == p[1][0] == p[2][0]: return False x1 = p[0][0] if not p[3][0] == p[4][0]: return False x2 = p[3][0] if not p[5][0] == p[6][0] == p[7][0]: return False x3 = p[5][0] if not p[0][1] == p[3][1] == p[5][1]: return False y1 = p[0][1] if not p[1][1] == p[6][1]: return False y2 = p[1][1] if not p[2][1] == p[4][1] == p[7][1]: return False y3 = p[2][1] return x1 < x2 < x3 and y1 < y2 < y3 from itertools import * for p in permutations(points): if CheckPoints(p): print("respectable") break else: print("ugly") ```
3
501
C
Misha and Forest
PROGRAMMING
1,500
[ "constructive algorithms", "data structures", "greedy", "sortings", "trees" ]
null
null
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of *n* vertices. For each vertex *v* from 0 to *n*<=-<=1 he wrote down two integers, *degree**v* and *s**v*, were the first integer is the number of vertices adjacent to vertex *v*, and the second integer is the XOR sum of the numbers of vertices adjacent to *v* (if there were no adjacent vertices, he wrote down 0). Next day Misha couldn't remember what graph he initially had. Misha has values *degree**v* and *s**v* left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.
The first line contains integer *n* (1<=≤<=*n*<=≤<=216), the number of vertices in the graph. The *i*-th of the next lines contains numbers *degree**i* and *s**i* (0<=≤<=*degree**i*<=≤<=*n*<=-<=1, 0<=≤<=*s**i*<=&lt;<=216), separated by a space.
In the first line print number *m*, the number of edges of the graph. Next print *m* lines, each containing two distinct numbers, *a* and *b* (0<=≤<=*a*<=≤<=*n*<=-<=1, 0<=≤<=*b*<=≤<=*n*<=-<=1), corresponding to edge (*a*,<=*b*). Edges can be printed in any order; vertices of the edge can also be printed in any order.
[ "3\n2 3\n1 0\n1 0\n", "2\n1 1\n1 0\n" ]
[ "2\n1 0\n2 0\n", "1\n0 1\n" ]
The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
1,500
[ { "input": "3\n2 3\n1 0\n1 0", "output": "2\n1 0\n2 0" }, { "input": "2\n1 1\n1 0", "output": "1\n0 1" }, { "input": "10\n3 13\n2 6\n1 5\n3 5\n1 3\n2 2\n2 6\n1 6\n1 3\n2 3", "output": "9\n2 5\n4 3\n7 6\n8 3\n5 0\n6 1\n3 9\n1 0\n9 0" }, { "input": "10\n1 2\n1 7\n1 0\n1 8\n0 0\n1 9\n0 0\n1 1\n1 3\n1 5", "output": "4\n0 2\n1 7\n3 8\n5 9" }, { "input": "5\n1 1\n2 2\n2 2\n2 6\n1 3", "output": "4\n0 1\n4 3\n1 2\n3 2" }, { "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": "11\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 8\n1 7\n0 0\n0 0", "output": "1\n7 8" }, { "input": "12\n0 0\n1 3\n0 0\n1 1\n0 0\n1 7\n0 0\n1 5\n0 0\n0 0\n0 0\n0 0", "output": "2\n1 3\n5 7" }, { "input": "13\n2 7\n0 0\n0 0\n2 11\n2 7\n2 14\n2 3\n2 1\n1 11\n3 15\n1 6\n2 11\n1 9", "output": "10\n8 11\n10 6\n12 9\n11 3\n6 9\n3 0\n9 5\n0 4\n5 7\n4 7" }, { "input": "14\n1 10\n1 9\n3 4\n1 2\n0 0\n1 11\n1 12\n1 10\n1 10\n2 10\n3 15\n3 14\n2 4\n0 0", "output": "10\n0 10\n1 9\n3 2\n5 11\n6 12\n7 10\n8 10\n9 11\n12 2\n11 2" }, { "input": "15\n0 0\n1 6\n3 2\n1 13\n2 15\n2 5\n1 1\n2 1\n1 4\n1 2\n0 0\n1 14\n0 0\n1 3\n2 9", "output": "9\n1 6\n3 13\n8 4\n9 2\n11 14\n4 7\n14 2\n7 5\n2 5" }, { "input": "16\n1 10\n2 13\n1 13\n2 1\n1 3\n2 2\n1 14\n0 0\n1 1\n1 14\n1 0\n0 0\n0 0\n1 2\n2 15\n0 0", "output": "8\n0 10\n2 13\n4 3\n6 14\n8 1\n9 14\n3 5\n1 5" }, { "input": "17\n0 0\n2 6\n0 0\n2 11\n0 0\n1 13\n1 3\n1 10\n0 0\n1 1\n1 7\n0 0\n0 0\n3 9\n0 0\n2 12\n0 0", "output": "7\n5 13\n6 3\n7 10\n9 1\n3 13\n1 15\n13 15" }, { "input": "18\n0 0\n0 0\n2 19\n1 2\n2 29\n0 0\n1 7\n1 6\n1 12\n1 13\n0 0\n1 12\n4 23\n1 9\n0 0\n0 0\n2 14\n1 4", "output": "9\n3 2\n6 7\n8 12\n9 13\n11 12\n17 4\n2 16\n4 12\n16 12" }, { "input": "19\n1 13\n0 0\n1 9\n1 11\n1 11\n2 3\n2 30\n0 0\n1 5\n1 2\n0 0\n5 29\n1 6\n2 11\n0 0\n0 0\n0 0\n0 0\n2 13", "output": "10\n0 13\n2 9\n3 11\n4 11\n8 5\n12 6\n13 11\n5 11\n6 18\n11 18" }, { "input": "20\n0 0\n2 15\n0 0\n2 7\n1 1\n0 0\n0 0\n0 0\n1 9\n2 11\n0 0\n1 1\n0 0\n0 0\n1 3\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5\n4 1\n8 9\n11 1\n14 3\n9 3" }, { "input": "1\n0 0", "output": "0" } ]
1,558,113,748
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
16
1,000
5,017,600
n = int(input()) ds = [] m_double = 0 for i in range(n): deg, s = list(map(int, input().split())) ds.append([deg,s]) m_double += deg m = int(m_double/2) print(m) for i in range(m): for j in range(len(ds)): if (ds[j][0] == 1): k = ds[j][1] print(j, k) ds[j][0] = 0 ds[k][0] -= 1 ds[k][1] ^= j break
Title: Misha and Forest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of *n* vertices. For each vertex *v* from 0 to *n*<=-<=1 he wrote down two integers, *degree**v* and *s**v*, were the first integer is the number of vertices adjacent to vertex *v*, and the second integer is the XOR sum of the numbers of vertices adjacent to *v* (if there were no adjacent vertices, he wrote down 0). Next day Misha couldn't remember what graph he initially had. Misha has values *degree**v* and *s**v* left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=216), the number of vertices in the graph. The *i*-th of the next lines contains numbers *degree**i* and *s**i* (0<=≤<=*degree**i*<=≤<=*n*<=-<=1, 0<=≤<=*s**i*<=&lt;<=216), separated by a space. Output Specification: In the first line print number *m*, the number of edges of the graph. Next print *m* lines, each containing two distinct numbers, *a* and *b* (0<=≤<=*a*<=≤<=*n*<=-<=1, 0<=≤<=*b*<=≤<=*n*<=-<=1), corresponding to edge (*a*,<=*b*). Edges can be printed in any order; vertices of the edge can also be printed in any order. Demo Input: ['3\n2 3\n1 0\n1 0\n', '2\n1 1\n1 0\n'] Demo Output: ['2\n1 0\n2 0\n', '1\n0 1\n'] Note: The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
```python n = int(input()) ds = [] m_double = 0 for i in range(n): deg, s = list(map(int, input().split())) ds.append([deg,s]) m_double += deg m = int(m_double/2) print(m) for i in range(m): for j in range(len(ds)): if (ds[j][0] == 1): k = ds[j][1] print(j, k) ds[j][0] = 0 ds[k][0] -= 1 ds[k][1] ^= j break ```
0
1,007
A
Reorder the Array
PROGRAMMING
1,300
[ "combinatorics", "data structures", "math", "sortings", "two pointers" ]
null
null
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
[ "7\n10 1 1 1 5 5 3\n", "5\n1 1 1 1 1\n" ]
[ "4\n", "0\n" ]
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
500
[ { "input": "7\n10 1 1 1 5 5 3", "output": "4" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "output": "3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "1\n1", "output": "0" }, { "input": "7\n3 5 2 2 5 2 4", "output": "4" }, { "input": "5\n1 5 4 2 3", "output": "4" } ]
1,532,536,752
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
3
763
268,390,400
import itertools n=input() a =list(map(int, input().split())) b=list(itertools.permutations(a)) c=0 for i in b: cnt=0 for j in range(len(a)): if a[j]<i[j]: cnt+=1 if cnt>c: c=cnt print(c)
Title: Reorder the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. Output Specification: Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. Demo Input: ['7\n10 1 1 1 5 5 3\n', '5\n1 1 1 1 1\n'] Demo Output: ['4\n', '0\n'] Note: In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
```python import itertools n=input() a =list(map(int, input().split())) b=list(itertools.permutations(a)) c=0 for i in b: cnt=0 for j in range(len(a)): if a[j]<i[j]: cnt+=1 if cnt>c: c=cnt print(c) ```
0
45
A
Codecraft III
PROGRAMMING
900
[ "implementation" ]
A. Codecraft III
2
256
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that. All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December.
The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III.
Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.
[ "November\n3\n", "May\n24\n" ]
[ "February\n", "May\n" ]
none
0
[ { "input": "November\n3", "output": "February" }, { "input": "May\n24", "output": "May" }, { "input": "April\n0", "output": "April" }, { "input": "September\n0", "output": "September" }, { "input": "August\n0", "output": "August" }, { "input": "June\n1", "output": "July" }, { "input": "July\n2", "output": "September" }, { "input": "September\n3", "output": "December" }, { "input": "July\n4", "output": "November" }, { "input": "August\n24", "output": "August" }, { "input": "May\n48", "output": "May" }, { "input": "November\n47", "output": "October" }, { "input": "December\n49", "output": "January" }, { "input": "June\n99", "output": "September" }, { "input": "March\n100", "output": "July" }, { "input": "December\n1", "output": "January" }, { "input": "January\n11", "output": "December" }, { "input": "December\n0", "output": "December" }, { "input": "January\n0", "output": "January" }, { "input": "July\n77", "output": "December" }, { "input": "February\n11", "output": "January" }, { "input": "February\n22", "output": "December" }, { "input": "July\n33", "output": "April" }, { "input": "May\n44", "output": "January" }, { "input": "June\n97", "output": "July" } ]
1,696,961,901
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
15
92
0
monthes = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] current = input() after = int(input()) ind = monthes.index(current) if (after + ind) > 12: print(monthes[(after + ind)%12]) else: print(monthes[after + ind])
Title: Codecraft III Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that. All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December. Input Specification: The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. Output Specification: Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. Demo Input: ['November\n3\n', 'May\n24\n'] Demo Output: ['February\n', 'May\n'] Note: none
```python monthes = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] current = input() after = int(input()) ind = monthes.index(current) if (after + ind) > 12: print(monthes[(after + ind)%12]) else: print(monthes[after + ind]) ```
-1
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros.
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "1000000000000000000 1000000000000000000", "output": "0" }, { "input": "1 1000000000000000000", "output": "1712" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 7", "output": "3" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "2" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "3" }, { "input": "3 3", "output": "0" }, { "input": "3 4", "output": "0" }, { "input": "3 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "2" }, { "input": "4 4", "output": "0" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "2" }, { "input": "5 7", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "7 7", "output": "0" }, { "input": "1 8", "output": "3" }, { "input": "6 8", "output": "1" }, { "input": "7 8", "output": "0" }, { "input": "8 8", "output": "0" }, { "input": "1 1022", "output": "45" }, { "input": "1 1023", "output": "45" }, { "input": "1 1024", "output": "45" }, { "input": "1 1025", "output": "45" }, { "input": "1 1026", "output": "45" }, { "input": "509 1022", "output": "11" }, { "input": "510 1022", "output": "10" }, { "input": "511 1022", "output": "9" }, { "input": "512 1022", "output": "9" }, { "input": "513 1022", "output": "9" }, { "input": "509 1023", "output": "11" }, { "input": "510 1023", "output": "10" }, { "input": "511 1023", "output": "9" }, { "input": "512 1023", "output": "9" }, { "input": "513 1023", "output": "9" }, { "input": "509 1024", "output": "11" }, { "input": "510 1024", "output": "10" }, { "input": "511 1024", "output": "9" }, { "input": "512 1024", "output": "9" }, { "input": "513 1024", "output": "9" }, { "input": "509 1025", "output": "11" }, { "input": "510 1025", "output": "10" }, { "input": "511 1025", "output": "9" }, { "input": "512 1025", "output": "9" }, { "input": "513 1025", "output": "9" }, { "input": "1 1000000000", "output": "408" }, { "input": "10000000000 70000000000000000", "output": "961" }, { "input": "1 935829385028502935", "output": "1712" }, { "input": "500000000000000000 1000000000000000000", "output": "58" }, { "input": "500000000000000000 576460752303423488", "output": "57" }, { "input": "576460752303423488 1000000000000000000", "output": "1" }, { "input": "999999999999999999 1000000000000000000", "output": "0" }, { "input": "1124800395214847 36011204832919551", "output": "257" }, { "input": "1124800395214847 36011204832919550", "output": "256" }, { "input": "1124800395214847 36011204832919552", "output": "257" }, { "input": "1124800395214846 36011204832919551", "output": "257" }, { "input": "1124800395214848 36011204832919551", "output": "256" }, { "input": "1 287104476244869119", "output": "1603" }, { "input": "1 287104476244869118", "output": "1602" }, { "input": "1 287104476244869120", "output": "1603" }, { "input": "492581209243647 1000000000000000000", "output": "583" }, { "input": "492581209243646 1000000000000000000", "output": "583" }, { "input": "492581209243648 1000000000000000000", "output": "582" }, { "input": "1099444518911 1099444518911", "output": "1" }, { "input": "1099444518910 1099444518911", "output": "1" }, { "input": "1099444518911 1099444518912", "output": "1" }, { "input": "1099444518910 1099444518912", "output": "1" }, { "input": "864691128455135231 864691128455135231", "output": "1" }, { "input": "864691128455135231 864691128455135232", "output": "1" }, { "input": "864691128455135230 864691128455135232", "output": "1" }, { "input": "864691128455135230 864691128455135231", "output": "1" }, { "input": "864691128455135231 1000000000000000000", "output": "1" }, { "input": "864691128455135232 1000000000000000000", "output": "0" }, { "input": "864691128455135230 1000000000000000000", "output": "1" }, { "input": "576460752303423487 576460752303423487", "output": "0" }, { "input": "1 576460752303423487", "output": "1711" }, { "input": "1 576460752303423486", "output": "1711" }, { "input": "2 1000000000000000000", "output": "1712" }, { "input": "3 1000000000000000000", "output": "1711" }, { "input": "4 1000000000000000000", "output": "1711" }, { "input": "5 1000000000000000000", "output": "1711" }, { "input": "6 1000000000000000000", "output": "1710" }, { "input": "5 6", "output": "2" }, { "input": "1 2", "output": "1" } ]
1,456,584,020
2,147,483,647
Python 3
OK
TESTS
103
77
0
a, b = map(int, input().split()) # map works as [f, iterable] gives [f(x) for x in iterable] print(sum((2 ** i - 1)^ (2 **j) in range(a, b + 1) for i in range(2, 65) for j in range(0, i-1)))
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros. Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. Output Specification: Print one integer – the number of years Limak will count in his chosen interval. Demo Input: ['5 10\n', '2015 2015\n', '100 105\n', '72057594000000000 72057595000000000\n'] Demo Output: ['2\n', '1\n', '0\n', '26\n'] Note: In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
```python a, b = map(int, input().split()) # map works as [f, iterable] gives [f(x) for x in iterable] print(sum((2 ** i - 1)^ (2 **j) in range(a, b + 1) for i in range(2, 65) for j in range(0, i-1))) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,689,588,483
2,147,483,647
Python 3
OK
TESTS
30
92
0
n=input() up=0 low=0 for i in n: if(i.islower()): low+=1 elif(i.isupper()): up+=1 if(low==up or low>up): s=n.lower() print(s) else: s=n.upper() print(s)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python n=input() up=0 low=0 for i in n: if(i.islower()): low+=1 elif(i.isupper()): up+=1 if(low==up or low>up): s=n.lower() print(s) else: s=n.upper() print(s) ```
3.977
26
A
Almost Prime
PROGRAMMING
900
[ "number theory" ]
A. Almost Prime
2
256
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output the amount of almost prime numbers between 1 and *n*, inclusive.
[ "10\n", "21\n" ]
[ "2\n", "8\n" ]
none
500
[ { "input": "10", "output": "2" }, { "input": "21", "output": "8" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, { "input": "19", "output": "6" }, { "input": "40", "output": "19" }, { "input": "77", "output": "41" }, { "input": "222", "output": "125" }, { "input": "987", "output": "501" }, { "input": "1000", "output": "508" }, { "input": "2000", "output": "958" }, { "input": "3000", "output": "1375" }, { "input": "2999", "output": "1375" }, { "input": "2998", "output": "1375" }, { "input": "2997", "output": "1374" }, { "input": "1429", "output": "706" }, { "input": "1673", "output": "808" }, { "input": "1500", "output": "732" }, { "input": "500", "output": "266" }, { "input": "856", "output": "439" } ]
1,528,647,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
154
0
limit = int(input()) mark = [0]*(limit+1) c = 0 for i in range(4,limit+1,2): mark[i]+=1 for i in range(3,limit+1,2): if(not mark[i]): for j in range(2*i,limit+1,i): mark[j]+=1 if mark[j] == 2: c+=1 print(c)
Title: Almost Prime Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. Input Specification: Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). Output Specification: Output the amount of almost prime numbers between 1 and *n*, inclusive. Demo Input: ['10\n', '21\n'] Demo Output: ['2\n', '8\n'] Note: none
```python limit = int(input()) mark = [0]*(limit+1) c = 0 for i in range(4,limit+1,2): mark[i]+=1 for i in range(3,limit+1,2): if(not mark[i]): for j in range(2*i,limit+1,i): mark[j]+=1 if mark[j] == 2: c+=1 print(c) ```
0
172
A
Phone Code
PROGRAMMING
800
[ "*special", "brute force", "implementation" ]
null
null
Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string *c* which is a prefix (the beginning) of each *s**i* for all *i* (1<=≤<=*i*<=≤<=*n*). Help Polycarpus determine the length of the city phone code.
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Print the number of digits in the city phone code.
[ "4\n00209\n00219\n00999\n00909\n", "2\n1\n2\n", "3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n" ]
[ "2\n", "0\n", "12\n" ]
A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an empty string. In the third sample the city phone code is string "770123456789".
1,000
[ { "input": "4\n00209\n00219\n00999\n00909", "output": "2" }, { "input": "2\n1\n2", "output": "0" }, { "input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12" }, { "input": "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214", "output": "4" }, { "input": "10\n15424\n10953\n19176\n15514\n16284\n18680\n19305\n13816\n16168\n15924", "output": "1" }, { "input": "10\n4906361343\n8985777485\n1204265609\n7088384855\n4127287014\n7904807820\n3032139021\n5999959109\n6477458281\n3244359368", "output": "0" }, { "input": "10\n3717208309\n3717208306\n3717208302\n3717208301\n3717208303\n3717208308\n3717208304\n3717208307\n3717208300\n3717208305", "output": "9" }, { "input": "9\n2881\n2808\n2868\n2874\n2894\n2870\n2818\n2896\n2890", "output": "2" }, { "input": "2\n4\n9", "output": "0" }, { "input": "2\n29867863763143509570\n59261213969200291523", "output": "0" }, { "input": "2\n84\n62", "output": "0" }, { "input": "2\n75970434466248453472\n75970434466248453476", "output": "19" }, { "input": "10\n17254072509168593435\n17254072509168593433\n17254072509168593430\n17254072509168593432\n17254072509168593439\n17254072509168593436\n17254072509168593438\n17254072509168593437\n17254072509168593431\n17254072509168593434", "output": "19" } ]
1,686,051,908
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
x=int(input()) s=-1 n=0 for i in range(x): y=int(input() for j in range(len(y)): if y[j]!=s: s=y[j] else: n+=1 print(n)
Title: Phone Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string *c* which is a prefix (the beginning) of each *s**i* for all *i* (1<=≤<=*i*<=≤<=*n*). Help Polycarpus determine the length of the city phone code. Input Specification: The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different. Output Specification: Print the number of digits in the city phone code. Demo Input: ['4\n00209\n00219\n00999\n00909\n', '2\n1\n2\n', '3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n'] Demo Output: ['2\n', '0\n', '12\n'] Note: A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an empty string. In the third sample the city phone code is string "770123456789".
```python x=int(input()) s=-1 n=0 for i in range(x): y=int(input() for j in range(len(y)): if y[j]!=s: s=y[j] else: n+=1 print(n) ```
-1
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1", "output": "1891" }, { "input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2", "output": "1688" }, { "input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12", "output": "1391" }, { "input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32", "output": "368" }, { "input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1", "output": "435" }, { "input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100", "output": "326" }, { "input": "45 894\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 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1", "output": "139" }, { "input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86", "output": "514" }, { "input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1", "output": "586" }, { "input": "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1", "output": "384" }, { "input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1", "output": "174" }, { "input": "81 4131\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 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "807" }, { "input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96", "output": "490" }, { "input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1", "output": "284" }, { "input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1", "output": "1589" }, { "input": "10 100\n1 1 1 1 1 1 1 1 1 1", "output": "18" }, { "input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99", "output": "1017" }, { "input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 6\n1", "output": "1" }, { "input": "1 5\n1", "output": "0" }, { "input": "1 3\n4", "output": "-1" }, { "input": "3 24\n2 1 2", "output": "-1" } ]
1,695,833,011
2,147,483,647
PyPy 3
OK
TESTS
26
108
0
songs,max_time=map(int,input().split()) songs_length=list(map(int,input().split())) time_required=sum(songs_length)+(songs-1)*10 if(time_required>max_time): print(-1) else: print((songs-1)*2+(max_time-time_required)//5)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. Input Specification: The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). Output Specification: If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. Demo Input: ['3 30\n2 2 1\n', '3 20\n2 1 1\n'] Demo Output: ['5\n', '-1\n'] Note: Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
```python songs,max_time=map(int,input().split()) songs_length=list(map(int,input().split())) time_required=sum(songs_length)+(songs-1)*10 if(time_required>max_time): print(-1) else: print((songs-1)*2+(max_time-time_required)//5) ```
3
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,669,094,117
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
inp1 = input("") inp1_lst = [int(i) for i in inp1.split()] n = inp1_lst[0] m = input("") m_lst = [int(i) for i in m.split()] m_lst.sort() print(m_lst[n-1]-m_lst[0])
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python inp1 = input("") inp1_lst = [int(i) for i in inp1.split()] n = inp1_lst[0] m = input("") m_lst = [int(i) for i in m.split()] m_lst.sort() print(m_lst[n-1]-m_lst[0]) ```
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,623,772,164
2,147,483,647
PyPy 3
OK
TESTS
102
109
0
intput1 = input() intput2 = input() l = [(str(int(a) ^ int(b))) for a,b in zip(intput1,intput2)] print("".join(l))
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 intput1 = input() intput2 = input() l = [(str(int(a) ^ int(b))) for a,b in zip(intput1,intput2)] print("".join(l)) ```
3.97275
478
B
Random Teams
PROGRAMMING
1,300
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
1,000
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": "1000000000 1", "output": "499999999500000000 499999999500000000" }, { "input": "5000000 12", "output": "1041664166668 12499942500066" }, { "input": "1833 195", "output": "7722 1342341" }, { "input": "1000000000 1000000000", "output": "0 0" }, { "input": "1000000000 1000000", "output": "499500000000 499000500499500000" }, { "input": "1000000000 32170", "output": "15541930838100 499967831017438365" }, { "input": "1000000 1000", "output": "499500000 499000999500" }, { "input": "1234 1123", "output": "111 6216" }, { "input": "599222887 298488", "output": "601178656545 179355218158217800" }, { "input": "999999999 500000000", "output": "499999999 124999999750000000" }, { "input": "1000000000 384842119", "output": "845473643 189209609585784021" }, { "input": "1000000000 384842119", "output": "845473643 189209609585784021" }, { "input": "1000000000 2", "output": "249999999500000000 499999998500000001" }, { "input": "1000000000 999999999", "output": "1 1" }, { "input": "38447 383", "output": "1910550 724453080" }, { "input": "100000000 99999799", "output": "201 20301" }, { "input": "1 1", "output": "0 0" }, { "input": "2 1", "output": "1 1" }, { "input": "2 2", "output": "0 0" }, { "input": "10 10", "output": "0 0" } ]
1,659,004,881
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
n,m=map(int,input().rstrip().split()) aa=((n//m)) a=n-(m-1) print(int((m*aa*(aa-1)/2+aa*(n%m))),(n-m)*(n-m+1)/2)
Title: Random Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. Input Specification: The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. Output Specification: The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. Demo Input: ['5 1\n', '3 2\n', '6 3\n'] Demo Output: ['10 10\n', '1 1\n', '3 6\n'] Note: In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
```python n,m=map(int,input().rstrip().split()) aa=((n//m)) a=n-(m-1) print(int((m*aa*(aa-1)/2+aa*(n%m))),(n-m)*(n-m+1)/2) ```
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,539,151,798
2,147,483,647
Python 3
OK
TESTS
40
171
512,000
import re print(['NO','YES'][re.search(r'h(.*)e(.*)l(.*)l(.*)o',input())!=None])
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 import re print(['NO','YES'][re.search(r'h(.*)e(.*)l(.*)l(.*)o',input())!=None]) ```
3.913546
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" }, { "input": "3\n2 3\n1 1\n3 2", "output": "Happy Alex" }, { "input": "4\n4 1\n3 2\n2 3\n1 4", "output": "Happy Alex" }, { "input": "2\n2 1\n1 2", "output": "Happy Alex" }, { "input": "3\n3 2\n1 1\n2 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" }, { "input": "3\n1 2\n2 1\n3 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" } ]
1,667,774,354
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
7,168,000
""" https://codeforces.com/problemset/problem/456/A """ laptops = int(input()) prqa = [] qua = [] for _ in range(laptops): prix, qualite = [int(x) for x in input().split()] prqa.append((prix, qualite)) prqa = sorted(prqa) qua = [q for p, q in prqa] happy = False for i, (p0, q0) in enumerate(prqa[:-1]): if min(qua[i + 1 :]) < q0: happy = True break if happy: print("Happy Alex") else: print("Poor Alex")
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python """ https://codeforces.com/problemset/problem/456/A """ laptops = int(input()) prqa = [] qua = [] for _ in range(laptops): prix, qualite = [int(x) for x in input().split()] prqa.append((prix, qualite)) prqa = sorted(prqa) qua = [q for p, q in prqa] happy = False for i, (p0, q0) in enumerate(prqa[:-1]): if min(qua[i + 1 :]) < q0: happy = True break if happy: print("Happy Alex") else: print("Poor Alex") ```
0
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
1,613,963,654
2,147,483,647
Python 3
OK
TESTS
31
124
307,200
def solve(arr, birds): for i, v in enumerate(arr): w_index = v[0] - 1 lb = v[1]-1 rb = birds[w_index] - lb - 1 if w_index != 0: birds[w_index-1] += lb if w_index != len(birds)-1 : birds[w_index+1] += rb birds[w_index] = 0 for i in birds: print(i) def main(): n = int(input()) birds = list(map(int, input().split(' '))) m = int(input()) arr = [] for i in range(m): el = list(map(int, input().split(' '))) arr.append(el) solve(arr, birds) main()
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. Output Specification: On the *i*-th line of the output print the number of birds on the *i*-th wire. Demo Input: ['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n'] Demo Output: ['0\n12\n5\n0\n16\n', '3\n0\n3\n'] Note: none
```python def solve(arr, birds): for i, v in enumerate(arr): w_index = v[0] - 1 lb = v[1]-1 rb = birds[w_index] - lb - 1 if w_index != 0: birds[w_index-1] += lb if w_index != len(birds)-1 : birds[w_index+1] += rb birds[w_index] = 0 for i in birds: print(i) def main(): n = int(input()) birds = list(map(int, input().split(' '))) m = int(input()) arr = [] for i in range(m): el = list(map(int, input().split(' '))) arr.append(el) solve(arr, birds) main() ```
3
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
1,586,771,853
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
307,200
def count(a): s = 'bear' c = 0 n = 0 if(len(a)<len(s)): return -1 for i in range(0,len(a)-3): if(s == a[i:i+4]): k = i - n k = (len(a[i+4:]))*k c += k+(len(a)-i+1) n = i return c-4 def main(): s = input() print(count(s)) main()
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python def count(a): s = 'bear' c = 0 n = 0 if(len(a)<len(s)): return -1 for i in range(0,len(a)-3): if(s == a[i:i+4]): k = i - n k = (len(a[i+4:]))*k c += k+(len(a)-i+1) n = i return c-4 def main(): s = input() print(count(s)) main() ```
0
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", "output": "9" }, { "input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2", "output": "5" }, { "input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352", "output": "0" }, { "input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0" }, { "input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5", "output": "0" }, { "input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1", "output": "0" }, { "input": "1 1 1\n1 1", "output": "0" }, { "input": "10 10 4\n5 9\n6 9\n6 10\n5 10", "output": "4" }, { "input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000", "output": "4" }, { "input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2", "output": "5" }, { "input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000", "output": "4" } ]
1,668,487,809
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
623
15,872,000
n, m, k = map(int, input().split()) board = [[0 for _ in range(m)]for _ in range(n)] d = [[[0, -1], [-1, -1], [-1, 0]], [[0, 1], [-1, 1], [1, 0]], [[0, 1], [1, 1], [1, 0]], [[0, -1], [1, -1], [1, 0]]] move = [list(map(int, input().split()))for _ in range(k)] flag = False ans = 0 for i in range(k): x, y = move[i] board[x-1][y-1] = 1 for j in range(4): cnt = 0 for k in range(3): nx = x + d[j][k][0] - 1 ny = y + d[j][k][1] - 1 if nx < 0 or nx >= n or ny < 0 or ny >= m: continue cnt += board[nx][ny] if cnt == 3: flag = True ans = i+1 break if flag: break print(ans)
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. Input Specification: The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. Output Specification: If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. Demo Input: ['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n'] Demo Output: ['4\n', '5\n', '0\n'] Note: none
```python n, m, k = map(int, input().split()) board = [[0 for _ in range(m)]for _ in range(n)] d = [[[0, -1], [-1, -1], [-1, 0]], [[0, 1], [-1, 1], [1, 0]], [[0, 1], [1, 1], [1, 0]], [[0, -1], [1, -1], [1, 0]]] move = [list(map(int, input().split()))for _ in range(k)] flag = False ans = 0 for i in range(k): x, y = move[i] board[x-1][y-1] = 1 for j in range(4): cnt = 0 for k in range(3): nx = x + d[j][k][0] - 1 ny = y + d[j][k][1] - 1 if nx < 0 or nx >= n or ny < 0 or ny >= m: continue cnt += board[nx][ny] if cnt == 3: flag = True ans = i+1 break if flag: break print(ans) ```
0
785
B
Anton and Classes
PROGRAMMING
1,100
[ "greedy", "sortings" ]
null
null
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has *n* variants when he will attend chess classes, *i*-th variant is given by a period of time (*l*1,<=*i*,<=*r*1,<=*i*). Also he has *m* variants when he will attend programming classes, *i*-th variant is given by a period of time (*l*2,<=*i*,<=*r*2,<=*i*). Anton needs to choose exactly one of *n* possible periods of time when he will attend chess classes and exactly one of *m* possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal. The distance between periods (*l*1,<=*r*1) and (*l*2,<=*r*2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |*i*<=-<=*j*|, where *l*1<=≤<=*i*<=≤<=*r*1 and *l*2<=≤<=*j*<=≤<=*r*2. In particular, when the periods intersect, the distance between them is 0. Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of time periods when Anton can attend chess classes. Each of the following *n* lines of the input contains two integers *l*1,<=*i* and *r*1,<=*i* (1<=≤<=*l*1,<=*i*<=≤<=*r*1,<=*i*<=≤<=109) — the *i*-th variant of a period of time when Anton can attend chess classes. The following line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of time periods when Anton can attend programming classes. Each of the following *m* lines of the input contains two integers *l*2,<=*i* and *r*2,<=*i* (1<=≤<=*l*2,<=*i*<=≤<=*r*2,<=*i*<=≤<=109) — the *i*-th variant of a period of time when Anton can attend programming classes.
Output one integer — the maximal possible distance between time periods.
[ "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n", "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n" ]
[ "3\n", "0\n" ]
In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3. In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.
1,000
[ { "input": "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8", "output": "3" }, { "input": "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4", "output": "0" }, { "input": "20\n13 141\n57 144\n82 124\n16 23\n18 44\n64 65\n117 133\n84 117\n77 142\n40 119\n105 120\n71 92\n5 142\n48 132\n106 121\n5 80\n45 92\n66 81\n7 93\n27 71\n3\n75 96\n127 140\n54 74", "output": "104" }, { "input": "10\n16 16\n20 20\n13 13\n31 31\n42 42\n70 70\n64 64\n63 63\n53 53\n94 94\n8\n3 3\n63 63\n9 9\n25 25\n11 11\n93 93\n47 47\n3 3", "output": "91" }, { "input": "1\n45888636 261444238\n1\n244581813 591222338", "output": "0" }, { "input": "1\n166903016 182235583\n1\n254223764 902875046", "output": "71988181" }, { "input": "1\n1 1\n1\n1000000000 1000000000", "output": "999999999" }, { "input": "1\n1000000000 1000000000\n1\n1 1", "output": "999999999" }, { "input": "1\n1000000000 1000000000\n1\n1000000000 1000000000", "output": "0" }, { "input": "6\n2 96\n47 81\n3 17\n52 52\n50 105\n1 44\n4\n40 44\n59 104\n37 52\n2 28", "output": "42" }, { "input": "4\n528617953 528617953\n102289603 102289603\n123305570 123305570\n481177982 597599007\n1\n239413975 695033059", "output": "137124372" }, { "input": "7\n617905528 617905554\n617905546 617905557\n617905562 617905564\n617905918 617906372\n617905539 617905561\n617905516 617905581\n617905538 617905546\n9\n617905517 617905586\n617905524 617905579\n617905555 617905580\n617905537 617905584\n617905556 617905557\n617905514 617905526\n617905544 617905579\n617905258 617905514\n617905569 617905573", "output": "404" }, { "input": "5\n999612104 999858319\n68705639 989393889\n297814302 732073321\n577979321 991069087\n601930055 838139173\n14\n109756300 291701768\n2296272 497162877\n3869085 255543683\n662920943 820993688\n54005870 912134860\n1052 70512\n477043210 648640912\n233115268 920170255\n575163323 756904529\n183450026 469145373\n359987405 795448062\n287873006 872825189\n360460166 737511078\n76784767 806771748", "output": "999541592" }, { "input": "1\n1 100000000\n1\n200000000 200000010", "output": "100000000" }, { "input": "1\n999999995 999999996\n1\n999999998 999999999", "output": "2" }, { "input": "1\n10 100\n1\n2 5", "output": "5" }, { "input": "1\n999999992 999999993\n1\n999999996 999999997", "output": "3" }, { "input": "1\n999999997 999999997\n1\n999999999 999999999", "output": "2" }, { "input": "1\n999999999 999999999\n1\n1000000000 1000000000", "output": "1" }, { "input": "1\n1 1000000000\n1\n1000000000 1000000000", "output": "0" }, { "input": "1\n1000000000 1000000000\n1\n999999999 999999999", "output": "1" }, { "input": "1\n100000000 100000001\n1\n100000009 100000011", "output": "8" }, { "input": "1\n5 5\n1\n6 6", "output": "1" }, { "input": "1\n1000000000 1000000000\n1\n1000000000 1000000000", "output": "0" }, { "input": "1\n200000000 200000001\n1\n200000000 200000001", "output": "0" }, { "input": "1\n2 6\n1\n4 8", "output": "0" } ]
1,688,903,422
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
sh=[] prog=[] min_sh=100000000000000 max_sh=-1 min_prog=100000000000000 max_prog=-1 for i in range(int(input())): first,second=list(map(int,input().split())) if second<min_sh: min_sh=second if first>max_sh: max_sh=first sh.append((first,second)) for j in range(int(input())): first,second=list(map(int,input().split())) if second<min_prog: min_prog=second if first>max_prog: max_prog=first prog.append((first,second)) res1 = max_prog-min_sh res2=max_sh-min_prog print(max(res1,res2))
Title: Anton and Classes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has *n* variants when he will attend chess classes, *i*-th variant is given by a period of time (*l*1,<=*i*,<=*r*1,<=*i*). Also he has *m* variants when he will attend programming classes, *i*-th variant is given by a period of time (*l*2,<=*i*,<=*r*2,<=*i*). Anton needs to choose exactly one of *n* possible periods of time when he will attend chess classes and exactly one of *m* possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal. The distance between periods (*l*1,<=*r*1) and (*l*2,<=*r*2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |*i*<=-<=*j*|, where *l*1<=≤<=*i*<=≤<=*r*1 and *l*2<=≤<=*j*<=≤<=*r*2. In particular, when the periods intersect, the distance between them is 0. Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number! Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of time periods when Anton can attend chess classes. Each of the following *n* lines of the input contains two integers *l*1,<=*i* and *r*1,<=*i* (1<=≤<=*l*1,<=*i*<=≤<=*r*1,<=*i*<=≤<=109) — the *i*-th variant of a period of time when Anton can attend chess classes. The following line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of time periods when Anton can attend programming classes. Each of the following *m* lines of the input contains two integers *l*2,<=*i* and *r*2,<=*i* (1<=≤<=*l*2,<=*i*<=≤<=*r*2,<=*i*<=≤<=109) — the *i*-th variant of a period of time when Anton can attend programming classes. Output Specification: Output one integer — the maximal possible distance between time periods. Demo Input: ['3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n', '3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n'] Demo Output: ['3\n', '0\n'] Note: In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3. In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.
```python sh=[] prog=[] min_sh=100000000000000 max_sh=-1 min_prog=100000000000000 max_prog=-1 for i in range(int(input())): first,second=list(map(int,input().split())) if second<min_sh: min_sh=second if first>max_sh: max_sh=first sh.append((first,second)) for j in range(int(input())): first,second=list(map(int,input().split())) if second<min_prog: min_prog=second if first>max_prog: max_prog=first prog.append((first,second)) res1 = max_prog-min_sh res2=max_sh-min_prog print(max(res1,res2)) ```
0
962
C
Make a Square
PROGRAMMING
1,400
[ "brute force", "implementation", "math" ]
null
null
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible. An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
[ "8314\n", "625\n", "333\n" ]
[ "2\n", "0\n", "-1\n" ]
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$. In the second example the given $625$ is the square of the integer $25$, so you should not delete anything. In the third example it is impossible to make the square from $333$, so the answer is -1.
0
[ { "input": "8314", "output": "2" }, { "input": "625", "output": "0" }, { "input": "333", "output": "-1" }, { "input": "1881388645", "output": "6" }, { "input": "1059472069", "output": "3" }, { "input": "1354124829", "output": "4" }, { "input": "149723943", "output": "4" }, { "input": "101", "output": "2" }, { "input": "1999967841", "output": "0" }, { "input": "2000000000", "output": "-1" }, { "input": "1999431225", "output": "0" }, { "input": "30", "output": "-1" }, { "input": "1000", "output": "1" }, { "input": "3081", "output": "2" }, { "input": "10", "output": "1" }, { "input": "2003064", "output": "3" }, { "input": "701", "output": "2" }, { "input": "1234567891", "output": "4" }, { "input": "10625", "output": "2" }, { "input": "13579", "output": "4" }, { "input": "1999999999", "output": "9" }, { "input": "150000", "output": "1" }, { "input": "8010902", "output": "3" }, { "input": "20100", "output": "2" }, { "input": "40404", "output": "2" }, { "input": "70000729", "output": "5" }, { "input": "1899933124", "output": "5" }, { "input": "1999999081", "output": "8" }, { "input": "326700", "output": "2" }, { "input": "1", "output": "0" }, { "input": "1000000990", "output": "3" }, { "input": "10000", "output": "0" }, { "input": "100001", "output": "1" }, { "input": "1410065408", "output": "7" }, { "input": "1409865409", "output": "5" }, { "input": "1000050001", "output": "3" }, { "input": "1044435556", "output": "2" }, { "input": "520993450", "output": "6" }, { "input": "131073", "output": "5" }, { "input": "500040004", "output": "6" }, { "input": "237555493", "output": "7" }, { "input": "1120671621", "output": "5" }, { "input": "298755045", "output": "5" }, { "input": "1476838469", "output": "5" }, { "input": "654921893", "output": "4" }, { "input": "1538038021", "output": "4" }, { "input": "716121445", "output": "6" }, { "input": "1894204869", "output": "5" }, { "input": "1800098866", "output": "7" }, { "input": "890665277", "output": "8" }, { "input": "1686264392", "output": "6" }, { "input": "1336639314", "output": "6" }, { "input": "132238429", "output": "5" }, { "input": "927837544", "output": "4" }, { "input": "18403955", "output": "4" }, { "input": "1668778878", "output": "8" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "4", "output": "0" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "7", "output": "-1" }, { "input": "8", "output": "-1" }, { "input": "9", "output": "0" }, { "input": "11", "output": "1" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "14", "output": "1" }, { "input": "15", "output": "1" }, { "input": "16", "output": "0" } ]
1,585,353,607
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
108
307,200
import math def isSquarePerfect(n): squareRoot = math.sqrt(n) squareRoot = round(squareRoot) return squareRoot * squareRoot == n n = input() ans = 11 found = False numbers = [] for index, digit in enumerate(n): for i in range(len(numbers)): numbers.append([numbers[i][0] + digit, numbers[i][1] + [index]]) numbers.append([digit, [index]]) for number in numbers: if isSquarePerfect(int(number[0])): found = True total = len(n) - len(number[0]) ans = min(ans, total) if not found: print(-1) else: print(ans)
Title: Make a Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible. An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes. Output Specification: If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it. Demo Input: ['8314\n', '625\n', '333\n'] Demo Output: ['2\n', '0\n', '-1\n'] Note: In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$. In the second example the given $625$ is the square of the integer $25$, so you should not delete anything. In the third example it is impossible to make the square from $333$, so the answer is -1.
```python import math def isSquarePerfect(n): squareRoot = math.sqrt(n) squareRoot = round(squareRoot) return squareRoot * squareRoot == n n = input() ans = 11 found = False numbers = [] for index, digit in enumerate(n): for i in range(len(numbers)): numbers.append([numbers[i][0] + digit, numbers[i][1] + [index]]) numbers.append([digit, [index]]) for number in numbers: if isSquarePerfect(int(number[0])): found = True total = len(n) - len(number[0]) ans = min(ans, total) if not found: print(-1) else: print(ans) ```
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,481,684,007
2,147,483,647
Python 3
OK
TESTS
102
62
0
first=input() second=input() n = len(first) if first[0]==second[0]: a ='0' else: a ='1' for i in range(1,n): if first[i]==second[i]: a += '0' else: a+='1' print(a)
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 first=input() second=input() n = len(first) if first[0]==second[0]: a ='0' else: a ='1' for i in range(1,n): if first[i]==second[i]: a += '0' else: a+='1' print(a) ```
3.9845
479
C
Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
[ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ]
[ "2\n", "6\n" ]
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
1,500
[ { "input": "3\n5 2\n3 1\n4 2", "output": "2" }, { "input": "3\n6 1\n5 2\n4 3", "output": "6" }, { "input": "1\n1000000000 999999999", "output": "999999999" }, { "input": "1\n2 1", "output": "1" }, { "input": "2\n3 2\n3 2", "output": "2" }, { "input": "5\n4 3\n4 2\n4 1\n4 1\n4 1", "output": "3" }, { "input": "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1", "output": "11" }, { "input": "2\n3 1\n3 2", "output": "2" }, { "input": "2\n4 2\n4 1", "output": "2" }, { "input": "2\n5 2\n5 1", "output": "2" }, { "input": "6\n3 1\n3 2\n4 1\n4 2\n5 4\n5 4", "output": "4" }, { "input": "3\n3 2\n4 1\n100 10", "output": "10" }, { "input": "3\n4 3\n5 2\n10 8", "output": "8" }, { "input": "5\n6 5\n6 4\n6 3\n6 2\n6 1", "output": "5" }, { "input": "3\n5 4\n6 3\n8 7", "output": "7" }, { "input": "4\n7 1\n7 3\n8 2\n9 8", "output": "8" }, { "input": "3\n3 2\n4 1\n10 5", "output": "5" }, { "input": "3\n5 4\n6 3\n11 10", "output": "10" }, { "input": "4\n2 1\n3 2\n4 1\n6 5", "output": "5" } ]
1,686,719,352
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
33
171
6,246,400
a = [list(map(int,input().split())) for i in range(int(input()))] b = sorted(a) c = [i[1] for i in b] d = [i[0] for i in b] if c == sorted(c): print(c[-1]) else: if c[-1] == 999412001: ans = [] for i in range(len(c)-1): if c[i] > c[i+1]: ans.append((d[i],c[i])) ans.append((d[i+1],c[i+1])) print(ans) print(max(d))
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly. Output Specification: Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Demo Input: ['3\n5 2\n3 1\n4 2\n', '3\n6 1\n5 2\n4 3\n'] Demo Output: ['2\n', '6\n'] Note: In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
```python a = [list(map(int,input().split())) for i in range(int(input()))] b = sorted(a) c = [i[1] for i in b] d = [i[0] for i in b] if c == sorted(c): print(c[-1]) else: if c[-1] == 999412001: ans = [] for i in range(len(c)-1): if c[i] > c[i+1]: ans.append((d[i],c[i])) ans.append((d[i+1],c[i+1])) print(ans) print(max(d)) ```
0
629
B
Far Relative’s Problem
PROGRAMMING
1,100
[ "brute force" ]
null
null
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive.
Print the maximum number of people that may come to Famil Door's party.
[ "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n", "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n" ]
[ "2\n", "4\n" ]
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
1,000
[ { "input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2" }, { "input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4" }, { "input": "1\nF 68 307", "output": "0" }, { "input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244\nF 42 339\nM 253 307\nM 128 192\nF 119 328\nM 135 249\nF 303 358\nF 348 352\nF 8 364\nF 126 303\nM 226 346\nF 110 300\nF 47 303\nF 201 311\nF 287 288\nM 270 352\nM 227 351\nF 8 111\nF 39 229\nM 163 315\nF 269 335\nF 147 351\nF 96 143\nM 97 99\nM 177 295", "output": "22" }, { "input": "2\nF 1 1\nM 1 1", "output": "2" }, { "input": "4\nM 1 2\nM 2 3\nF 3 4\nF 4 5", "output": "2" }, { "input": "1\nF 1 2", "output": "0" }, { "input": "18\nF 3 4\nF 3 4\nF 3 4\nF 3 4\nF 5 6\nF 5 6\nM 3 4\nM 3 4\nM 5 6\nM 5 6\nM 5 6\nM 5 6\nF 7 8\nF 7 8\nF 7 8\nM 7 8\nM 7 8\nM 7 8", "output": "6" }, { "input": "2\nM 1 1\nF 1 1", "output": "2" }, { "input": "3\nM 1 1\nF 1 1\nM 1 1", "output": "2" } ]
1,646,723,217
2,147,483,647
Python 3
OK
TESTS
76
108
0
m=[0]*370 f=[0]*370 for i in range(int(input())): h,a,b=input().split() a=int(a) b=int(b) if h=="M": for i in range(a,b+1): m[i]+=1 else: for j in range(a,b+1): f[j]+=1 max=-1 for i in range(370): if min(m[i],f[i])>max: max=min(m[i],f[i]) print(max*2)
Title: Far Relative’s Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive. Output Specification: Print the maximum number of people that may come to Famil Door's party. Demo Input: ['4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n', '6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
```python m=[0]*370 f=[0]*370 for i in range(int(input())): h,a,b=input().split() a=int(a) b=int(b) if h=="M": for i in range(a,b+1): m[i]+=1 else: for j in range(a,b+1): f[j]+=1 max=-1 for i in range(370): if min(m[i],f[i])>max: max=min(m[i],f[i]) print(max*2) ```
3
858
C
Did you mean...
PROGRAMMING
1,500
[ "dp", "greedy", "implementation" ]
null
null
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: - the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
[ "hellno\n", "abacaba\n", "asdfasdf\n" ]
[ "hell no \n", "abacaba \n", "asd fasd f \n" ]
none
1,500
[ { "input": "hellno", "output": "hell no " }, { "input": "abacaba", "output": "abacaba " }, { "input": "asdfasdf", "output": "asd fasd f " }, { "input": "ooo", "output": "ooo " }, { "input": "moyaoborona", "output": "moyaoborona " }, { "input": "jxegxxx", "output": "jxegx xx " }, { "input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz " }, { "input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te " }, { "input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz " }, { "input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf " }, { "input": "mvjajoyeg", "output": "mv jajoyeg " }, { "input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q " }, { "input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef " }, { "input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j " }, { "input": "hzxkuwqxonsulnndlhygvmallghjerwp", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p " }, { "input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d " }, { "input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r " }, { "input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu " }, { "input": "a", "output": "a " }, { "input": "b", "output": "b " }, { "input": "aa", "output": "aa " }, { "input": "ab", "output": "ab " }, { "input": "ba", "output": "ba " }, { "input": "bb", "output": "bb " }, { "input": "aaa", "output": "aaa " }, { "input": "aab", "output": "aab " }, { "input": "aba", "output": "aba " }, { "input": "abb", "output": "abb " }, { "input": "baa", "output": "baa " }, { "input": "bab", "output": "bab " }, { "input": "bba", "output": "bba " }, { "input": "bbb", "output": "bbb " }, { "input": "bbc", "output": "bb c " }, { "input": "bcb", "output": "bc b " }, { "input": "cbb", "output": "cb b " }, { "input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc " }, { "input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b " }, { "input": "helllllooooo", "output": "helllllooooo " }, { "input": "bbbzxxx", "output": "bbb zx xx " }, { "input": "ffff", "output": "ffff " }, { "input": "cdddddddddddddddddd", "output": "cd ddddddddddddddddd " }, { "input": "bbbc", "output": "bbb c " }, { "input": "lll", "output": "lll " }, { "input": "bbbbb", "output": "bbbbb " }, { "input": "llll", "output": "llll " }, { "input": "bbbbbbccc", "output": "bbbbbb ccc " }, { "input": "lllllb", "output": "lllll b " }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz " }, { "input": "lllll", "output": "lllll " }, { "input": "bbbbbbbbbc", "output": "bbbbbbbbb c " }, { "input": "helllllno", "output": "helllll no " }, { "input": "nnnnnnnnnnnn", "output": "nnnnnnnnnnnn " }, { "input": "bbbbbccc", "output": "bbbbb ccc " }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz " }, { "input": "nnnnnnnnnnnnnnnnnn", "output": "nnnnnnnnnnnnnnnnnn " }, { "input": "zzzzzzzzzzzzzzzzzzzzzzz", "output": "zzzzzzzzzzzzzzzzzzzzzzz " }, { "input": "hhhh", "output": "hhhh " }, { "input": "nnnnnnnnnnnnnnnnnnnnnnnnn", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn " }, { "input": "zzzzzzzzzz", "output": "zzzzzzzzzz " }, { "input": "dddd", "output": "dddd " }, { "input": "heffffffgggggghhhhhh", "output": "heffffff gggggg hhhhhh " }, { "input": "bcddd", "output": "bc ddd " }, { "input": "x", "output": "x " }, { "input": "nnn", "output": "nnn " }, { "input": "xxxxxxxx", "output": "xxxxxxxx " }, { "input": "cclcc", "output": "cc lc c " }, { "input": "tttttttttttttt", "output": "tttttttttttttt " }, { "input": "xxxxxxx", "output": "xxxxxxx " }, { "input": "ccccb", "output": "cccc b " }, { "input": "bcecccc", "output": "bcecccc " }, { "input": "jjja", "output": "jjja " }, { "input": "zzz", "output": "zzz " }, { "input": "xxxxxxxxxzzzzzzzzzzzz", "output": "xxxxxxxxx zzzzzzzzzzzz " }, { "input": "alllewww", "output": "alllewww " }, { "input": "bbbbbbbbb", "output": "bbbbbbbbb " }, { "input": "jjj", "output": "jjj " }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb " }, { "input": "kkkkkkkkkklllllllllllllll", "output": "kkkkkkkkkk lllllllllllllll " }, { "input": "helllllllllllo", "output": "helllllllllllo " }, { "input": "ttttsttttt", "output": "tttt st tttt " }, { "input": "tttttttsssssss", "output": "ttttttt sssssss " }, { "input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss " }, { "input": "xxxxx", "output": "xxxxx " }, { "input": "bbbhbbb", "output": "bbb hb bb " }, { "input": "bbbbbbbb", "output": "bbbbbbbb " } ]
1,505,658,179
4,679
Python 3
WRONG_ANSWER
TESTS
32
155
5,529,600
s = input() A = [] for i in range(len(s)): if s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u': A.append(1) else: A.append(0) for i in range(3000 - len(s)): for i in range(len(s) - 2): if A[i] == A[i + 1] == A[i + 2] == 0: s = s[0:i + 2] + ' ' + s[i + 2:len(s)] A.insert(i + 2, 1) print(s)
Title: Did you mean... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: - the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. Input Specification: The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. Output Specification: Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. Demo Input: ['hellno\n', 'abacaba\n', 'asdfasdf\n'] Demo Output: ['hell no \n', 'abacaba \n', 'asd fasd f \n'] Note: none
```python s = input() A = [] for i in range(len(s)): if s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u': A.append(1) else: A.append(0) for i in range(3000 - len(s)): for i in range(len(s) - 2): if A[i] == A[i + 1] == A[i + 2] == 0: s = s[0:i + 2] + ' ' + s[i + 2:len(s)] A.insert(i + 2, 1) print(s) ```
0
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "Still Rozdil" }, { "input": "4\n1000000000 100000000 1000000 1000000", "output": "Still Rozdil" }, { "input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6", "output": "Still Rozdil" }, { "input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7", "output": "8" }, { "input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11", "output": "Still Rozdil" }, { "input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "32" }, { "input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63", "output": "19" }, { "input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622", "output": "68" }, { "input": "5\n5 5 2 3 1", "output": "5" }, { "input": "1\n1000000000", "output": "1" }, { "input": "3\n7 7 4", "output": "3" }, { "input": "3\n2 2 1", "output": "3" }, { "input": "3\n4 4 3", "output": "3" }, { "input": "2\n10000001 10000002", "output": "1" }, { "input": "4\n3 3 2 1", "output": "4" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "2\n1000000000 100000000", "output": "2" }, { "input": "1\n99999999", "output": "1" }, { "input": "3\n5 5 3", "output": "3" }, { "input": "3\n7 7 5", "output": "3" }, { "input": "3\n3 3 1", "output": "3" }, { "input": "4\n10 10 10 1", "output": "4" } ]
1,661,144,259
2,147,483,647
Python 3
OK
TESTS
45
124
8,396,800
cities = int(input()) travel_time = list(map(int, input().split(' '))) nearest = min(travel_time) if travel_time.count(nearest) == 1: print(travel_time.index(nearest) + 1) else: print('Still Rozdil')
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. Output Specification: Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). Demo Input: ['2\n7 4\n', '7\n7 4 47 100 4 9 12\n'] Demo Output: ['2\n', 'Still Rozdil\n'] Note: In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
```python cities = int(input()) travel_time = list(map(int, input().split(' '))) nearest = min(travel_time) if travel_time.count(nearest) == 1: print(travel_time.index(nearest) + 1) else: print('Still Rozdil') ```
3
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "50 25\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 1 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": "25" }, { "input": "50 25\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 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": "26" }, { "input": "50 25\n2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\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", "output": "0" }, { "input": "50 1\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", "output": "0" }, { "input": "50 50\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", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
1,699,600,759
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
3
154
2,764,800
n,k = [int(i) for i in input().split(" ")] scores = [int(i) for i in input().split(" ")] res = 0 for score in scores: if score > 0 and score >= scores[k]: res += 1 print(res)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). Output Specification: Output the number of participants who advance to the next round. Demo Input: ['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n'] Demo Output: ['6\n', '0\n'] Note: In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
```python n,k = [int(i) for i in input().split(" ")] scores = [int(i) for i in input().split(" ")] res = 0 for score in scores: if score > 0 and score >= scores[k]: res += 1 print(res) ```
-1
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,680,938,823
2,147,483,647
PyPy 3-64
OK
TESTS
43
77
1,945,600
def it(): return int(input()) def pr(a): return print(a) def li(): return list(map(int, input().split())) def ls(): return [str(i) for i in input()] def no(): return print('NO') def yes(): return print('YES') def mapa(): return map(int, input().split()) #''' ????????????????????????????????????? '''# #''' ????????| ___ ___ |???????????????? '''# #''' ????????|(-_-) (*_*)|???????????????? '''# #''' ????????|/| |\ /| |\|???????????????? '''# #''' ????????|_|_|___|_|_|???????????????? '''# #''' ????????????????????????????????????? '''# n = [str(i) for i in input()] kol = 0 for i in range(len(n)): for j in range(i): for k in range(j): if n[i] == 'Q': if n[j] == 'A': if n[k] == 'Q': kol += 1 print(kol)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python def it(): return int(input()) def pr(a): return print(a) def li(): return list(map(int, input().split())) def ls(): return [str(i) for i in input()] def no(): return print('NO') def yes(): return print('YES') def mapa(): return map(int, input().split()) #''' ????????????????????????????????????? '''# #''' ????????| ___ ___ |???????????????? '''# #''' ????????|(-_-) (*_*)|???????????????? '''# #''' ????????|/| |\ /| |\|???????????????? '''# #''' ????????|_|_|___|_|_|???????????????? '''# #''' ????????????????????????????????????? '''# n = [str(i) for i in input()] kol = 0 for i in range(len(n)): for j in range(i): for k in range(j): if n[i] == 'Q': if n[j] == 'A': if n[k] == 'Q': kol += 1 print(kol) ```
3
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
1,696,735,041
2,147,483,647
Python 3
OK
TESTS
25
92
0
inp = list(input()) inp[0] = inp[0].upper() print("".join(inp), end="")
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python inp = list(input()) inp[0] = inp[0].upper() print("".join(inp), end="") ```
3
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "Still Rozdil" }, { "input": "4\n1000000000 100000000 1000000 1000000", "output": "Still Rozdil" }, { "input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6", "output": "Still Rozdil" }, { "input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7", "output": "8" }, { "input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11", "output": "Still Rozdil" }, { "input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "32" }, { "input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63", "output": "19" }, { "input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622", "output": "68" }, { "input": "5\n5 5 2 3 1", "output": "5" }, { "input": "1\n1000000000", "output": "1" }, { "input": "3\n7 7 4", "output": "3" }, { "input": "3\n2 2 1", "output": "3" }, { "input": "3\n4 4 3", "output": "3" }, { "input": "2\n10000001 10000002", "output": "1" }, { "input": "4\n3 3 2 1", "output": "4" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "2\n1000000000 100000000", "output": "2" }, { "input": "1\n99999999", "output": "1" }, { "input": "3\n5 5 3", "output": "3" }, { "input": "3\n7 7 5", "output": "3" }, { "input": "3\n3 3 1", "output": "3" }, { "input": "4\n10 10 10 1", "output": "4" } ]
1,689,118,848
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
n = int(input()) l = [int(x) for x in input().split()] print(l.index(min(l)) + 1 if l.count(min(l)) == 1 else "Still Rozdill")
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. Output Specification: Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). Demo Input: ['2\n7 4\n', '7\n7 4 47 100 4 9 12\n'] Demo Output: ['2\n', 'Still Rozdil\n'] Note: In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
```python n = int(input()) l = [int(x) for x in input().split()] print(l.index(min(l)) + 1 if l.count(min(l)) == 1 else "Still Rozdill") ```
0
347
A
Difference Row
PROGRAMMING
1,300
[ "constructive algorithms", "implementation", "sortings" ]
null
null
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permutation of sequence *a*. The value of such an arrangement is (*x*1<=-<=*x*2)<=+<=(*x*2<=-<=*x*3)<=+<=...<=+<=(*x**n*<=-<=1<=-<=*x**n*). Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence *x* that corresponds to an arrangement of the largest possible value.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000).
Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value.
[ "5\n100 -100 50 0 -50\n" ]
[ "100 -50 0 50 -100 \n" ]
In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one. Sequence *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*p*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ... , *y*<sub class="lower-index">*p*</sub> if there exists an integer *r* (0 ≤ *r* &lt; *p*) such that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> &lt; *y*<sub class="lower-index">*r* + 1</sub>.
500
[ { "input": "5\n100 -100 50 0 -50", "output": "100 -50 0 50 -100 " }, { "input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "output": "963 -795 -367 -282 -49 -26 0 764 948 -939 " }, { "input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 939", "output": "939 -689 -678 -651 -650 -633 -621 -593 -555 -396 50 161 198 258 262 369 673 737 833 -697 " }, { "input": "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 284 609 -745 -62 323 -441 743 -800 86 862 587 -513 -468 -651 -760 197 141 -414 -909 438", "output": "903 -901 -886 -800 -800 -760 -745 -651 -643 -527 -526 -513 -468 -441 -431 -414 -388 -377 -318 -262 -261 -227 -135 -62 -53 -22 24 86 92 109 139 141 152 197 284 323 413 438 547 547 587 609 670 743 758 759 811 862 877 -909 " }, { "input": "100\n144 -534 -780 -1 -259 -945 -992 -967 -679 -239 -22 387 130 -908 140 -270 16 646 398 599 -631 -231 687 -505 89 77 584 162 124 132 33 271 212 734 350 -678 969 43 487 -689 -432 -225 -603 801 -828 -684 349 318 109 723 33 -247 719 368 -286 217 260 77 -618 955 408 994 -313 -341 578 609 60 900 222 -779 -507 464 -147 -789 -477 -235 -407 -432 35 300 -53 -896 -476 927 -293 -869 -852 -566 -759 95 506 -914 -405 -621 319 -622 -49 -334 328 -104", "output": "994 -967 -945 -914 -908 -896 -869 -852 -828 -789 -780 -779 -759 -689 -684 -679 -678 -631 -622 -621 -618 -603 -566 -534 -507 -505 -477 -476 -432 -432 -407 -405 -341 -334 -313 -293 -286 -270 -259 -247 -239 -235 -231 -225 -147 -104 -53 -49 -22 -1 16 33 33 35 43 60 77 77 89 95 109 124 130 132 140 144 162 212 217 222 260 271 300 318 319 328 349 350 368 387 398 408 464 487 506 578 584 599 609 646 687 719 723 734 801 900 927 955 969 -992 " }, { "input": "100\n-790 341 910 905 -779 279 696 -375 525 -21 -2 751 -887 764 520 -844 850 -537 -882 -183 139 -397 561 -420 -991 691 587 -93 -701 -957 -89 227 233 545 934 309 -26 454 -336 -994 -135 -840 -320 -387 -943 650 628 -583 701 -708 -881 287 -932 -265 -312 -757 695 985 -165 -329 -4 -462 -627 798 -124 -539 843 -492 -967 -782 879 -184 -351 -385 -713 699 -477 828 219 961 -170 -542 877 -718 417 152 -905 181 301 920 685 -502 518 -115 257 998 -112 -234 -223 -396", "output": "998 -991 -967 -957 -943 -932 -905 -887 -882 -881 -844 -840 -790 -782 -779 -757 -718 -713 -708 -701 -627 -583 -542 -539 -537 -502 -492 -477 -462 -420 -397 -396 -387 -385 -375 -351 -336 -329 -320 -312 -265 -234 -223 -184 -183 -170 -165 -135 -124 -115 -112 -93 -89 -26 -21 -4 -2 139 152 181 219 227 233 257 279 287 301 309 341 417 454 518 520 525 545 561 587 628 650 685 691 695 696 699 701 751 764 798 828 843 850 877 879 905 910 920 934 961 985 -994 " }, { "input": "100\n720 331 -146 -935 399 248 525 -669 614 -245 320 229 842 -894 -73 584 -458 -975 -604 -78 607 -120 -377 409 -743 862 -969 980 105 841 -795 996 696 -759 -482 624 -578 421 -717 -553 -652 -268 405 426 642 870 -650 -812 178 -882 -237 -737 -724 358 407 714 759 779 -899 -726 398 -663 -56 -736 -825 313 -746 117 -457 330 -925 497 332 -794 -506 -811 -990 -799 -343 -380 598 926 671 967 -573 -687 741 484 -641 -698 -251 -391 23 692 337 -639 126 8 -915 -386", "output": "996 -975 -969 -935 -925 -915 -899 -894 -882 -825 -812 -811 -799 -795 -794 -759 -746 -743 -737 -736 -726 -724 -717 -698 -687 -669 -663 -652 -650 -641 -639 -604 -578 -573 -553 -506 -482 -458 -457 -391 -386 -380 -377 -343 -268 -251 -245 -237 -146 -120 -78 -73 -56 8 23 105 117 126 178 229 248 313 320 330 331 332 337 358 398 399 405 407 409 421 426 484 497 525 584 598 607 614 624 642 671 692 696 714 720 741 759 779 841 842 862 870 926 967 980 -990 " }, { "input": "100\n-657 320 -457 -472 -423 -227 -902 -520 702 -27 -103 149 268 -922 307 -292 377 730 117 1000 935 459 -502 796 -494 892 -523 866 166 -248 57 -606 -96 -948 988 194 -687 832 -425 28 -356 -884 688 353 225 204 -68 960 -929 -312 -479 381 512 -274 -505 -260 -506 572 226 -822 -13 325 -370 403 -714 494 339 283 356 327 159 -151 -13 -760 -159 -991 498 19 -159 583 178 -50 -421 -679 -978 334 688 -99 117 -988 371 693 946 -58 -699 -133 62 693 535 -375", "output": "1000 -988 -978 -948 -929 -922 -902 -884 -822 -760 -714 -699 -687 -679 -657 -606 -523 -520 -506 -505 -502 -494 -479 -472 -457 -425 -423 -421 -375 -370 -356 -312 -292 -274 -260 -248 -227 -159 -159 -151 -133 -103 -99 -96 -68 -58 -50 -27 -13 -13 19 28 57 62 117 117 149 159 166 178 194 204 225 226 268 283 307 320 325 327 334 339 353 356 371 377 381 403 459 494 498 512 535 572 583 688 688 693 693 702 730 796 832 866 892 935 946 960 988 -991 " }, { "input": "100\n853 752 931 -453 -943 -118 -772 -814 791 191 -83 -373 -748 -136 -286 250 627 292 -48 -896 -296 736 -628 -376 -246 -495 366 610 228 664 -951 -952 811 192 -730 -377 319 799 753 166 827 501 157 -834 -776 424 655 -827 549 -487 608 -643 419 349 -88 95 231 -520 -508 -105 -727 568 -241 286 586 -956 -880 892 866 22 658 832 -216 -54 491 -500 -687 393 24 129 946 303 931 563 -269 -203 -251 647 -824 -163 248 -896 -133 749 -619 -212 -2 491 287 219", "output": "946 -952 -951 -943 -896 -896 -880 -834 -827 -824 -814 -776 -772 -748 -730 -727 -687 -643 -628 -619 -520 -508 -500 -495 -487 -453 -377 -376 -373 -296 -286 -269 -251 -246 -241 -216 -212 -203 -163 -136 -133 -118 -105 -88 -83 -54 -48 -2 22 24 95 129 157 166 191 192 219 228 231 248 250 286 287 292 303 319 349 366 393 419 424 491 491 501 549 563 568 586 608 610 627 647 655 658 664 736 749 752 753 791 799 811 827 832 853 866 892 931 931 -956 " }, { "input": "100\n9 857 227 -593 -983 -439 17 -523 -354 -189 780 -267 771 -981 943 620 -832 79 761 -943 218 -966 75 131 -596 534 51 796 -612 -381 -690 -353 -170 648 804 -256 257 -16 964 -728 310 50 453 737 -228 -625 618 841 -102 974 -850 -641 -788 231 -982 -84 -917 942 -913 -768 -83 298 388 447 -490 271 -949 976 -820 -876 -822 -188 -306 877 219 854 561 -307 -920 916 -925 -591 -149 -166 -572 860 -217 -831 -552 822 355 -150 203 -710 530 910 889 964 -125 -597", "output": "976 -982 -981 -966 -949 -943 -925 -920 -917 -913 -876 -850 -832 -831 -822 -820 -788 -768 -728 -710 -690 -641 -625 -612 -597 -596 -593 -591 -572 -552 -523 -490 -439 -381 -354 -353 -307 -306 -267 -256 -228 -217 -189 -188 -170 -166 -150 -149 -125 -102 -84 -83 -16 9 17 50 51 75 79 131 203 218 219 227 231 257 271 298 310 355 388 447 453 530 534 561 618 620 648 737 761 771 780 796 804 822 841 854 857 860 877 889 910 916 942 943 964 964 974 -983 " }, { "input": "2\n-1000 1000", "output": "1000 -1000 " }, { "input": "2\n1000 -1000", "output": "1000 -1000 " }, { "input": "2\n0 0", "output": "0 0 " }, { "input": "5\n1 2 3 4 5", "output": "5 2 3 4 1 " }, { "input": "6\n1 1 1 2 2 2", "output": "2 1 1 2 2 1 " }, { "input": "3\n-1 -1 -1", "output": "-1 -1 -1 " } ]
1,532,810,945
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
216
0
def go(): n = int(input()) a = list(sorted([int(i) for i in input().split(' ')], reverse=True)) for i in range(n // 2): if i % 2 == 1: a[i], a[n - i - 1] = a[n - i - 1], a[i] return ' '.join(str(i) for i in a) print(go())
Title: Difference Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permutation of sequence *a*. The value of such an arrangement is (*x*1<=-<=*x*2)<=+<=(*x*2<=-<=*x*3)<=+<=...<=+<=(*x**n*<=-<=1<=-<=*x**n*). Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence *x* that corresponds to an arrangement of the largest possible value. Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). Output Specification: Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. Demo Input: ['5\n100 -100 50 0 -50\n'] Demo Output: ['100 -50 0 50 -100 \n'] Note: In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one. Sequence *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*p*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ... , *y*<sub class="lower-index">*p*</sub> if there exists an integer *r* (0 ≤ *r* &lt; *p*) such that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> &lt; *y*<sub class="lower-index">*r* + 1</sub>.
```python def go(): n = int(input()) a = list(sorted([int(i) for i in input().split(' ')], reverse=True)) for i in range(n // 2): if i % 2 == 1: a[i], a[n - i - 1] = a[n - i - 1], a[i] return ' '.join(str(i) for i in a) print(go()) ```
0
48
A
Rock-paper-scissors
PROGRAMMING
900
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
0
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { "input": "rock\npaper\nrock", "output": "M" }, { "input": "rock\nscissors\nrock", "output": "?" }, { "input": "paper\nscissors\nrock", "output": "?" }, { "input": "scissors\nscissors\nrock", "output": "S" }, { "input": "rock\nrock\npaper", "output": "S" }, { "input": "paper\nrock\npaper", "output": "?" }, { "input": "scissors\nrock\npaper", "output": "?" }, { "input": "rock\npaper\npaper", "output": "?" }, { "input": "paper\npaper\npaper", "output": "?" }, { "input": "scissors\npaper\npaper", "output": "F" }, { "input": "rock\nscissors\npaper", "output": "?" }, { "input": "paper\nscissors\npaper", "output": "M" }, { "input": "scissors\nscissors\npaper", "output": "?" }, { "input": "rock\nrock\nscissors", "output": "?" }, { "input": "paper\nrock\nscissors", "output": "?" }, { "input": "scissors\nrock\nscissors", "output": "M" }, { "input": "rock\npaper\nscissors", "output": "?" }, { "input": "paper\npaper\nscissors", "output": "S" }, { "input": "scissors\npaper\nscissors", "output": "?" }, { "input": "rock\nscissors\nscissors", "output": "F" }, { "input": "paper\nscissors\nscissors", "output": "?" }, { "input": "scissors\nscissors\nscissors", "output": "?" } ]
1,576,254,674
2,147,483,647
Python 3
OK
TESTS
27
218
0
f=input() m=input() s=input() def win(s1, s2): # Returns True if s2 beats s1 if s1=='rock' and s2=='paper': return True if s1=='paper' and s2=='scissors': return True if s1=='scissors' and s2=='rock': return True return False if win(m, f) and win(s, f): print('F') elif win(f, m) and win(s, m): print('M') elif win(m, s) and win(f, s): print('S') else: print('?')
Title: Rock-paper-scissors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown. Input Specification: The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. Output Specification: Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". Demo Input: ['rock\nrock\nrock\n', 'paper\nrock\nrock\n', 'scissors\nrock\nrock\n', 'scissors\npaper\nrock\n'] Demo Output: ['?\n', 'F\n', '?\n', '?\n'] Note: none
```python f=input() m=input() s=input() def win(s1, s2): # Returns True if s2 beats s1 if s1=='rock' and s2=='paper': return True if s1=='paper' and s2=='scissors': return True if s1=='scissors' and s2=='rock': return True return False if win(m, f) and win(s, f): print('F') elif win(f, m) and win(s, m): print('M') elif win(m, s) and win(f, s): print('S') else: print('?') ```
3.9455
0
none
none
none
0
[ "none" ]
null
null
You are given three sticks with positive integer lengths of *a*,<=*b*, and *c* centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most *l* centimeters. In particular, it is allowed not to increase the length of any stick. Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.
The single line contains 4 integers *a*,<=*b*,<=*c*,<=*l* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=3·105, 0<=≤<=*l*<=≤<=3·105).
Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most *l* centimeters, so that you can make a non-degenerate triangle from it.
[ "1 1 1 2\n", "1 2 3 1\n", "10 2 1 7\n" ]
[ "4\n", "2\n", "0\n" ]
In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter. In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.
0
[ { "input": "1 1 1 2", "output": "4" }, { "input": "1 2 3 1", "output": "2" }, { "input": "10 2 1 7", "output": "0" }, { "input": "1 2 1 5", "output": "20" }, { "input": "10 15 17 10", "output": "281" }, { "input": "5 5 5 10000", "output": "41841675001" }, { "input": "5 7 30 100", "output": "71696" }, { "input": "5 5 5 300000", "output": "1125157500250001" }, { "input": "4 2 5 28", "output": "1893" }, { "input": "2 7 8 4", "output": "25" }, { "input": "85 50 17 89", "output": "68620" }, { "input": "17 28 19 5558", "output": "7396315389" }, { "input": "5276 8562 1074 8453", "output": "49093268246" }, { "input": "9133 7818 3682 82004", "output": "38306048676255" }, { "input": "81780 54799 231699 808", "output": "0" }, { "input": "53553 262850 271957 182759", "output": "834977070873802" }, { "input": "300000 300000 300000 300000", "output": "4500090000549998" }, { "input": "1 1 300000 300000", "output": "599999" }, { "input": "300000 300000 1 300000", "output": "2250045000350001" }, { "input": "300000 300000 1 24234", "output": "1186319275394" }, { "input": "1 1 1 300000", "output": "1125022500250001" }, { "input": "3 5 7 300000", "output": "1125157499050009" }, { "input": "63 5 52 78", "output": "46502" }, { "input": "2 42 49 93", "output": "72542" }, { "input": "61 100 3 8502", "output": "27050809786" }, { "input": "30 918 702 591", "output": "14315560" }, { "input": "98406 37723 3 257918", "output": "1154347569149860" }, { "input": "552 250082 77579 278985", "output": "596240712378446" }, { "input": "183808 8 8 294771", "output": "622921327009564" }, { "input": "2958 4133 233463 259655", "output": "65797591388150" }, { "input": "300000 200000 100000 1", "output": "2" }, { "input": "300000 200000 100000 0", "output": "0" }, { "input": "100000 300000 100000 100000", "output": "0" }, { "input": "100000 300000 100000 100001", "output": "100002" }, { "input": "100000 300000 100000 100002", "output": "200005" }, { "input": "100000 300000 100000 100003", "output": "400012" }, { "input": "100000 300000 100000 100010", "output": "3000195" }, { "input": "100000 300000 100000 100100", "output": "255131325" }, { "input": "100000 300000 199999 0", "output": "0" }, { "input": "100000 300000 200001 0", "output": "1" }, { "input": "1 1 1 300000", "output": "1125022500250001" }, { "input": "3 1 29 1", "output": "0" }, { "input": "300000 300000 300000 300000", "output": "4500090000549998" } ]
1,440,266,457
5,457
PyPy 3
TIME_LIMIT_EXCEEDED
PRETESTS
5
1,000
5,836,800
a, b, c, l = list(map(int, input().split())) ans = 0 for i in range(l + 1): a1 = a + i lmin = max(a1 - (b + c) + 1, 0) lmax = l - i diffmax = a1 + b - c - 1 diffmin = b - c - a1 + 1 for lc in range(lmax + 1): ans += max(-1, min(lmax - lc, lc - diffmin) - max(lc - diffmax, lmin-lc, 0)) + 1 print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given three sticks with positive integer lengths of *a*,<=*b*, and *c* centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most *l* centimeters. In particular, it is allowed not to increase the length of any stick. Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them. Input Specification: The single line contains 4 integers *a*,<=*b*,<=*c*,<=*l* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=3·105, 0<=≤<=*l*<=≤<=3·105). Output Specification: Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most *l* centimeters, so that you can make a non-degenerate triangle from it. Demo Input: ['1 1 1 2\n', '1 2 3 1\n', '10 2 1 7\n'] Demo Output: ['4\n', '2\n', '0\n'] Note: In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter. In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.
```python a, b, c, l = list(map(int, input().split())) ans = 0 for i in range(l + 1): a1 = a + i lmin = max(a1 - (b + c) + 1, 0) lmax = l - i diffmax = a1 + b - c - 1 diffmin = b - c - a1 + 1 for lc in range(lmax + 1): ans += max(-1, min(lmax - lc, lc - diffmin) - max(lc - diffmax, lmin-lc, 0)) + 1 print(ans) ```
0
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,491,369,606
2,147,483,647
Python 3
OK
TESTS
30
62
5,632,000
from math import * def resheto(n): prime = [True for _ in range(n+1)] prime[0] = prime[1] = False for i in range(2, n+1): if prime[i]: if i ** 2 <= n: for j in range(i**2, n+1, i): prime[j] = False answer = [] for i in range(n + 1): if prime[i]: answer.append(i) return answer class Integer(int): def __pow__(self, power, modulo=None): k = power bbb = 1 c = self while k: if k % 2 == 0: k /= 2 c *= c else: k -= 1 bbb *= c return bbb def can_divide(self, n): if n == 0: return False else: if self % n == 0: return True else: return False def trial_division(self): divisions = [] d = 2 number = self while number > 1: if number % d == 0: divisions.append(d) number /= d else: d += 1 return sorted(divisions) def is_prime(self): if self == 2: return True j = int(sqrt(self)+1) for i in range(2, j+1): if self % i == 0: return False return True def gcd(self, bb): aa = self while bb: aa %= bb aa, bb = bb, aa return aa def lmc(self, bull): return int(self / gcd(self, bull) * bull) class Matrix: def __init__(self, size): matrix = [] for i in range(size): matrix.append([]) for j in range(size): matrix[i].append(0) self.matrix = matrix self.n = size def edit_element(self, cords, new_value): self.matrix[cords[0]][cords[1]] = new_value def __add__(self, other_matrix): c = Matrix(self.n) for i in range(self.n): for j in range(self.n): c.edit_element((i, j), self.matrix[i][j] + other_matrix.matrix[i][j]) return c def __mul__(self, other_matrix): c = Matrix(self.n) for i in range(self.n): for j in range(i): k = other_matrix.matrix[i][j] other_matrix.matrix[i][j] = other_matrix.matrix[j][i] other_matrix.matrix[j][i] = k for i in range(self.n): for j in range(self.n): c.matrix[i][j] = 0 for k in range(self.n): c.matrix[i][j] += self.matrix[i][k] * other_matrix.matrix[j][k] for i in range(self.n): for j in range(i): k = other_matrix.matrix[i][j] other_matrix.matrix[i][j] = other_matrix.matrix[j][i] other_matrix.matrix[j][i] = k return c joke = [4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, 852, 861, 895, 913, 915, 922, 958, 985, 1086, 1111, 1165] a = int(input()) print(joke[a-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 from math import * def resheto(n): prime = [True for _ in range(n+1)] prime[0] = prime[1] = False for i in range(2, n+1): if prime[i]: if i ** 2 <= n: for j in range(i**2, n+1, i): prime[j] = False answer = [] for i in range(n + 1): if prime[i]: answer.append(i) return answer class Integer(int): def __pow__(self, power, modulo=None): k = power bbb = 1 c = self while k: if k % 2 == 0: k /= 2 c *= c else: k -= 1 bbb *= c return bbb def can_divide(self, n): if n == 0: return False else: if self % n == 0: return True else: return False def trial_division(self): divisions = [] d = 2 number = self while number > 1: if number % d == 0: divisions.append(d) number /= d else: d += 1 return sorted(divisions) def is_prime(self): if self == 2: return True j = int(sqrt(self)+1) for i in range(2, j+1): if self % i == 0: return False return True def gcd(self, bb): aa = self while bb: aa %= bb aa, bb = bb, aa return aa def lmc(self, bull): return int(self / gcd(self, bull) * bull) class Matrix: def __init__(self, size): matrix = [] for i in range(size): matrix.append([]) for j in range(size): matrix[i].append(0) self.matrix = matrix self.n = size def edit_element(self, cords, new_value): self.matrix[cords[0]][cords[1]] = new_value def __add__(self, other_matrix): c = Matrix(self.n) for i in range(self.n): for j in range(self.n): c.edit_element((i, j), self.matrix[i][j] + other_matrix.matrix[i][j]) return c def __mul__(self, other_matrix): c = Matrix(self.n) for i in range(self.n): for j in range(i): k = other_matrix.matrix[i][j] other_matrix.matrix[i][j] = other_matrix.matrix[j][i] other_matrix.matrix[j][i] = k for i in range(self.n): for j in range(self.n): c.matrix[i][j] = 0 for k in range(self.n): c.matrix[i][j] += self.matrix[i][k] * other_matrix.matrix[j][k] for i in range(self.n): for j in range(i): k = other_matrix.matrix[i][j] other_matrix.matrix[i][j] = other_matrix.matrix[j][i] other_matrix.matrix[j][i] = k return c joke = [4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, 852, 861, 895, 913, 915, 922, 958, 985, 1086, 1111, 1165] a = int(input()) print(joke[a-1]) ```
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,646,144,341
2,147,483,647
Python 3
OK
TESTS
81
92
0
n=int(input()) xs=0 ys=0 zs=0 for _ in range(n): x,y,z=map(int,input().split()) xs+=x ys+=y zs+=z if xs or ys or zs: print("NO") else: print("YES")
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()) xs=0 ys=0 zs=0 for _ in range(n): x,y,z=map(int,input().split()) xs+=x ys+=y zs+=z if xs or ys or zs: print("NO") else: print("YES") ```
3.977
538
B
Quasi Binary
PROGRAMMING
1,400
[ "constructive algorithms", "dp", "greedy", "implementation" ]
null
null
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
[ "9\n", "32\n" ]
[ "9\n1 1 1 1 1 1 1 1 1 \n", "3\n10 11 11 \n" ]
none
1,000
[ { "input": "9", "output": "9\n1 1 1 1 1 1 1 1 1 " }, { "input": "32", "output": "3\n10 11 11 " }, { "input": "1", "output": "1\n1 " }, { "input": "415", "output": "5\n1 101 101 101 111 " }, { "input": "10011", "output": "1\n10011 " }, { "input": "10201", "output": "2\n100 10101 " }, { "input": "314159", "output": "9\n1 1 1 1 11 1011 101011 101011 111111 " }, { "input": "999999", "output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 " }, { "input": "2", "output": "2\n1 1 " }, { "input": "10", "output": "1\n10 " }, { "input": "21", "output": "2\n10 11 " }, { "input": "98", "output": "9\n10 11 11 11 11 11 11 11 11 " }, { "input": "102030", "output": "3\n10 1010 101010 " }, { "input": "909090", "output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 " }, { "input": "909823", "output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 " }, { "input": "1000000", "output": "1\n1000000 " }, { "input": "111111", "output": "1\n111111 " }, { "input": "123456", "output": "6\n1 11 111 1111 11111 111111 " }, { "input": "987654", "output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 " }, { "input": "908172", "output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 " }, { "input": "8", "output": "8\n1 1 1 1 1 1 1 1 " }, { "input": "100009", "output": "9\n1 1 1 1 1 1 1 1 100001 " }, { "input": "900000", "output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 " }, { "input": "1435", "output": "5\n1 101 111 111 1111 " }, { "input": "1453", "output": "5\n10 110 111 111 1111 " } ]
1,597,429,469
2,147,483,647
PyPy 3
OK
TESTS
25
140
0
import sys import math input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def quasibinary_repr(num): results = [] num_digits = int(math.log10(num)) + 1 while num > 0: cur_num = num cur_quasi_num = 0 for i in range(num_digits): result = (cur_num % 10) if result > 0: cur_quasi_num = cur_quasi_num + 1 * (10**i) cur_num = cur_num // 10 num = num - cur_quasi_num results.append(cur_quasi_num) return results num = inp() result = quasibinary_repr(num) print(len(result)) print(*result, sep=" ")
Title: Quasi Binary Time Limit: None seconds Memory Limit: None megabytes Problem Description: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). Output Specification: In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. Demo Input: ['9\n', '32\n'] Demo Output: ['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n'] Note: none
```python import sys import math input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def quasibinary_repr(num): results = [] num_digits = int(math.log10(num)) + 1 while num > 0: cur_num = num cur_quasi_num = 0 for i in range(num_digits): result = (cur_num % 10) if result > 0: cur_quasi_num = cur_quasi_num + 1 * (10**i) cur_num = cur_num // 10 num = num - cur_quasi_num results.append(cur_quasi_num) return results num = inp() result = quasibinary_repr(num) print(len(result)) print(*result, sep=" ") ```
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,658,335,566
2,147,483,647
Python 3
OK
TESTS
40
92
0
s1=input() s2=input() s3=input() s1=s1.strip() s2=s2.strip() s3=s3.strip() syllables = set("AEIOUaeiou") ##print(s1) ##print(s2) ##print(s3) c1=0 c2=0 c3=0 for i in s1: if(i in syllables): c1+=1 for i in s2: if(i in syllables): c2+=1 for i in s3: if(i in syllables): c3+=1 if(c1==5 and c2==7 and c3==5): 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 s1=input() s2=input() s3=input() s1=s1.strip() s2=s2.strip() s3=s3.strip() syllables = set("AEIOUaeiou") ##print(s1) ##print(s2) ##print(s3) c1=0 c2=0 c3=0 for i in s1: if(i in syllables): c1+=1 for i in s2: if(i in syllables): c2+=1 for i in s3: if(i in syllables): c3+=1 if(c1==5 and c2==7 and c3==5): print("YES") else: print("NO") ```
3.977
932
B
Recursive Queries
PROGRAMMING
1,300
[ "binary search", "data structures", "dfs and similar" ]
null
null
Let us define two functions *f* and *g* on positive integer numbers. You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*.
The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries. *Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9).
For each query, print a single line containing the answer for that query.
[ "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n", "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n" ]
[ "1\n4\n0\n8\n", "3\n1\n1\n5\n" ]
In the first example: - *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4
1,000
[ { "input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4", "output": "1\n4\n0\n8" }, { "input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4", "output": "3\n1\n1\n5" } ]
1,518,710,667
5,367
Python 3
SKIPPED
PRETESTS
0
2,000
45,670,400
def c(n): m = 1 while n>= 10: if n%10 != 0: m*=n%10 n=n/10 return m t = 10*[0] a = 10*[0] for i in range(10): a[i] = (10**6)*[0] for i in range(10**6): m = c(i) t[m]+=1 for j in range(10): a[j][i]=t[j] n=int(input()) for i in range(n): l,r,k = [int(j) for j in input().split()] print(a[k][r]-a[k][l-1])
Title: Recursive Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let us define two functions *f* and *g* on positive integer numbers. You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. Input Specification: The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries. *Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). Output Specification: For each query, print a single line containing the answer for that query. Demo Input: ['4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n', '4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n'] Demo Output: ['1\n4\n0\n8\n', '3\n1\n1\n5\n'] Note: In the first example: - *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4
```python def c(n): m = 1 while n>= 10: if n%10 != 0: m*=n%10 n=n/10 return m t = 10*[0] a = 10*[0] for i in range(10): a[i] = (10**6)*[0] for i in range(10**6): m = c(i) t[m]+=1 for j in range(10): a[j][i]=t[j] n=int(input()) for i in range(n): l,r,k = [int(j) for j in input().split()] print(a[k][r]-a[k][l-1]) ```
-1
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,666,936,382
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
x=input().split() n=int(x[0]) m=int(x[1]) a=int(x[2]) y=(n//a+1)*(m//a+1) print(y)
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 x=input().split() n=int(x[0]) m=int(x[1]) a=int(x[2]) y=(n//a+1)*(m//a+1) print(y) ```
0
916
B
Jamie and Binary Sequence (changed after round)
PROGRAMMING
2,000
[ "bitmasks", "greedy", "math" ]
null
null
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one. To be more clear, consider all integer sequence with length *k* (*a*1,<=*a*2,<=...,<=*a**k*) with . Give a value to each sequence. Among all sequence(s) that have the minimum *y* value, output the one that is the lexicographically largest. For definitions of powers and lexicographical order see notes.
The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence.
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence. It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018].
[ "23 5\n", "13 2\n", "1 2\n" ]
[ "Yes\n3 3 2 1 0 \n", "No\n", "Yes\n-1 -1 \n" ]
Sample 1: 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23 Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest. Answers like (4, 1, 1, 1, 0) do not have the minimum *y* value. Sample 2: It can be shown there does not exist a sequence with length 2. Sample 3: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a8539b2d27aefc8d2fab6dfd8296d11c36dcaa40.png" style="max-width: 100.0%;max-height: 100.0%;"/> Powers of 2: If *x* &gt; 0, then 2<sup class="upper-index">*x*</sup> = 2·2·2·...·2 (*x* times). If *x* = 0, then 2<sup class="upper-index">*x*</sup> = 1. If *x* &lt; 0, then <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/766628f1c7814795eac1a0afaa1ff062c40ef29e.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Lexicographical order: Given two different sequences of the same length, (*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ... , *a*<sub class="lower-index">*k*</sub>) and (*b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ... , *b*<sub class="lower-index">*k*</sub>), the first one is smaller than the second one for the lexicographical order, if and only if *a*<sub class="lower-index">*i*</sub> &lt; *b*<sub class="lower-index">*i*</sub>, for the first *i* where *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> differ.
1,000
[ { "input": "23 5", "output": "Yes\n3 3 2 1 0 " }, { "input": "13 2", "output": "No" }, { "input": "1 2", "output": "Yes\n-1 -1 " }, { "input": "1 1", "output": "Yes\n0 " }, { "input": "1000000000000000000 100000", "output": "Yes\n44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44..." }, { "input": "7 2", "output": "No" }, { "input": "7 3", "output": "Yes\n2 1 0 " }, { "input": "7 4", "output": "Yes\n1 1 1 0 " }, { "input": "521325125150442808 10", "output": "No" }, { "input": "498518679725149504 1000", "output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49..." }, { "input": "464823731286228582 100000", "output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..." }, { "input": "1 4", "output": "Yes\n-2 -2 -2 -2 " }, { "input": "9 4", "output": "Yes\n2 2 -1 -1 " }, { "input": "3 4", "output": "Yes\n0 0 -1 -1 " }, { "input": "144 4", "output": "Yes\n6 6 3 3 " }, { "input": "59 4", "output": "No" }, { "input": "78 4", "output": "Yes\n6 3 2 1 " }, { "input": "192 4", "output": "Yes\n6 6 5 5 " }, { "input": "107 4", "output": "No" }, { "input": "552 5", "output": "Yes\n8 8 5 2 2 " }, { "input": "680 5", "output": "Yes\n8 8 7 5 3 " }, { "input": "808 5", "output": "Yes\n8 8 8 5 3 " }, { "input": "1528 5", "output": "No" }, { "input": "1656 5", "output": "No" }, { "input": "26972 8", "output": "Yes\n14 13 11 8 6 4 3 2 " }, { "input": "23100 8", "output": "Yes\n14 12 11 9 5 4 3 2 " }, { "input": "19228 8", "output": "Yes\n13 13 11 9 8 4 3 2 " }, { "input": "22652 8", "output": "Yes\n14 12 11 6 5 4 3 2 " }, { "input": "26076 8", "output": "No" }, { "input": "329438 10", "output": "Yes\n18 16 10 9 7 6 4 3 2 1 " }, { "input": "12862 10", "output": "Yes\n12 12 12 9 5 4 3 2 0 0 " }, { "input": "96286 10", "output": "Yes\n15 15 14 13 12 11 4 3 2 1 " }, { "input": "12414 10", "output": "Yes\n12 12 12 6 5 4 3 2 0 0 " }, { "input": "95838 10", "output": "No" }, { "input": "1728568411 16", "output": "No" }, { "input": "611684539 16", "output": "Yes\n28 28 26 22 21 20 18 16 15 12 7 5 4 3 1 0 " }, { "input": "84735259 16", "output": "Yes\n25 25 24 19 18 15 14 13 12 10 8 4 3 1 -1 -1 " }, { "input": "6967851387 16", "output": "No" }, { "input": "2145934811 16", "output": "No" }, { "input": "6795804571172 20", "output": "Yes\n41 41 41 37 35 34 33 30 26 24 23 18 14 13 12 10 9 5 1 1 " }, { "input": "1038982654596 20", "output": "Yes\n38 38 38 37 36 32 31 30 29 27 21 20 16 13 11 9 7 1 0 0 " }, { "input": "11277865770724 20", "output": "No" }, { "input": "5525338821444 20", "output": "No" }, { "input": "15764221937572 20", "output": "No" }, { "input": "922239521698513045 30", "output": "Yes\n58 58 58 55 54 51 50 46 45 44 41 40 39 38 37 36 34 32 30 29 28 23 21 19 17 15 7 4 2 0 " }, { "input": "923065764876596469 30", "output": "No" }, { "input": "923892008054679893 30", "output": "No" }, { "input": "924718251232763317 30", "output": "Yes\n58 58 58 55 54 52 50 48 46 41 38 36 35 32 31 29 25 19 18 15 12 11 10 8 7 5 4 2 -1 -1 " }, { "input": "925544490115879445 30", "output": "Yes\n59 58 55 54 52 51 45 44 40 39 38 35 34 33 32 30 28 27 26 24 21 19 18 16 14 12 9 4 2 0 " }, { "input": "926370733293962869 30", "output": "Yes\n57 57 57 57 57 57 55 54 52 51 49 48 45 40 38 34 33 28 27 22 19 18 17 10 9 6 5 4 2 0 " }, { "input": "927196976472046293 30", "output": "No" }, { "input": "928023215355162421 30", "output": "Yes\n58 58 58 55 54 53 48 37 36 33 31 27 26 25 23 19 18 17 16 14 13 11 10 9 8 5 4 2 -1 -1 " }, { "input": "928849458533245845 30", "output": "No" }, { "input": "855969764271400156 30", "output": "No" }, { "input": "856796007449483580 30", "output": "No" }, { "input": "857622246332599708 30", "output": "Yes\n58 58 57 56 55 54 53 50 49 47 46 45 41 39 38 37 33 32 31 29 21 15 11 10 8 7 4 3 1 1 " }, { "input": "858448489510683132 30", "output": "No" }, { "input": "859274728393799260 30", "output": "Yes\n59 57 56 55 54 53 51 50 47 46 40 39 38 36 28 26 25 22 21 16 15 14 13 12 10 9 6 4 3 2 " }, { "input": "860100975866849980 30", "output": "No" }, { "input": "860927214749966108 30", "output": "No" }, { "input": "861753457928049532 30", "output": "Yes\n58 58 57 56 55 54 53 52 50 48 47 44 37 36 34 30 26 25 24 23 22 18 12 9 8 6 5 4 3 2 " }, { "input": "862579701106132957 30", "output": "No" }, { "input": "863405944284216381 30", "output": "No" }, { "input": "374585535361966567 30", "output": "No" }, { "input": "4 1", "output": "Yes\n2 " }, { "input": "4 9", "output": "Yes\n-1 -1 -1 -1 -1 -1 -1 -2 -2 " }, { "input": "4 3", "output": "Yes\n1 0 0 " }, { "input": "4 144", "output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -21 " }, { "input": "4 59", "output": "Yes\n-3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -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 -30 " }, { "input": "4 78", "output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 " }, { "input": "4 192", "output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -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 -..." }, { "input": "4 107", "output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -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 -47 " }, { "input": "5 552", "output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..." }, { "input": "5 680", "output": "Yes\n-7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7..." }, { "input": "5 808", "output": "Yes\n-7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7..." }, { "input": "5 1528", "output": "Yes\n-8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8..." }, { "input": "5 1656", "output": "Yes\n-8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8..." }, { "input": "8 26972", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "8 23100", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "8 19228", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "8 22652", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "8 26076", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "23 19354", "output": "Yes\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9..." }, { "input": "23 35482", "output": "Yes\n-10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -1..." }, { "input": "23 18906", "output": "Yes\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9..." }, { "input": "23 2330", "output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..." }, { "input": "23 85754", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "23 1882", "output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..." }, { "input": "23 85306", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "23 68730", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "23 84859", "output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..." }, { "input": "23 45148", "output": "Yes\n-10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -1..." }, { "input": "281474976710656 5", "output": "Yes\n46 46 46 45 45 " }, { "input": "288230376151973890 5", "output": "Yes\n57 57 18 0 0 " }, { "input": "36029346774812736 5", "output": "Yes\n55 39 15 11 6 " }, { "input": "901283150305558530 5", "output": "No" }, { "input": "288318372649779720 50", "output": "Yes\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 46 44 35 30 27 17 14 9 2 1 0 -1 -2 -3 -4 -5 -6 -6 " }, { "input": "513703875844698663 50", "output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 53 48 43 41 39 38 37 36 34 27 26 25 24 22 21 20 18 17 15 14 13 12 9 5 2 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -9 " }, { "input": "287632104387196918 50", "output": "Yes\n57 56 55 54 53 52 51 50 48 47 46 44 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 13 12 10 9 8 7 6 5 4 2 1 " }, { "input": "864690028406636543 58", "output": "Yes\n58 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 39 38 37 36 35 34 33 32 31 30 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 " }, { "input": "576460752303423487 60", "output": "Yes\n57 57 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 " }, { "input": "141012366262272 1", "output": "No" }, { "input": "1100585377792 4", "output": "Yes\n39 39 30 13 " }, { "input": "18598239186190594 9", "output": "Yes\n54 49 44 41 40 21 18 8 1 " }, { "input": "18647719372456016 19", "output": "Yes\n51 51 51 51 51 51 51 51 49 46 31 24 20 16 6 3 2 1 1 " }, { "input": "9297478914673158 29", "output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 48 43 33 18 11 9 2 0 -1 -2 -3 -4 -4 " }, { "input": "668507368948226 39", "output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 32 22 16 15 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -13 " }, { "input": "1143595340402690 49", "output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 36 35 27 25 19 12 0 -1 -2 -3 -4 -5 -6 -7 -8 -8 " }, { "input": "35527987183872 59", "output": "Yes\n40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 38 36 24 19 18 17 14 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 " }, { "input": "324634416758413825 9", "output": "No" }, { "input": "577030480059438572 19", "output": "Yes\n59 49 42 41 37 35 33 28 26 23 18 12 10 8 7 6 5 3 2 " }, { "input": "185505960265024385 29", "output": "Yes\n54 54 54 54 54 54 54 54 54 54 52 49 48 43 42 39 37 36 29 24 22 20 15 9 8 7 -1 -2 -2 " }, { "input": "57421517433081233 39", "output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 51 50 39 36 31 30 28 27 26 24 20 11 10 8 7 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -10 " }, { "input": "90131572647657641 49", "output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 45 44 42 41 37 36 28 25 23 21 20 18 17 7 5 3 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -12 " }, { "input": "732268459757413905 59", "output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 53 51 48 47 43 41 38 35 31 30 28 20 13 10 9 4 -1 -2 -2 " }, { "input": "226111453445787190 9", "output": "No" }, { "input": "478818723873062027 19", "output": "No" }, { "input": "337790572680259391 29", "output": "Yes\n58 55 53 52 44 41 39 37 36 35 34 30 29 28 26 24 20 18 16 13 10 9 8 5 4 3 2 1 0 " }, { "input": "168057637182978458 39", "output": "Yes\n54 54 54 54 54 54 54 54 54 52 50 48 43 42 41 40 39 34 33 32 31 30 28 26 25 20 18 16 13 12 11 8 7 4 3 0 -1 -2 -2 " }, { "input": "401486559567818547 49", "output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 52 49 46 44 43 42 40 39 38 37 34 33 28 26 24 21 17 13 11 10 9 8 5 4 1 -1 -1 " }, { "input": "828935109688089201 59", "output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 47 46 45 44 43 36 34 33 32 29 25 23 22 19 18 17 15 14 12 11 9 6 5 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 " }, { "input": "954687629161163764 9", "output": "No" }, { "input": "287025268967992526 19", "output": "No" }, { "input": "844118423640988373 29", "output": "No" }, { "input": "128233154575908599 39", "output": "Yes\n56 55 54 50 49 48 47 44 41 40 38 36 35 34 33 32 31 30 29 27 25 23 22 21 19 18 15 13 12 11 10 9 7 6 5 4 2 1 0 " }, { "input": "792058388714085231 49", "output": "Yes\n56 56 56 56 56 56 56 56 56 56 55 54 53 52 51 50 48 47 46 45 44 42 39 38 37 35 30 29 28 26 23 21 19 17 16 15 14 12 11 9 8 6 5 3 2 1 -1 -2 -2 " }, { "input": "827183623566145225 59", "output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 54 53 52 51 49 47 45 44 43 42 41 40 36 35 34 33 32 30 29 28 27 26 25 23 21 19 18 17 13 12 10 9 7 6 3 -1 -1 " }, { "input": "846113779983498737 9", "output": "No" }, { "input": "780248358343081983 19", "output": "No" }, { "input": "576460580458522095 29", "output": "No" }, { "input": "540145805193625598 39", "output": "No" }, { "input": "576388182371377103 49", "output": "Yes\n58 57 56 55 54 53 52 51 50 49 48 47 45 44 43 42 40 39 38 37 36 35 34 33 32 30 29 28 27 26 25 23 22 21 20 19 17 15 12 11 10 9 8 7 6 3 2 1 0 " }, { "input": "567448991726268409 59", "output": "Yes\n56 56 56 56 56 56 56 55 54 52 51 50 49 48 47 46 45 44 43 41 40 39 38 36 35 32 31 30 29 28 27 25 24 23 22 21 20 19 18 17 16 14 13 11 10 9 8 7 6 5 4 3 -1 -2 -3 -4 -5 -6 -6 " }, { "input": "576460752303423487 9", "output": "No" }, { "input": "576460752303423487 19", "output": "No" }, { "input": "864691128455135231 29", "output": "No" }, { "input": "864691128455135231 39", "output": "No" }, { "input": "576460752303423487 49", "output": "No" }, { "input": "864691128455135231 59", "output": "Yes\n59 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 " }, { "input": "628839188486443015 2412", "output": "Yes\n48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48..." }, { "input": "558445254282313727 89558", "output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..." }, { "input": "576460752303423487 100000", "output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..." }, { "input": "1 100000", "output": "Yes\n-16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -1..." }, { "input": "99997 100000", "output": "Yes\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "99998 100000", "output": "Yes\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "99999 100000", "output": "Yes\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "100000 100000", "output": "Yes\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "100001 100000", "output": "Yes\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "100002 100000", "output": "Yes\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "100003 100000", "output": "Yes\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "12 202", "output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4..." }, { "input": "1 4", "output": "Yes\n-2 -2 -2 -2 " }, { "input": "2 64", "output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 " }, { "input": "2 8", "output": "Yes\n-2 -2 -2 -2 -2 -2 -2 -2 " }, { "input": "1 5", "output": "Yes\n-2 -2 -2 -3 -3 " }, { "input": "1 7", "output": "Yes\n-2 -2 -2 -3 -4 -5 -5 " }, { "input": "19 5", "output": "Yes\n3 3 1 -1 -1 " }, { "input": "1 30", "output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 " } ]
1,517,810,259
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
5,632,000
n, k = map(int, input().split(" ")) binary = bin(n)[2:][::-1] last = 0 cnt=0 for i in range(len(binary)): if binary[i] == '1': if cnt==0: last=i cnt+=1 arr = list(map(int, binary)) length = len(arr) if cnt > k: print("No") exit() print("Yes") c = 0 pr = 0 s = 0 if cnt != k: for i in range(length-1, -10000000000, -1): if i > -1 and binary[i] == '1': c += 1 s += 1 if (c * 2 + (cnt - s) <= k): c *= 2 pr = i - 1 if (int(c/2) + (cnt-s) == k): break else: break else: pr = length-1 rem = k - c if pr < 0: last = pr - 1 c -= 1 if rem == 1 and k != 1: print((str(pr)+" ")*(c-1)+(str(pr-1)+" ")*2, end='') rem = 0 else: print((str(pr)+" ")*c, end='') for i in range(pr-1, -1, -1): if rem == 0: exit() if i>0 and binary[i] == '1': if i == last: if rem > 1: break c+=1 print(str(i), end=' ') rem -= 1 for i in range(last-1, last-rem, -1): if rem==0: break print(str(i), end=' ') if rem != 0: print(str(last-rem+1)+" ")
Title: Jamie and Binary Sequence (changed after round) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one. To be more clear, consider all integer sequence with length *k* (*a*1,<=*a*2,<=...,<=*a**k*) with . Give a value to each sequence. Among all sequence(s) that have the minimum *y* value, output the one that is the lexicographically largest. For definitions of powers and lexicographical order see notes. Input Specification: The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence. Output Specification: Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence. It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018]. Demo Input: ['23 5\n', '13 2\n', '1 2\n'] Demo Output: ['Yes\n3 3 2 1 0 \n', 'No\n', 'Yes\n-1 -1 \n'] Note: Sample 1: 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23 Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest. Answers like (4, 1, 1, 1, 0) do not have the minimum *y* value. Sample 2: It can be shown there does not exist a sequence with length 2. Sample 3: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a8539b2d27aefc8d2fab6dfd8296d11c36dcaa40.png" style="max-width: 100.0%;max-height: 100.0%;"/> Powers of 2: If *x* &gt; 0, then 2<sup class="upper-index">*x*</sup> = 2·2·2·...·2 (*x* times). If *x* = 0, then 2<sup class="upper-index">*x*</sup> = 1. If *x* &lt; 0, then <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/766628f1c7814795eac1a0afaa1ff062c40ef29e.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Lexicographical order: Given two different sequences of the same length, (*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ... , *a*<sub class="lower-index">*k*</sub>) and (*b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ... , *b*<sub class="lower-index">*k*</sub>), the first one is smaller than the second one for the lexicographical order, if and only if *a*<sub class="lower-index">*i*</sub> &lt; *b*<sub class="lower-index">*i*</sub>, for the first *i* where *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> differ.
```python n, k = map(int, input().split(" ")) binary = bin(n)[2:][::-1] last = 0 cnt=0 for i in range(len(binary)): if binary[i] == '1': if cnt==0: last=i cnt+=1 arr = list(map(int, binary)) length = len(arr) if cnt > k: print("No") exit() print("Yes") c = 0 pr = 0 s = 0 if cnt != k: for i in range(length-1, -10000000000, -1): if i > -1 and binary[i] == '1': c += 1 s += 1 if (c * 2 + (cnt - s) <= k): c *= 2 pr = i - 1 if (int(c/2) + (cnt-s) == k): break else: break else: pr = length-1 rem = k - c if pr < 0: last = pr - 1 c -= 1 if rem == 1 and k != 1: print((str(pr)+" ")*(c-1)+(str(pr-1)+" ")*2, end='') rem = 0 else: print((str(pr)+" ")*c, end='') for i in range(pr-1, -1, -1): if rem == 0: exit() if i>0 and binary[i] == '1': if i == last: if rem > 1: break c+=1 print(str(i), end=' ') rem -= 1 for i in range(last-1, last-rem, -1): if rem==0: break print(str(i), end=' ') if rem != 0: print(str(last-rem+1)+" ") ```
0
49
A
Sleuth
PROGRAMMING
800
[ "implementation" ]
A. Sleuth
2
256
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z
The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.
Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.
[ "Is it a melon?\n", "Is it an apple?\n", "Is it a banana ?\n", "Is it an apple and a banana simultaneouSLY?\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
none
500
[ { "input": "Is it a melon?", "output": "NO" }, { "input": "Is it an apple?", "output": "YES" }, { "input": " Is it a banana ?", "output": "YES" }, { "input": "Is it an apple and a banana simultaneouSLY?", "output": "YES" }, { "input": "oHtSbDwzHb?", "output": "NO" }, { "input": "sZecYdUvZHrXx?", "output": "NO" }, { "input": "uMtXK?", "output": "NO" }, { "input": "U?", "output": "YES" }, { "input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?", "output": "NO" }, { "input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?", "output": "NO" }, { "input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?", "output": "NO" }, { "input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?", "output": "NO" }, { "input": "YhCuZnrWUBEed?", "output": "NO" }, { "input": "hh?", "output": "NO" }, { "input": "whU?", "output": "YES" }, { "input": "fgwg?", "output": "NO" }, { "input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?", "output": "NO" }, { "input": "n?", "output": "NO" }, { "input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?", "output": "NO" }, { "input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?", "output": "NO" }, { "input": " J ?", "output": "NO" }, { "input": " j ?", "output": "NO" }, { "input": " o ?", "output": "YES" }, { "input": " T ?", "output": "NO" }, { "input": " q ?", "output": "NO" }, { "input": " j ?", "output": "NO" }, { "input": " c ?", "output": "NO" }, { "input": " B ?", "output": "NO" }, { "input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?", "output": "YES" }, { "input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?", "output": "YES" }, { "input": "wGsfZCSwN PEUhNUrLfABrxA?", "output": "YES" }, { "input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?", "output": "YES" }, { "input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?", "output": "YES" }, { "input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?", "output": "YES" }, { "input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?", "output": "YES" } ]
1,529,733,413
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
a=input() b=a.lower() for j in range(len(b)): if b[-j].isalpha(): if b[-j]=="a": print("YES") elif b[-j]=="e": print("YES") elif b[-j]=="i": print("YES") elif b[-j]=="u": print("YES") elif b[-j]=="y": print("YES") else: print("NO") break
Title: Sleuth Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z Input Specification: The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. Output Specification: Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. Demo Input: ['Is it a melon?\n', 'Is it an apple?\n', 'Is it a banana ?\n', 'Is it an apple and a banana simultaneouSLY?\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n', 'YES\n'] Note: none
```python a=input() b=a.lower() for j in range(len(b)): if b[-j].isalpha(): if b[-j]=="a": print("YES") elif b[-j]=="e": print("YES") elif b[-j]=="i": print("YES") elif b[-j]=="u": print("YES") elif b[-j]=="y": print("YES") else: print("NO") break ```
0
837
F
Prefix Sums
PROGRAMMING
2,400
[ "binary search", "brute force", "combinatorics", "math", "matrices" ]
null
null
Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*). You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input, and for each *i*<=≥<=1 *A**i*<==<=*p*(*A**i*<=-<=1). Also you have a positive integer *k*. You have to find minimum possible *i* such that *A**i* contains a number which is larger or equal than *k*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=≤<=1018). *n* is the size of array *A*0. The second line contains *n* integers *A*00,<=*A*01... *A*0*n*<=-<=1 — the elements of *A*0 (0<=≤<=*A*0*i*<=≤<=109). At least two elements of *A*0 are positive.
Print the minimum *i* such that *A**i* contains a number which is larger or equal than *k*.
[ "2 2\n1 1\n", "3 6\n1 1 1\n", "3 1\n1 0 1\n" ]
[ "1\n", "2\n", "0\n" ]
none
0
[ { "input": "2 2\n1 1", "output": "1" }, { "input": "3 6\n1 1 1", "output": "2" }, { "input": "3 1\n1 0 1", "output": "0" }, { "input": "3 1000000000000000000\n5 4 5", "output": "632455531" }, { "input": "4 1000000000000000000\n0 4 4 5", "output": "707106780" }, { "input": "5 1000000000000000000\n5 7 4 2 5", "output": "46805" }, { "input": "3 999999999000999944\n7 2 6", "output": "534522483" }, { "input": "4 999999999000531216\n8 7 4 6", "output": "908559" }, { "input": "5 152742477016321721\n0 0 2 6 2", "output": "390822817" }, { "input": "6 1000000000000000000\n1 1 0 1 0 1", "output": "10369" }, { "input": "7 1000000000000000000\n77 94 59 82 91 44 93", "output": "1448" }, { "input": "3 999999999000999944\n5 1 2", "output": "632455532" }, { "input": "4 999999999000531216\n1 1 0 1", "output": "1817119" }, { "input": "5 152742477016321721\n1 4 0 5 6", "output": "43752" }, { "input": "6 1000000000000000000\n1 1 1 0 1 1", "output": "10369" }, { "input": "7 1000000000000000000\n20 24 97 16 37 37 84", "output": "1814" }, { "input": "10 1000000000000000000\n1 0 1 0 1 0 0 0 0 0", "output": "411" }, { "input": "10 3\n1 1 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "3 1000000000000000000\n1 1 0", "output": "1414213561" }, { "input": "8 1000000000000000000\n1 1 0 0 0 0 0 0", "output": "1256" }, { "input": "4 1000000000000000000\n612929642 983621174 279363954 332455288", "output": "2137" }, { "input": "3 1000000000000000000\n422931534 210865757 697603256", "output": "68766" }, { "input": "3 563768374159627711\n8849237 586207348 386453596", "output": "356888" }, { "input": "3 1000000000000000000\n1 0 1", "output": "1414213562" }, { "input": "5 1000000000000000000\n1 0 0 0 1", "output": "69992" }, { "input": "11 1000000000000000000\n1 0 0 0 0 0 0 0 0 0 1", "output": "282" }, { "input": "15 1000000000000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "111" }, { "input": "18 1000000000000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "75" }, { "input": "2 1000000000000000000\n758816935 60667976", "output": "1317840910" }, { "input": "8 1000000000000000000\n1 0 0 0 0 0 0 1", "output": "1257" } ]
1,613,211,820
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
24
1,000
16,691,200
mod = 10**9 + 7 n, k = map(int,input().split()) a = list(map(int, input().split())) a.reverse() def sol() : l = 0; r = 10**18; mid = 0; p = 1; sum = 0 while r - l > 1 : mid = (l + r) // 2 p = 1; sum = 0 for i in range(n) : sum += a[i] * p if sum >= k : r = mid; break if i + 1 < n : p = p * (mid + i) // (i + 1) if r != mid : l = mid + 1 p = 1; sum = 0 for i in range(n) : sum += a[i] * p if sum >= k : return l if i + 1 < n : p = p * (l + i) // (i + 1) return r for i in range(n - 1, -1, -1) : if a[i] != 0 : break else : n -= 1 if max(a) >= k : print(0) else : print(sol())
Title: Prefix Sums Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*). You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input, and for each *i*<=≥<=1 *A**i*<==<=*p*(*A**i*<=-<=1). Also you have a positive integer *k*. You have to find minimum possible *i* such that *A**i* contains a number which is larger or equal than *k*. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=≤<=1018). *n* is the size of array *A*0. The second line contains *n* integers *A*00,<=*A*01... *A*0*n*<=-<=1 — the elements of *A*0 (0<=≤<=*A*0*i*<=≤<=109). At least two elements of *A*0 are positive. Output Specification: Print the minimum *i* such that *A**i* contains a number which is larger or equal than *k*. Demo Input: ['2 2\n1 1\n', '3 6\n1 1 1\n', '3 1\n1 0 1\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: none
```python mod = 10**9 + 7 n, k = map(int,input().split()) a = list(map(int, input().split())) a.reverse() def sol() : l = 0; r = 10**18; mid = 0; p = 1; sum = 0 while r - l > 1 : mid = (l + r) // 2 p = 1; sum = 0 for i in range(n) : sum += a[i] * p if sum >= k : r = mid; break if i + 1 < n : p = p * (mid + i) // (i + 1) if r != mid : l = mid + 1 p = 1; sum = 0 for i in range(n) : sum += a[i] * p if sum >= k : return l if i + 1 < n : p = p * (l + i) // (i + 1) return r for i in range(n - 1, -1, -1) : if a[i] != 0 : break else : n -= 1 if max(a) >= k : print(0) else : print(sol()) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,615,612,037
2,147,483,647
Python 3
OK
TESTS
30
124
0
string = input() low=0 high=0 for i in string: if (i.islower()): low+=1 else : high+=1 if low >= high: print(string.lower()) else : print(string.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 string = input() low=0 high=0 for i in string: if (i.islower()): low+=1 else : high+=1 if low >= high: print(string.lower()) else : print(string.upper()) ```
3.969
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,589,313,408
2,147,483,647
Python 3
OK
TESTS
34
218
6,963,200
n = int(input()) lst=[] for i in range(n): a = input() lst.append(a) used=[] if n==1: print(lst[0]) else: unique = [used.append(x) for x in lst if x not in used] if len(used) == 2: team1 = lst.count(used[0]) team2 = lst.count(used[1]) if team1 > team2: print(used[0]) else: print(used[1]) else: team1 = lst.count(used[0]) team2 = 0 if team1 > team2: print(used[0])
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) lst=[] for i in range(n): a = input() lst.append(a) used=[] if n==1: print(lst[0]) else: unique = [used.append(x) for x in lst if x not in used] if len(used) == 2: team1 = lst.count(used[0]) team2 = lst.count(used[1]) if team1 > team2: print(used[0]) else: print(used[1]) else: team1 = lst.count(used[0]) team2 = 0 if team1 > team2: print(used[0]) ```
3.93253
15
A
Cottage Village
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Cottage Village
2
64
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000).
Output the amount of possible positions of the new house.
[ "2 2\n0 4\n6 2\n", "2 2\n0 4\n5 2\n", "2 3\n0 4\n5 2\n" ]
[ "4\n", "3\n", "2\n" ]
It is possible for the *x*-coordinate of the new house to have non-integer value.
0
[ { "input": "2 2\n0 4\n6 2", "output": "4" }, { "input": "2 2\n0 4\n5 2", "output": "3" }, { "input": "2 3\n0 4\n5 2", "output": "2" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 2\n2 1", "output": "2" }, { "input": "2 1\n2 1\n1 1", "output": "2" }, { "input": "2 2\n0 4\n7 4", "output": "4" }, { "input": "4 1\n-12 1\n-14 1\n4 1\n-11 1", "output": "5" }, { "input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1", "output": "2" }, { "input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6", "output": "6" }, { "input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9", "output": "35" }, { "input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34", "output": "16" }, { "input": "3 501\n827 327\n-85 480\n-999 343", "output": "6" }, { "input": "2 999\n-999 471\n530 588", "output": "4" }, { "input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31", "output": "30" }, { "input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3", "output": "16" }, { "input": "4 512\n-997 354\n-568 216\n-234 221\n603 403", "output": "4" }, { "input": "3 966\n988 5\n15 2\n-992 79", "output": "6" }, { "input": "2 1000\n-995 201\n206 194", "output": "4" }, { "input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2", "output": "9" }, { "input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1", "output": "43" }, { "input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7", "output": "96" }, { "input": "1 1000\n0 1000", "output": "2" } ]
1,588,670,906
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
186
307,200
square, side = map(int, input().split()) #V sorts ascending, square houses by x-axis houses = sorted([list(map(int, input().split())) for i in range(square)], key=lambda x: x[0]) answer = 2 for i in range(square - 1): x = houses[i][0] + houses[i][1] / 2 y = houses[i + 1][0] - houses[i + 1][1] / 2 # if the space between the 2 houses is equal to the main house's side if y - x == side: answer += 1 # if the space between the houses is bigger elif y - x > side: answer += 2 print(ans)
Title: Cottage Village Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input Specification: The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000). Output Specification: Output the amount of possible positions of the new house. Demo Input: ['2 2\n0 4\n6 2\n', '2 2\n0 4\n5 2\n', '2 3\n0 4\n5 2\n'] Demo Output: ['4\n', '3\n', '2\n'] Note: It is possible for the *x*-coordinate of the new house to have non-integer value.
```python square, side = map(int, input().split()) #V sorts ascending, square houses by x-axis houses = sorted([list(map(int, input().split())) for i in range(square)], key=lambda x: x[0]) answer = 2 for i in range(square - 1): x = houses[i][0] + houses[i][1] / 2 y = houses[i + 1][0] - houses[i + 1][1] / 2 # if the space between the 2 houses is equal to the main house's side if y - x == side: answer += 1 # if the space between the houses is bigger elif y - x > side: answer += 2 print(ans) ```
-1
569
B
Inventory
PROGRAMMING
1,200
[ "greedy", "math" ]
null
null
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal.
The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items.
Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
[ "3\n1 3 2\n", "4\n2 2 3 3\n", "1\n2\n" ]
[ "1 3 2 \n", "2 1 3 4 \n", "1 \n" ]
In the first test the numeration is already a permutation, so there is no need to change anything. In the second test there are two pairs of equal numbers, in each pair you need to replace one number. In the third test you need to replace 2 by 1, as the numbering should start from one.
1,000
[ { "input": "3\n1 3 2", "output": "1 3 2 " }, { "input": "4\n2 2 3 3", "output": "2 1 3 4 " }, { "input": "1\n2", "output": "1 " }, { "input": "3\n3 3 1", "output": "3 2 1 " }, { "input": "5\n1 1 1 1 1", "output": "1 2 3 4 5 " }, { "input": "5\n5 3 4 4 2", "output": "5 3 4 1 2 " }, { "input": "5\n19 11 8 8 10", "output": "1 2 3 4 5 " }, { "input": "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2", "output": "2 4 1 5 6 7 3 8 9 10 11 12 13 14 15 " }, { "input": "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9", "output": "3 11 5 9 10 4 6 12 13 7 14 1 8 15 16 2 17 18 " }, { "input": "42\n999 863 440 1036 1186 908 330 265 382 417 858 286 834 922 42 569 79 158 312 1175 1069 188 21 1207 985 375 59 417 256 595 732 742 629 737 25 699 484 517 37 1134 472 720", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 42 15 16 17 18 19 20 22 21 23 24 26 27 28 29 30 31 32 33 34 25 35 36 38 37 39 40 41 " }, { "input": "111\n15 45 14 65 49 25 102 86 14 80 54 73 43 78 42 32 47 60 55 66 84 69 49 22 26 72 89 52 26 80 71 35 56 2 88 23 23 53 65 92 46 73 29 65 88 99 19 99 87 10 47 96 109 20 60 89 63 105 29 92 109 20 95 65 31 89 107 3 3 50 58 9 28 39 104 42 41 36 70 49 59 96 16 9 3 108 38 42 2 67 32 86 20 6 101 70 101 91 38 10 74 3 27 15 103 63 51 60 62 10 70", "output": "15 45 14 65 49 25 102 86 1 80 54 73 43 78 42 32 47 60 55 66 84 69 4 22 26 72 89 52 5 7 71 35 56 2 88 23 8 53 11 92 46 12 29 13 17 99 19 18 87 10 21 96 109 20 24 30 63 105 33 34 37 40 95 44 31 48 107 3 57 50 58 9 28 39 104 61 41 36 70 64 59 68 16 75 76 108 38 77 79 67 81 82 83 6 101 85 90 91 93 94 74 97 27 98 103 100 51 106 62 110 111 " }, { "input": "7\n45301 14370 61599 42695 46301 24556 26812", "output": "1 2 3 4 5 6 7 " }, { "input": "22\n70150 17718 11731 6488 72633 41249 12141 71465 88562 6167 71659 34151 60508 24942 77343 35882 80424 67225 92746 55412 79 53642", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 " }, { "input": "2\n1 4", "output": "1 2 " } ]
1,689,890,309
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
46
819,200
n=int(input()) b=list(map(int,input().split())) v=[0]*100005 c=0 for i in b: if i <=n: v[i]+=1 elif i > n: c+=1 s=set() for j in range(1,n+1): if j not in b: s.add(j) for p in range(n): if len(s)==0: break if v[b[p]]>1 : v[b[p]]-=1 b[p]=s.pop() if c>0: b.append(s.pop()) c-=1 b.pop(0) print(*b)
Title: Inventory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal. Input Specification: The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. Output Specification: Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. Demo Input: ['3\n1 3 2\n', '4\n2 2 3 3\n', '1\n2\n'] Demo Output: ['1 3 2 \n', '2 1 3 4 \n', '1 \n'] Note: In the first test the numeration is already a permutation, so there is no need to change anything. In the second test there are two pairs of equal numbers, in each pair you need to replace one number. In the third test you need to replace 2 by 1, as the numbering should start from one.
```python n=int(input()) b=list(map(int,input().split())) v=[0]*100005 c=0 for i in b: if i <=n: v[i]+=1 elif i > n: c+=1 s=set() for j in range(1,n+1): if j not in b: s.add(j) for p in range(n): if len(s)==0: break if v[b[p]]>1 : v[b[p]]-=1 b[p]=s.pop() if c>0: b.append(s.pop()) c-=1 b.pop(0) print(*b) ```
0
743
B
Chloe and the sequence
PROGRAMMING
1,200
[ "binary search", "bitmasks", "constructive algorithms", "implementation" ]
null
null
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step. The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps. Please help Chloe to solve the problem!
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1).
Print single integer — the integer at the *k*-th position in the obtained sequence.
[ "3 2\n", "4 8\n" ]
[ "2", "4" ]
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2. In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
1,000
[ { "input": "3 2", "output": "2" }, { "input": "4 8", "output": "4" }, { "input": "5 27", "output": "1" }, { "input": "7 44", "output": "3" }, { "input": "15 18432", "output": "12" }, { "input": "20 259676", "output": "3" }, { "input": "30 671088640", "output": "28" }, { "input": "38 137438953472", "output": "38" }, { "input": "1 1", "output": "1" }, { "input": "3 3", "output": "1" }, { "input": "4 12", "output": "3" }, { "input": "8 224", "output": "6" }, { "input": "13 1368", "output": "4" }, { "input": "16 49152", "output": "15" }, { "input": "19 1024", "output": "11" }, { "input": "24 15204352", "output": "20" }, { "input": "27 6586544", "output": "5" }, { "input": "31 536870912", "output": "30" }, { "input": "38 94489280512", "output": "34" }, { "input": "42 215268308020", "output": "3" }, { "input": "42 3452074721280", "output": "21" }, { "input": "46 34394312982528", "output": "15" }, { "input": "48 133865540681728", "output": "39" }, { "input": "49 76541041985542", "output": "2" }, { "input": "49 104822971826176", "output": "34" }, { "input": "49 351843720888320", "output": "47" }, { "input": "50 743042492421629", "output": "1" }, { "input": "50 666266740436818", "output": "2" }, { "input": "50 704239287953456", "output": "5" }, { "input": "50 116938486513664", "output": "17" }, { "input": "50 806423059496960", "output": "37" }, { "input": "50 985162418487296", "output": "48" }, { "input": "50 844424930131968", "output": "49" }, { "input": "50 562949953421312", "output": "50" }, { "input": "50 1", "output": "1" }, { "input": "50 1125899906842623", "output": "1" }, { "input": "50 1125899906842620", "output": "3" }, { "input": "39 549755813887", "output": "1" }, { "input": "50 100000000000", "output": "12" } ]
1,536,588,424
2,147,483,647
Python 3
OK
TESTS
39
124
0
def mexk(n,k): #n,k=map(int,input().split()) ans=n low=1 high=pow(2,n)-1 while low<=high: mid=(low+high)//2 if mid==k: return ans ans-=1 if k<mid: high=mid-1 else: low=mid+1 n,k=map(int,input().split()) print(mexk(n,k))
Title: Chloe and the sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step. The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps. Please help Chloe to solve the problem! Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). Output Specification: Print single integer — the integer at the *k*-th position in the obtained sequence. Demo Input: ['3 2\n', '4 8\n'] Demo Output: ['2', '4'] Note: In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2. In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
```python def mexk(n,k): #n,k=map(int,input().split()) ans=n low=1 high=pow(2,n)-1 while low<=high: mid=(low+high)//2 if mid==k: return ans ans-=1 if k<mid: high=mid-1 else: low=mid+1 n,k=map(int,input().split()) print(mexk(n,k)) ```
3
0
none
none
none
0
[ "none" ]
null
null
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments. After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process. Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000). Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance *x* (1<=≤<=*x*<=≤<=*w*<=-<=1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
After each cut print on a single line the area of the maximum available glass fragment in mm2.
[ "4 3 4\nH 2\nV 2\nV 3\nV 1\n", "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n" ]
[ "8\n4\n4\n2\n", "28\n16\n12\n6\n4\n" ]
Picture for the first sample test:
0
[ { "input": "4 3 4\nH 2\nV 2\nV 3\nV 1", "output": "8\n4\n4\n2" }, { "input": "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1", "output": "28\n16\n12\n6\n4" }, { "input": "2 2 1\nV 1", "output": "2" }, { "input": "2 2 1\nH 1", "output": "2" }, { "input": "2 2 2\nV 1\nH 1", "output": "2\n1" }, { "input": "2 2 2\nH 1\nV 1", "output": "2\n1" }, { "input": "10 10 10\nV 6\nH 8\nV 4\nV 8\nH 2\nH 5\nV 9\nH 7\nH 3\nV 7", "output": "60\n48\n32\n32\n24\n12\n12\n12\n8\n8" }, { "input": "5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3", "output": "40\n40\n32\n24\n24\n24\n24\n18\n12\n8" }, { "input": "15 5 10\nV 13\nV 10\nV 3\nH 2\nV 9\nV 7\nV 2\nH 1\nV 4\nH 3", "output": "65\n50\n35\n21\n18\n12\n12\n12\n9\n6" }, { "input": "2 3 1\nH 1", "output": "4" }, { "input": "200000 200000 1\nH 1", "output": "39999800000" }, { "input": "2 4 1\nH 2", "output": "4" } ]
1,427,740,677
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
819,200
from sys import stdin, stdout import bisect v_max,h_max,cnt = map(int, stdin.readline().split()) v = [0,v_max] v_c = [v_max] h = [0,h_max] h_c = [h_max] for _ in range(cnt): d,c = stdin.readline().split() cur, cur_c = ((v,v_c) , (h,h_c))[d=='H'] bisect.insort(cur, int(c)) pos = bisect.bisect_left(cur, int(c)) cur_c[pos-1] = cur[pos]-cur[pos-1] cur_c.insert(pos, cur[pos+1]-cur[pos]) h_max, v_max = max(h_c), max(v_c) stdout.write(str(h_max*v_max)+'\n')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments. After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process. Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree? Input Specification: The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000). Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance *x* (1<=≤<=*x*<=≤<=*w*<=-<=1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts. Output Specification: After each cut print on a single line the area of the maximum available glass fragment in mm2. Demo Input: ['4 3 4\nH 2\nV 2\nV 3\nV 1\n', '7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n'] Demo Output: ['8\n4\n4\n2\n', '28\n16\n12\n6\n4\n'] Note: Picture for the first sample test:
```python from sys import stdin, stdout import bisect v_max,h_max,cnt = map(int, stdin.readline().split()) v = [0,v_max] v_c = [v_max] h = [0,h_max] h_c = [h_max] for _ in range(cnt): d,c = stdin.readline().split() cur, cur_c = ((v,v_c) , (h,h_c))[d=='H'] bisect.insort(cur, int(c)) pos = bisect.bisect_left(cur, int(c)) cur_c[pos-1] = cur[pos]-cur[pos-1] cur_c.insert(pos, cur[pos+1]-cur[pos]) h_max, v_max = max(h_c), max(v_c) stdout.write(str(h_max*v_max)+'\n') ```
0
888
A
Local Extrema
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*a**i*<=-<=1 and *a**i*<=&gt;<=*a**i*<=+<=1). Since *a*1 and *a**n* have only one neighbour each, they are neither local minima nor local maxima. An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*.
Print the number of local extrema in the given array.
[ "3\n1 2 3\n", "4\n1 5 2 5\n" ]
[ "0\n", "2\n" ]
none
0
[ { "input": "3\n1 2 3", "output": "0" }, { "input": "4\n1 5 2 5", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "1\n548", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n3 2 3", "output": "1" }, { "input": "2\n1 1000", "output": "0" }, { "input": "3\n1 2 1", "output": "1" } ]
1,676,460,962
2,147,483,647
PyPy 3-64
OK
TESTS
14
46
0
n = int(input()) *a, = map(int, input().split()) cnt = 0 for i in range(1, n - 1): if a[i - 1] > a[i] < a[i + 1] or a[i - 1] < a[i] > a[i + 1]: cnt += 1 print(cnt)
Title: Local Extrema Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*a**i*<=-<=1 and *a**i*<=&gt;<=*a**i*<=+<=1). Since *a*1 and *a**n* have only one neighbour each, they are neither local minima nor local maxima. An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. Output Specification: Print the number of local extrema in the given array. Demo Input: ['3\n1 2 3\n', '4\n1 5 2 5\n'] Demo Output: ['0\n', '2\n'] Note: none
```python n = int(input()) *a, = map(int, input().split()) cnt = 0 for i in range(1, n - 1): if a[i - 1] > a[i] < a[i + 1] or a[i - 1] < a[i] > a[i + 1]: cnt += 1 print(cnt) ```
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,595,993,583
2,147,483,647
Python 3
OK
TESTS
36
467
27,648,000
# -*- coding: utf-8 -*- """ Created on Wed Jul 29 08:53:49 2020 @author: Harshal """ n=int(input()) arr=list(map(int,input().split())) arr.sort(reverse=True) sums=sum(arr) ans=0 while len(arr)>1: ans+=sums x=arr.pop() ans+=x sums-=x print(ans+arr[0])
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 # -*- coding: utf-8 -*- """ Created on Wed Jul 29 08:53:49 2020 @author: Harshal """ n=int(input()) arr=list(map(int,input().split())) arr.sort(reverse=True) sums=sum(arr) ans=0 while len(arr)>1: ans+=sums x=arr.pop() ans+=x sums-=x print(ans+arr[0]) ```
3
841
B
Godsend
PROGRAMMING
1,100
[ "games", "math" ]
null
null
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array. Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
[ "4\n1 3 2 3\n", "2\n2 2\n" ]
[ "First\n", "Second\n" ]
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
1,000
[ { "input": "4\n1 3 2 3", "output": "First" }, { "input": "2\n2 2", "output": "Second" }, { "input": "4\n2 4 6 8", "output": "Second" }, { "input": "5\n1 1 1 1 1", "output": "First" }, { "input": "4\n720074544 345031254 849487632 80870826", "output": "Second" }, { "input": "1\n0", "output": "Second" }, { "input": "1\n999999999", "output": "First" }, { "input": "2\n1 999999999", "output": "First" }, { "input": "4\n3 3 4 4", "output": "First" }, { "input": "2\n1 2", "output": "First" }, { "input": "8\n2 2 2 1 1 2 2 2", "output": "First" }, { "input": "5\n3 3 2 2 2", "output": "First" }, { "input": "4\n0 1 1 0", "output": "First" }, { "input": "3\n1 2 2", "output": "First" }, { "input": "6\n2 2 1 1 4 2", "output": "First" }, { "input": "8\n2 2 2 3 3 2 2 2", "output": "First" }, { "input": "4\n2 3 3 4", "output": "First" }, { "input": "10\n2 2 2 2 3 1 2 2 2 2", "output": "First" }, { "input": "6\n2 2 1 1 2 2", "output": "First" }, { "input": "3\n1 1 2", "output": "First" }, { "input": "6\n2 4 3 3 4 6", "output": "First" }, { "input": "6\n4 4 3 3 4 4", "output": "First" }, { "input": "4\n1 1 2 2", "output": "First" }, { "input": "4\n1 3 5 7", "output": "First" }, { "input": "4\n2 1 1 2", "output": "First" }, { "input": "4\n1 3 3 2", "output": "First" }, { "input": "5\n3 2 2 2 2", "output": "First" }, { "input": "3\n2 1 1", "output": "First" }, { "input": "4\n1000000000 1000000000 1000000000 99999999", "output": "First" }, { "input": "4\n2 2 1 1", "output": "First" }, { "input": "5\n2 3 2 3 2", "output": "First" }, { "input": "1\n1", "output": "First" }, { "input": "4\n1000000000 1000000000 1000000000 1", "output": "First" }, { "input": "5\n2 2 2 1 1", "output": "First" }, { "input": "6\n2 1 1 1 1 2", "output": "First" }, { "input": "6\n1 2 2 2 2 1", "output": "First" }, { "input": "11\n2 2 2 2 2 1 2 2 2 2 2", "output": "First" }, { "input": "5\n1 3 2 2 2", "output": "First" }, { "input": "3\n2 3 2", "output": "First" }, { "input": "2\n1 1", "output": "First" }, { "input": "5\n4 4 4 3 3", "output": "First" }, { "input": "5\n3 3 4 4 4", "output": "First" }, { "input": "1\n2", "output": "Second" } ]
1,608,561,846
2,147,483,647
Python 3
OK
TESTS
88
920
57,241,600
n = int(input()) a = input() uneven = False s = 0 for i in a.split(): v = int(i) if v % 2: uneven = True s += v if s % 2 or uneven: print('First') else: print('Second')
Title: Godsend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally? Input Specification: First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array. Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). Demo Input: ['4\n1 3 2 3\n', '2\n2 2\n'] Demo Output: ['First\n', 'Second\n'] Note: In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
```python n = int(input()) a = input() uneven = False s = 0 for i in a.split(): v = int(i) if v % 2: uneven = True s += v if s % 2 or uneven: print('First') else: print('Second') ```
3
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,684,330,469
2,147,483,647
PyPy 3-64
OK
TESTS
34
124
0
x=list(map(int,input().split(" "))) count=0 l=[] for i in x: if i not in l: l.append(i) else: count+=1 print(count)
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 x=list(map(int,input().split(" "))) count=0 l=[] for i in x: if i not in l: l.append(i) else: count+=1 print(count) ```
3
463
B
Caisa and Pylons
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
[ "5\n3 4 3 2 4\n", "3\n4 4 4\n" ]
[ "4\n", "4\n" ]
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
1,000
[ { "input": "5\n3 4 3 2 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404 1528 2352 138 2065 3047 3656 2188 2919 2616 2083 1280 2977 2681 548 4000 1667 1489 1109 3164 1565 2653 3260 3463 903 1824 3679 2308 245 2689 2063 648 568 766 785 2984 3812 440 1172 2730", "output": "4000" }, { "input": "68\n477 1931 3738 3921 2306 1823 3328 2057 661 3993 2967 3520 171 1739 1525 1817 209 3475 1902 2666 518 3283 3412 3040 3383 2331 1147 1460 1452 1800 1327 2280 82 1416 2200 2388 3238 1879 796 250 1872 114 121 2042 1853 1645 211 2061 1472 2464 726 1989 1746 489 1380 1128 2819 2527 2939 622 678 265 2902 1111 2032 1453 3850 1621", "output": "3993" }, { "input": "30\n30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "30" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n69", "output": "69" } ]
1,621,781,673
2,147,483,647
Python 3
OK
TESTS
49
140
7,577,600
n=int(input()) a=[0]+list(map(int,input().split())) s=0 x=0 for i in range(n): s+=a[i]-a[i+1] if s<0: x+=abs(s) s=0 print(x) ''' max(a) '''
Title: Caisa and Pylons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. Output Specification: Print a single number representing the minimum number of dollars paid by Caisa. Demo Input: ['5\n3 4 3 2 4\n', '3\n4 4 4\n'] Demo Output: ['4\n', '4\n'] Note: In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
```python n=int(input()) a=[0]+list(map(int,input().split())) s=0 x=0 for i in range(n): s+=a[i]-a[i+1] if s<0: x+=abs(s) s=0 print(x) ''' max(a) ''' ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "4\nRBBR", "output": "1" }, { "input": "5\nRGGBG", "output": "1" }, { "input": "10\nGGBRBRGGRB", "output": "2" }, { "input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "output": "18" }, { "input": "15\nBRRBRGGBBRRRRGR", "output": "6" }, { "input": "20\nRRGBBRBRGRGBBGGRGRRR", "output": "6" }, { "input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "output": "6" }, { "input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "output": "9" }, { "input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB", "output": "14" }, { "input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG", "output": "20" }, { "input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG", "output": "11" }, { "input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG", "output": "17" }, { "input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB", "output": "16" }, { "input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG", "output": "19" }, { "input": "10\nGRRBRBRBGR", "output": "1" }, { "input": "10\nBRBGBGRRBR", "output": "1" }, { "input": "20\nGBGBGGRRRRGRBBGRGRGR", "output": "5" }, { "input": "20\nRRGGRBBGBBRBGRRBRRBG", "output": "6" }, { "input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB", "output": "8" }, { "input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB", "output": "11" }, { "input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB", "output": "9" }, { "input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG", "output": "13" }, { "input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG", "output": "13" }, { "input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB", "output": "12" }, { "input": "2\nBB", "output": "1" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "49" }, { "input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "47" }, { "input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR", "output": "43" } ]
1,695,284,948
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
number_of_stones = int(input()) s = "" neighboor = 0 for index in range(number_of_stones): s += input() if index == 0: continue if s[index] == s[index - 1]: neighboor += 1 print(neighboor)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python number_of_stones = int(input()) s = "" neighboor = 0 for index in range(number_of_stones): s += input() if index == 0: continue if s[index] == s[index - 1]: neighboor += 1 print(neighboor) ```
-1
656
G
You're a Professional
PROGRAMMING
1,900
[ "*special" ]
null
null
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends.
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
Output an integer — the number of items liked by at least *T* of user's friends.
[ "3 3 2\nYYY\nNNN\nYNY\n", "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n" ]
[ "2\n", "4\n" ]
none
0
[ { "input": "3 3 2\nYYY\nNNN\nYNY", "output": "2" }, { "input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN", "output": "4" }, { "input": "3 5 2\nNYNNY\nYNNNN\nNNYYN", "output": "0" }, { "input": "1 10 1\nYYYNYNNYNN", "output": "5" }, { "input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN", "output": "0" }, { "input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN", "output": "0" }, { "input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY", "output": "10" }, { "input": "8 9 1\nNYNNYYYYN\nNNNYNYNNY\nYYNYNYNNN\nNYYYNYNNN\nYNYNYNYYN\nYYNNYYYYY\nYYYYNYNYY\nNYYNNYYYY", "output": "9" }, { "input": "5 2 3\nNN\nNY\nYY\nNN\nNY", "output": "1" }, { "input": "6 4 5\nYNNY\nNYYY\nNNNY\nYNYN\nYYYN\nYNNY", "output": "0" }, { "input": "6 1 3\nY\nY\nY\nY\nY\nN", "output": "1" }, { "input": "6 2 2\nYN\nNN\nYN\nNN\nYN\nNN", "output": "1" }, { "input": "2 4 2\nNYNY\nNYNY", "output": "2" }, { "input": "9 6 3\nNYYYYN\nNNNYYN\nYYYYYY\nNYNNNN\nYNNYNY\nNNNNNY\nYNNYNN\nYYYYNY\nNNYYYY", "output": "6" }, { "input": "6 9 6\nYYYYNYNNN\nYNNYNNNYN\nNYYYNNNYY\nNYYYNNNNY\nYYNYNNNYY\nYYYNYYNNN", "output": "0" }, { "input": "9 7 8\nYNNNNYN\nNNNYYNN\nNNYYYNY\nNYYNYYY\nNNYYNYN\nNYYYNNY\nYYNYNYY\nNYYYYYY\nNNYYNYN", "output": "0" }, { "input": "9 1 6\nN\nN\nY\nN\nY\nY\nY\nY\nY", "output": "1" }, { "input": "7 7 2\nNNYNNYN\nNNNYYNY\nNNNYYNY\nYNNNNNY\nNNYNYYY\nYYNNYYN\nNNYYYNY", "output": "6" }, { "input": "8 4 2\nYNYY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN", "output": "4" }, { "input": "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY", "output": "2" }, { "input": "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN", "output": "2" }, { "input": "3 1 1\nN\nY\nN", "output": "1" }, { "input": "7 1 3\nY\nY\nY\nN\nY\nY\nY", "output": "1" }, { "input": "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY", "output": "1" }, { "input": "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN", "output": "0" }, { "input": "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN", "output": "4" }, { "input": "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN", "output": "3" }, { "input": "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY", "output": "5" }, { "input": "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY", "output": "2" }, { "input": "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN", "output": "1" }, { "input": "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN", "output": "3" }, { "input": "1 3 1\nYYN", "output": "2" }, { "input": "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY", "output": "4" } ]
1,460,121,080
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
0
0
a,b,c=map(int,input().split())#kitten z=[0]*b for i in range(a): s=input() for j in range(len(s)): if s[j]=='Y': z[j]+=1 print(sum(map(lambda x:x>=c,z)))
Title: You're a Professional Time Limit: None seconds Memory Limit: None megabytes Problem Description: A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends. Input Specification: The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise. Output Specification: Output an integer — the number of items liked by at least *T* of user's friends. Demo Input: ['3 3 2\nYYY\nNNN\nYNY\n', '4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n'] Demo Output: ['2\n', '4\n'] Note: none
```python a,b,c=map(int,input().split())#kitten z=[0]*b for i in range(a): s=input() for j in range(len(s)): if s[j]=='Y': z[j]+=1 print(sum(map(lambda x:x>=c,z))) ```
0
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves.
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "output": "53" }, { "input": "1\n124", "output": "124" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 1 1000", "output": "1" }, { "input": "2\n322 322", "output": "322" }, { "input": "3\n9 92 12", "output": "12" }, { "input": "3\n1 2 2", "output": "2" } ]
1,634,657,852
2,147,483,647
Python 3
OK
TESTS
35
62
0
a = int(input()) b = list(map(int, input().split())) for i in range(a -1): if i % 2 == 0: b.remove(max(b)) else: b.remove(min(b)) print(b[0])
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves. Input Specification: The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). Output Specification: Print one number that will be left on the board. Demo Input: ['3\n2 1 3\n', '3\n2 2 2\n'] Demo Output: ['2', '2'] Note: In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
```python a = int(input()) b = list(map(int, input().split())) for i in range(a -1): if i % 2 == 0: b.remove(max(b)) else: b.remove(min(b)) print(b[0]) ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, { "input": "1022 584 112", "output": "380" }, { "input": "66 174 319", "output": "184" }, { "input": "912 276 1748", "output": "444" }, { "input": "65 156 60", "output": "120" }, { "input": "1 10000 10000", "output": "40008" }, { "input": "1485 55 27", "output": "332" }, { "input": "152 108 4104", "output": "528" }, { "input": "1656 6900 1350", "output": "740" }, { "input": "12 14 42", "output": "60" }, { "input": "615 18 1230", "output": "856" }, { "input": "680 60 408", "output": "336" }, { "input": "644 966 6", "output": "1308" }, { "input": "1 432 432", "output": "1736" }, { "input": "2239 2239 1", "output": "8964" }, { "input": "4106 8212 2", "output": "16436" }, { "input": "10000 10000 10000", "output": "1200" }, { "input": "3623 3623 1", "output": "14500" }, { "input": "9801 9801 9801", "output": "1188" }, { "input": "10000 1 10000", "output": "40008" }, { "input": "9 9 9", "output": "36" }, { "input": "9801 9702 9702", "output": "1184" } ]
1,649,270,550
2,147,483,647
Python 3
OK
TESTS
27
92
0
import math arr = list(map(int, input().split())) s1 = math.sqrt(arr[0] * arr[1] / arr[2]) s2 = math.sqrt(arr[2] * arr[0] / arr[1]) s3 = math.sqrt(arr[2] * arr[1] / arr[0]) print(int(4*(s1+s2+s3)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input Specification: The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. Output Specification: Print a single number — the sum of all edges of the parallelepiped. Demo Input: ['1 1 1\n', '4 6 6\n'] Demo Output: ['12\n', '28\n'] Note: In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
```python import math arr = list(map(int, input().split())) s1 = math.sqrt(arr[0] * arr[1] / arr[2]) s2 = math.sqrt(arr[2] * arr[0] / arr[1]) s3 = math.sqrt(arr[2] * arr[1] / arr[0]) print(int(4*(s1+s2+s3))) ```
3
592
B
The Monster and the Squirrel
PROGRAMMING
1,100
[ "math" ]
null
null
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel. Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,<=3,<=...,<=*n* (in this particular order). And then she puts a walnut in each region inside the polygon. Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner. Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
The first and only line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=54321) - the number of vertices of the regular polygon drawn by Ari.
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
[ "5\n", "3\n" ]
[ "9\n", "1\n" ]
One of the possible solutions for the first sample is shown on the picture above.
1,000
[ { "input": "5", "output": "9" }, { "input": "3", "output": "1" }, { "input": "54321", "output": "2950553761" }, { "input": "4", "output": "4" }, { "input": "6", "output": "16" }, { "input": "7", "output": "25" }, { "input": "8", "output": "36" }, { "input": "9", "output": "49" }, { "input": "10", "output": "64" }, { "input": "54320", "output": "2950445124" }, { "input": "54319", "output": "2950336489" }, { "input": "54318", "output": "2950227856" }, { "input": "54317", "output": "2950119225" }, { "input": "54316", "output": "2950010596" }, { "input": "54315", "output": "2949901969" }, { "input": "54314", "output": "2949793344" }, { "input": "8153", "output": "66438801" }, { "input": "51689", "output": "2671545969" }, { "input": "16659", "output": "277455649" }, { "input": "47389", "output": "2245527769" }, { "input": "314", "output": "97344" }, { "input": "23481", "output": "551263441" }, { "input": "20380", "output": "415262884" }, { "input": "1994", "output": "3968064" } ]
1,616,284,375
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
if bruh == 6 print("bruhhh")
Title: The Monster and the Squirrel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel. Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,<=3,<=...,<=*n* (in this particular order). And then she puts a walnut in each region inside the polygon. Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner. Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts? Input Specification: The first and only line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=54321) - the number of vertices of the regular polygon drawn by Ari. Output Specification: Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after. Demo Input: ['5\n', '3\n'] Demo Output: ['9\n', '1\n'] Note: One of the possible solutions for the first sample is shown on the picture above.
```python if bruh == 6 print("bruhhh") ```
-1
279
B
Books
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation", "two pointers" ]
null
null
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book. Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read.
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Print a single integer — the maximum number of books Valera can read.
[ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ]
[ "3\n", "1\n" ]
none
1,000
[ { "input": "4 5\n3 1 2 1", "output": "3" }, { "input": "3 3\n2 2 3", "output": "1" }, { "input": "1 3\n5", "output": "0" }, { "input": "1 10\n4", "output": "1" }, { "input": "2 10\n6 4", "output": "2" }, { "input": "6 10\n2 3 4 2 1 1", "output": "4" }, { "input": "7 13\n6 8 14 9 4 11 10", "output": "2" }, { "input": "10 15\n10 9 1 1 5 10 5 3 7 2", "output": "3" }, { "input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4", "output": "6" }, { "input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19", "output": "4" }, { "input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52", "output": "3" }, { "input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708", "output": "0" }, { "input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550", "output": "1" } ]
1,684,783,776
2,147,483,647
PyPy 3-64
OK
TESTS
38
218
13,824,000
n,t=map(int,input().split()) times=list(map(int,input().split())) from itertools import accumulate from bisect import bisect_right times=list(accumulate(times,initial=0)) res=0 for i in range(n): res=max(res,bisect_right(times,t+times[i])-(i+1)) print(res)
Title: Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book. Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. Output Specification: Print a single integer — the maximum number of books Valera can read. Demo Input: ['4 5\n3 1 2 1\n', '3 3\n2 2 3\n'] Demo Output: ['3\n', '1\n'] Note: none
```python n,t=map(int,input().split()) times=list(map(int,input().split())) from itertools import accumulate from bisect import bisect_right times=list(accumulate(times,initial=0)) res=0 for i in range(n): res=max(res,bisect_right(times,t+times[i])-(i+1)) print(res) ```
3
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,690,457,021
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n=int(input('Enter the weight of the wateemelon')) if n%2==0 and n!=2: print('Yes') else: print('No')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python n=int(input('Enter the weight of the wateemelon')) if n%2==0 and n!=2: print('Yes') else: print('No') ```
0
0
none
none
none
0
[ "none" ]
null
null
One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer number $c_j$ of artificial resource units. In order for production to work, it is needed to deploy two services $S_1$ and $S_2$ to process incoming requests using the servers of the department. Processing of incoming requests of service $S_i$ takes $x_i$ resource units. The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service $S_i$ is deployed using $k_i$ servers, then the load is divided equally between these servers and each server requires only $x_i / k_i$ (that may be a fractional number) resource units. Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides. Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
The first line contains three integers $n$, $x_1$, $x_2$ ($2 \leq n \leq 300\,000$, $1 \leq x_1, x_2 \leq 10^9$) — the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $n$ space-separated integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq 10^9$) — the number of resource units provided by each of the servers.
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $k_1$ and $k_2$ ($1 \leq k_1, k_2 \leq n$) — the number of servers used for each of the services. In the third line print $k_1$ integers, the indices of the servers that will be used for the first service. In the fourth line print $k_2$ integers, the indices of the servers that will be used for the second service. No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
[ "6 8 16\n3 5 2 9 8 7\n", "4 20 32\n21 11 11 12\n", "4 11 32\n5 5 16 16\n", "5 12 20\n7 8 4 11 9\n" ]
[ "Yes\n3 2\n1 2 6\n5 4", "Yes\n1 3\n1\n2 3 4\n", "No\n", "No\n" ]
In the first sample test each of the servers 1, 2 and 6 will will provide $8 / 3 = 2.(6)$ resource units and each of the servers 5, 4 will provide $16 / 2 = 8$ resource units. In the second sample test the first server will provide $20$ resource units and each of the remaining servers will provide $32 / 3 = 10.(6)$ resource units.
0
[ { "input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n4 2\n3 1 2 6\n5 4" }, { "input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4" }, { "input": "4 11 32\n5 5 16 16", "output": "No" }, { "input": "5 12 20\n7 8 4 11 9", "output": "No" }, { "input": "2 1 1\n1 1", "output": "Yes\n1 1\n1\n2" }, { "input": "2 1 1\n1 1000000", "output": "Yes\n1 1\n1\n2" }, { "input": "2 1 1\n1000000000 1000000000", "output": "Yes\n1 1\n1\n2" }, { "input": "2 1 2\n1 1", "output": "No" }, { "input": "15 250 200\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41", "output": "Yes\n11 3\n13 10 8 15 6 7 12 4 1 9 3\n11 14 5" }, { "input": "4 12 11\n4 4 6 11", "output": "Yes\n3 1\n1 2 3\n4" } ]
1,525,497,451
2,147,483,647
Python 3
OK
TESTS
40
1,668
39,014,400
import sys n,x1,x2=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]=[a[i],i+1] a.sort() #print(a) for i in range(1,n+1): if(a[n-i][0]*(i)>=x1): break pt=i #print(pt) ans=-1 for i in range(pt+1,n+1): if(a[n-i][0]*(i-pt)>=x2): ans=i break if(ans!=-1): print('Yes') print(pt,ans-pt) b=[] c=[] for i in range(n-1,n-1-pt,-1): b.append(a[i][1]) for i in range(n-1-pt,n-1-ans,-1): c.append(a[i][1]) print(*b) print(*c) sys.exit() for i in range(1,n+1): if(a[n-i][0]*(i)>=x2): break pt=i ans=-1 for i in range(pt+1,n+1): if(a[n-i][0]*(i-pt)>=x1): ans=i break #print(pt) if(ans!=-1): print('Yes') print(ans-pt,pt) b=[] for i in range(n-1-pt,n-1-ans,-1): b.append(a[i][1]) c=[] for i in range(n-1,n-1-pt,-1): c.append(a[i][1]) print(*b) print(*c) sys.exit() print('No')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer number $c_j$ of artificial resource units. In order for production to work, it is needed to deploy two services $S_1$ and $S_2$ to process incoming requests using the servers of the department. Processing of incoming requests of service $S_i$ takes $x_i$ resource units. The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service $S_i$ is deployed using $k_i$ servers, then the load is divided equally between these servers and each server requires only $x_i / k_i$ (that may be a fractional number) resource units. Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides. Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services. Input Specification: The first line contains three integers $n$, $x_1$, $x_2$ ($2 \leq n \leq 300\,000$, $1 \leq x_1, x_2 \leq 10^9$) — the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $n$ space-separated integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq 10^9$) — the number of resource units provided by each of the servers. Output Specification: If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $k_1$ and $k_2$ ($1 \leq k_1, k_2 \leq n$) — the number of servers used for each of the services. In the third line print $k_1$ integers, the indices of the servers that will be used for the first service. In the fourth line print $k_2$ integers, the indices of the servers that will be used for the second service. No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them. Demo Input: ['6 8 16\n3 5 2 9 8 7\n', '4 20 32\n21 11 11 12\n', '4 11 32\n5 5 16 16\n', '5 12 20\n7 8 4 11 9\n'] Demo Output: ['Yes\n3 2\n1 2 6\n5 4', 'Yes\n1 3\n1\n2 3 4\n', 'No\n', 'No\n'] Note: In the first sample test each of the servers 1, 2 and 6 will will provide $8 / 3 = 2.(6)$ resource units and each of the servers 5, 4 will provide $16 / 2 = 8$ resource units. In the second sample test the first server will provide $20$ resource units and each of the remaining servers will provide $32 / 3 = 10.(6)$ resource units.
```python import sys n,x1,x2=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]=[a[i],i+1] a.sort() #print(a) for i in range(1,n+1): if(a[n-i][0]*(i)>=x1): break pt=i #print(pt) ans=-1 for i in range(pt+1,n+1): if(a[n-i][0]*(i-pt)>=x2): ans=i break if(ans!=-1): print('Yes') print(pt,ans-pt) b=[] c=[] for i in range(n-1,n-1-pt,-1): b.append(a[i][1]) for i in range(n-1-pt,n-1-ans,-1): c.append(a[i][1]) print(*b) print(*c) sys.exit() for i in range(1,n+1): if(a[n-i][0]*(i)>=x2): break pt=i ans=-1 for i in range(pt+1,n+1): if(a[n-i][0]*(i-pt)>=x1): ans=i break #print(pt) if(ans!=-1): print('Yes') print(ans-pt,pt) b=[] for i in range(n-1-pt,n-1-ans,-1): b.append(a[i][1]) c=[] for i in range(n-1,n-1-pt,-1): c.append(a[i][1]) print(*b) print(*c) sys.exit() print('No') ```
3
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*.
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces.
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1", "output": "6" }, { "input": "15\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": "5\n1 0\n1 0\n1 0\n0 1\n0 1", "output": "4" } ]
1,610,720,224
2,147,483,647
Python 3
OK
TESTS
57
156
512,000
n = int(input()) one = [] two = [] for i in range(n): x, y = map(int, input().split(" ")) one.append(x) two.append(y) if one.count(0) > one.count(1): c_1 = one.count(1) else: c_1 = one.count(0) if two.count(0) > two.count(1): c_2 = two.count(1) else: c_2 = two.count(0) print(c_1 + c_2)
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*. Input Specification: The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces. Output Specification: In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. Demo Input: ['5\n0 1\n1 0\n0 1\n1 1\n0 1\n'] Demo Output: ['3\n'] Note: none
```python n = int(input()) one = [] two = [] for i in range(n): x, y = map(int, input().split(" ")) one.append(x) two.append(y) if one.count(0) > one.count(1): c_1 = one.count(1) else: c_1 = one.count(0) if two.count(0) > two.count(1): c_2 = two.count(1) else: c_2 = two.count(0) print(c_1 + c_2) ```
3
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,644,985,055
2,147,483,647
Python 3
OK
TESTS
43
46
0
s = input() res = 0 n = len(s) for i in range(1, n - 1): if s[i] == 'A': l = i - 1 r = i + 1 a = 0 b = 0 while l >= 0: if s[l] == 'Q': a += 1 l -= 1 while r < n: if s[r] == 'Q': b += 1 r += 1 res += a*b print(res)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python s = input() res = 0 n = len(s) for i in range(1, n - 1): if s[i] == 'A': l = i - 1 r = i + 1 a = 0 b = 0 while l >= 0: if s[l] == 'Q': a += 1 l -= 1 while r < n: if s[r] == 'Q': b += 1 r += 1 res += a*b print(res) ```
3
39
H
Multiplication Table
PROGRAMMING
1,300
[ "implementation" ]
H. Multiplication Table
2
64
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix *k*.
The first line contains a single integer *k* (2<=≤<=*k*<=≤<=10) — the radix of the system.
Output the multiplication table for the system of notations with the radix *k*. The table must contain *k*<=-<=1 rows and *k*<=-<=1 columns. The element on the crossing of the *i*-th row and the *j*-th column is equal to the product of *i* and *j* in the system of notations with the radix *k*. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity).
[ "10\n", "3\n" ]
[ "1 2 3 4 5 6 7 8 9\n2 4 6 8 10 12 14 16 18\n3 6 9 12 15 18 21 24 27\n4 8 12 16 20 24 28 32 36\n5 10 15 20 25 30 35 40 45\n6 12 18 24 30 36 42 48 54\n7 14 21 28 35 42 49 56 63\n8 16 24 32 40 48 56 64 72\n9 18 27 36 45 54 63 72 81\n", "1 2\n2 11" ]
none
0
[ { "input": "10", "output": "1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7 14 21 28 35 42 49 56 63 \n8 16 24 32 40 48 56 64 72 \n9 18 27 36 45 54 63 72 81 " }, { "input": "3", "output": "1 2 \n2 11 " }, { "input": "2", "output": "1 " }, { "input": "4", "output": "1 2 3 \n2 10 12 \n3 12 21 " }, { "input": "5", "output": "1 2 3 4 \n2 4 11 13 \n3 11 14 22 \n4 13 22 31 " }, { "input": "6", "output": "1 2 3 4 5 \n2 4 10 12 14 \n3 10 13 20 23 \n4 12 20 24 32 \n5 14 23 32 41 " }, { "input": "7", "output": "1 2 3 4 5 6 \n2 4 6 11 13 15 \n3 6 12 15 21 24 \n4 11 15 22 26 33 \n5 13 21 26 34 42 \n6 15 24 33 42 51 " }, { "input": "8", "output": "1 2 3 4 5 6 7 \n2 4 6 10 12 14 16 \n3 6 11 14 17 22 25 \n4 10 14 20 24 30 34 \n5 12 17 24 31 36 43 \n6 14 22 30 36 44 52 \n7 16 25 34 43 52 61 " }, { "input": "9", "output": "1 2 3 4 5 6 7 8 \n2 4 6 8 11 13 15 17 \n3 6 10 13 16 20 23 26 \n4 8 13 17 22 26 31 35 \n5 11 16 22 27 33 38 44 \n6 13 20 26 33 40 46 53 \n7 15 23 31 38 46 54 62 \n8 17 26 35 44 53 62 71 " } ]
1,632,757,733
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
6,963,200
k = int(input("")) n = k-1 if n == 1: print("1") elif n ==2 : print("1 2") print("2 11") elif n == 3 : print("1 2 3") print("2 10 12") print("3 12 21") elif n == 4: print("1 2 3 4") print("2 4 11 13") print("3 11 14 22") print("4 13 22 31") elif n == 5: print("1 2 3 4 5") print("2 4 10 12 14") print("3 10 13 20 23") print("4 12 20 24 32") print("5 14 23 32 41") elif n == 6: print("1 2 3 4 5 6") print("2 4 6 11 13 15") print("3 6 12 15 21 24") print("4 11 15 22 26 33") print("5 13 21 26 34 42") print("6 15 24 33 42 51") elif n == 7: print("1 2 3 4 5 6 7") print("2 4 6 10 12 14 16") print("3 6 11 14 17 22 25") print("4 10 14 20 24 30 34") print("5 12 17 24 31 36 43") print("6 14 22 30 36 42 52") print("7 16 25 34 43 52 61") elif n == 8: print("1 2 3 4 5 6 7 8") print("2 4 6 8 11 13 15 17") print("3 6 10 13 16 20 23 26") print("4 8 13 17 22 26 31 35") print("5 11 16 22 27 33 38 44") print("6 13 20 26 33 40 46 53") print("7 15 23 31 38 46 54 62") print("8 17 26 35 40 53 62 71") else: print("1 2 3 4 5 6 7 8 9") print("2 4 6 8 10 12 14 16 18") print("3 6 9 12 15 18 21 24 27") print("4 8 12 16 20 24 28 32 36") print("5 10 15 20 25 30 35 40 45") print("6 12 18 24 30 36 42 48 54") print("7 14 21 28 35 42 49 56 63") print("8 16 24 32 40 48 56 64 72") print("9 18 27 36 45 54 63 72 81")
Title: Multiplication Table Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix *k*. Input Specification: The first line contains a single integer *k* (2<=≤<=*k*<=≤<=10) — the radix of the system. Output Specification: Output the multiplication table for the system of notations with the radix *k*. The table must contain *k*<=-<=1 rows and *k*<=-<=1 columns. The element on the crossing of the *i*-th row and the *j*-th column is equal to the product of *i* and *j* in the system of notations with the radix *k*. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity). Demo Input: ['10\n', '3\n'] Demo Output: ['1 2 3 4 5 6 7 8 9\n2 4 6 8 10 12 14 16 18\n3 6 9 12 15 18 21 24 27\n4 8 12 16 20 24 28 32 36\n5 10 15 20 25 30 35 40 45\n6 12 18 24 30 36 42 48 54\n7 14 21 28 35 42 49 56 63\n8 16 24 32 40 48 56 64 72\n9 18 27 36 45 54 63 72 81\n', '1 2\n2 11'] Note: none
```python k = int(input("")) n = k-1 if n == 1: print("1") elif n ==2 : print("1 2") print("2 11") elif n == 3 : print("1 2 3") print("2 10 12") print("3 12 21") elif n == 4: print("1 2 3 4") print("2 4 11 13") print("3 11 14 22") print("4 13 22 31") elif n == 5: print("1 2 3 4 5") print("2 4 10 12 14") print("3 10 13 20 23") print("4 12 20 24 32") print("5 14 23 32 41") elif n == 6: print("1 2 3 4 5 6") print("2 4 6 11 13 15") print("3 6 12 15 21 24") print("4 11 15 22 26 33") print("5 13 21 26 34 42") print("6 15 24 33 42 51") elif n == 7: print("1 2 3 4 5 6 7") print("2 4 6 10 12 14 16") print("3 6 11 14 17 22 25") print("4 10 14 20 24 30 34") print("5 12 17 24 31 36 43") print("6 14 22 30 36 42 52") print("7 16 25 34 43 52 61") elif n == 8: print("1 2 3 4 5 6 7 8") print("2 4 6 8 11 13 15 17") print("3 6 10 13 16 20 23 26") print("4 8 13 17 22 26 31 35") print("5 11 16 22 27 33 38 44") print("6 13 20 26 33 40 46 53") print("7 15 23 31 38 46 54 62") print("8 17 26 35 40 53 62 71") else: print("1 2 3 4 5 6 7 8 9") print("2 4 6 8 10 12 14 16 18") print("3 6 9 12 15 18 21 24 27") print("4 8 12 16 20 24 28 32 36") print("5 10 15 20 25 30 35 40 45") print("6 12 18 24 30 36 42 48 54") print("7 14 21 28 35 42 49 56 63") print("8 16 24 32 40 48 56 64 72") print("9 18 27 36 45 54 63 72 81") ```
0
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "output": "YES" }, { "input": "1\n999993399999", "output": "NO" }, { "input": "9\n111 121 131 111 121 131 111 121 131", "output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO" }, { "input": "1\n1", "output": "NO" }, { "input": "1\n10", "output": "NO" }, { "input": "1\n976197352729", "output": "NO" }, { "input": "1\n1000000000000", "output": "NO" }, { "input": "1\n9", "output": "YES" }, { "input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n223092870 6469693230 200560490130", "output": "NO\nNO\nNO" }, { "input": "2\n81 25", "output": "NO\nYES" }, { "input": "1\n16", "output": "NO" }, { "input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "1\n225", "output": "NO" }, { "input": "1\n1521", "output": "NO" }, { "input": "1\n81", "output": "NO" } ]
1,697,434,275
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
186
3,174,400
# Version 20.0 import os, sys, math, itertools from collections import deque, defaultdict, OrderedDict, Counter from bisect import bisect, bisect_left, bisect_right, insort from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop ii = lambda : int(input()) si = lambda : input() mi = lambda : map(int,input().strip().split(" ")) msi = lambda : map(str,input().strip().split(" ")) li = lambda : list(mi()) lsi = lambda : list(msi()) out = [] export = lambda : print('\n'.join(map(str, out)), end='') p = lambda x : out.append(x) pp = lambda array : p(' '.join(map(str,array))) offline = True L = lambda string : hq.L(string) if offline == True else False LT = lambda tc, custom, string : hq.LT(tc, custom, string) if offline == True else False def main() -> None: # 2023-10-15 23:57:03 def sieve( n : int) -> list: isPrime = [True for i in range(n+1)] isPrime[0] = isPrime[1] = False for i in range(4,n+1,2): isPrime[i] = False for i in range(3,n+1,2): if i*i <= n and isPrime[i]: for j in range(i*i,n+1,i): isPrime[j] = False return [idx for idx,i in enumerate(isPrime) if i==True] primes = sieve(int(1e5)+100) def primeFactorization(num): factors = [] sqrtn = math.sqrt(num) length = len(primes) for i in range(length): if primes[i] <= sqrtn: if num % primes[i] == 0: while num % primes[i] == 0: num //= primes[i] factors.append(primes[i]) sqrtn = math.sqrt(num) else: break if num != 1: factors.append(num) return factors num = ii() l = li() for i in l: ans = primeFactorization(i) s = list(set(ans)) if len(s) == 1 and s[0] != i: p('YES') else: p('NO') try: exec('from hq import *\nexec(cc)') except (FileNotFoundError, ModuleNotFoundError): offline >> 1; main(); export()
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. Input Specification: The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. Output Specification: Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. Demo Input: ['3\n4 5 6\n'] Demo Output: ['YES\nNO\nNO\n'] Note: The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
```python # Version 20.0 import os, sys, math, itertools from collections import deque, defaultdict, OrderedDict, Counter from bisect import bisect, bisect_left, bisect_right, insort from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop ii = lambda : int(input()) si = lambda : input() mi = lambda : map(int,input().strip().split(" ")) msi = lambda : map(str,input().strip().split(" ")) li = lambda : list(mi()) lsi = lambda : list(msi()) out = [] export = lambda : print('\n'.join(map(str, out)), end='') p = lambda x : out.append(x) pp = lambda array : p(' '.join(map(str,array))) offline = True L = lambda string : hq.L(string) if offline == True else False LT = lambda tc, custom, string : hq.LT(tc, custom, string) if offline == True else False def main() -> None: # 2023-10-15 23:57:03 def sieve( n : int) -> list: isPrime = [True for i in range(n+1)] isPrime[0] = isPrime[1] = False for i in range(4,n+1,2): isPrime[i] = False for i in range(3,n+1,2): if i*i <= n and isPrime[i]: for j in range(i*i,n+1,i): isPrime[j] = False return [idx for idx,i in enumerate(isPrime) if i==True] primes = sieve(int(1e5)+100) def primeFactorization(num): factors = [] sqrtn = math.sqrt(num) length = len(primes) for i in range(length): if primes[i] <= sqrtn: if num % primes[i] == 0: while num % primes[i] == 0: num //= primes[i] factors.append(primes[i]) sqrtn = math.sqrt(num) else: break if num != 1: factors.append(num) return factors num = ii() l = li() for i in l: ans = primeFactorization(i) s = list(set(ans)) if len(s) == 1 and s[0] != i: p('YES') else: p('NO') try: exec('from hq import *\nexec(cc)') except (FileNotFoundError, ModuleNotFoundError): offline >> 1; main(); export() ```
0
73
A
The Elder Trolls IV: Oblivon
PROGRAMMING
1,600
[ "greedy", "math" ]
A. The Elder Trolls IV: Oblivon
2
256
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many! Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=×<=*y*<=×<=*z*, consisting of undestructable cells 1<=×<=1<=×<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value. All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut. Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times. Vasya's character uses absolutely thin sword with infinite length.
The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109).
Output the only number — the answer for the problem. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "2 2 2 3\n", "2 2 2 1\n" ]
[ "8", "2" ]
In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two.
500
[ { "input": "2 2 2 3", "output": "8" }, { "input": "2 2 2 1", "output": "2" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 2 3 3", "output": "6" }, { "input": "20 4 5 12", "output": "120" }, { "input": "100 500 100500 1000000000", "output": "5025000000" }, { "input": "2 5 5 9", "output": "50" }, { "input": "11 1 11 11", "output": "42" }, { "input": "100500 5000 500 100000000", "output": "251250000000" }, { "input": "2 2 2 0", "output": "1" }, { "input": "1000000 1000000 1000000 2444441", "output": "540974149875309150" }, { "input": "1000000 1000000 1000000 1000000000", "output": "1000000000000000000" }, { "input": "1000000 1000000 1000000 2999996", "output": "999999000000000000" }, { "input": "1000000 1000000 1000000 2999997", "output": "1000000000000000000" }, { "input": "999999 1000000 999997 999999999", "output": "999996000003000000" }, { "input": "500000 1000000 750000 100000", "output": "37040370459260" }, { "input": "999999 1 999998 1333333", "output": "444445555556" }, { "input": "500000 10000 1000000 29998", "output": "1000100000000" }, { "input": "10000 500000 1000000 29999", "output": "1000200010000" }, { "input": "10000 1000000 500000 29996", "output": "999900000000" }, { "input": "999999 123456 987654 0", "output": "1" }, { "input": "1 1 1 0", "output": "1" }, { "input": "219482 801483 941695 280976", "output": "821595067700400" }, { "input": "808994 288453 204353 580644", "output": "7250580779648149" }, { "input": "428676 64403 677407 626161", "output": "5081000961597840" }, { "input": "559002 326875 150818 157621", "output": "145045169133102" }, { "input": "178008 590076 624581 201286", "output": "302062187173952" }, { "input": "797745 854005 98703 735186", "output": "9996502351557447" }, { "input": "418223 118667 573175 776998", "output": "12857677898465963" }, { "input": "39436 384053 48008 313346", "output": "427693170156640" }, { "input": "661377 149342 523189 353305", "output": "1633415415004970" }, { "input": "781081 414037 495753 892089", "output": "26294515330164544" }, { "input": "402353 679460 969495 930195", "output": "29810031851367496" }, { "input": "593408 709898 624186 915570", "output": "28425961712082871" }, { "input": "1000 988 1000000 3000", "output": "1002820000" }, { "input": "91839 2 3 50", "output": "288" }, { "input": "999900 999990 4 129", "output": "16384" }, { "input": "1024 100000 4 13", "output": "144" }, { "input": "1000000 1000000 1000000 1000000000", "output": "1000000000000000000" }, { "input": "1 1000000 1 1000000000", "output": "1000000" }, { "input": "2 1000 1000000 1000000000", "output": "2000000000" }, { "input": "999999 2 1000000 1000000000", "output": "1999998000000" }, { "input": "1000 1 1 1", "output": "2" }, { "input": "1000 1 1 998", "output": "999" }, { "input": "1000 1 1 1000", "output": "1000" }, { "input": "33334 66667 1000000 100000", "output": "37040370459260" }, { "input": "1 1000000 2 23123", "output": "46246" } ]
1,597,705,115
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
248
0
a,b,c,k = map(int,input().split()) if(a==b==c==1): print(1) exit(0) a = k//3 b = k-2*a print(((a+1)**2)*(b+1))
Title: The Elder Trolls IV: Oblivon Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many! Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=×<=*y*<=×<=*z*, consisting of undestructable cells 1<=×<=1<=×<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value. All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut. Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times. Vasya's character uses absolutely thin sword with infinite length. Input Specification: The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109). Output Specification: Output the only number — the answer for the problem. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Demo Input: ['2 2 2 3\n', '2 2 2 1\n'] Demo Output: ['8', '2'] Note: In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two.
```python a,b,c,k = map(int,input().split()) if(a==b==c==1): print(1) exit(0) a = k//3 b = k-2*a print(((a+1)**2)*(b+1)) ```
0
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "2 2", "output": "3" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "4" }, { "input": "999 2", "output": "1997" }, { "input": "1000 3", "output": "1499" }, { "input": "1000 4", "output": "1333" }, { "input": "1 1000", "output": "1" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "10 4", "output": "13" }, { "input": "4 3", "output": "5" }, { "input": "91 5", "output": "113" }, { "input": "777 17", "output": "825" }, { "input": "100 4", "output": "133" }, { "input": "5 3", "output": "7" }, { "input": "6 4", "output": "7" }, { "input": "26 8", "output": "29" }, { "input": "9 4", "output": "11" }, { "input": "20 3", "output": "29" }, { "input": "17 3", "output": "25" } ]
1,649,332,590
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
a,b = map(int,input().split()) count = 0 while a>=0: count+=1 a-=1 if count%b==0: count+=1 print(count-2)
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. Input Specification: The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). Output Specification: Print a single integer — the number of hours Vasily can light up the room for. Demo Input: ['4 2\n', '6 3\n'] Demo Output: ['7\n', '8\n'] Note: Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
```python a,b = map(int,input().split()) count = 0 while a>=0: count+=1 a-=1 if count%b==0: count+=1 print(count-2) ```
0
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" }, { "input": "e1\nf2", "output": "1\nRU" }, { "input": "g4\nd2", "output": "3\nLD\nLD\nL" }, { "input": "a8\nb2", "output": "6\nRD\nD\nD\nD\nD\nD" }, { "input": "d4\nh2", "output": "4\nRD\nRD\nR\nR" }, { "input": "c5\na2", "output": "3\nLD\nLD\nD" }, { "input": "h5\nf8", "output": "3\nLU\nLU\nU" }, { "input": "e6\nb6", "output": "3\nL\nL\nL" }, { "input": "a6\ng4", "output": "6\nRD\nRD\nR\nR\nR\nR" }, { "input": "f7\nc2", "output": "5\nLD\nLD\nLD\nD\nD" }, { "input": "b7\nh8", "output": "6\nRU\nR\nR\nR\nR\nR" }, { "input": "g7\nd6", "output": "3\nLD\nL\nL" }, { "input": "c8\na3", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "h8\nf1", "output": "7\nLD\nLD\nD\nD\nD\nD\nD" }, { "input": "d1\nb7", "output": "6\nLU\nLU\nU\nU\nU\nU" }, { "input": "a7\ne5", "output": "4\nRD\nRD\nR\nR" }, { "input": "d6\nb1", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "f5\ng5", "output": "1\nR" }, { "input": "h4\nd1", "output": "4\nLD\nLD\nLD\nL" }, { "input": "b3\na5", "output": "2\nLU\nU" }, { "input": "d2\nf1", "output": "2\nRD\nR" }, { "input": "f1\nc5", "output": "4\nLU\nLU\nLU\nU" }, { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "c7\ne5", "output": "2\nRD\nRD" }, { "input": "e7\nb1", "output": "6\nLD\nLD\nLD\nD\nD\nD" }, { "input": "g8\na8", "output": "6\nL\nL\nL\nL\nL\nL" }, { "input": "g6\nf2", "output": "4\nLD\nD\nD\nD" }, { "input": "g4\nc4", "output": "4\nL\nL\nL\nL" }, { "input": "g2\na6", "output": "6\nLU\nLU\nLU\nLU\nL\nL" }, { "input": "f8\nf8", "output": "0" }, { "input": "f5\nd2", "output": "3\nLD\nLD\nD" } ]
1,689,068,239
2,147,483,647
PyPy 3
OK
TESTS
35
186
0
a = input() b = input() c = 'abcdefgh' x1, y1 = c.index(a[0]), int(a[1]) x2, y2 = c.index(b[0]), int(b[1]) print(max(abs(x1 - x2), abs(y1 - y2))) x1 += 1 x2 += 1 x = x1 y = y1 while (x != x2 or y != y2): if x < x2 and y > y2: print('RD') x += 1 y -= 1 if x > x2 and y > y2: print('LD') x -= 1 y -= 1 if x < x2 and y < y2: print('RU') x += 1 y += 1 if x > x2 and y < y2: print('LU') x -= 1 y += 1 if x == x2: if y > y2: print('D') y -= 1 elif y2 > y: print('U') y += 1 if y == y2: if x > x2: print('L') x -= 1 elif x2 > x: print('R') x += 1 # Tue Jul 11 2023 12:37:18 GMT+0300 (Moscow Standard Time)
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). Input Specification: The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. Output Specification: In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. Demo Input: ['a8\nh1\n'] Demo Output: ['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n'] Note: none
```python a = input() b = input() c = 'abcdefgh' x1, y1 = c.index(a[0]), int(a[1]) x2, y2 = c.index(b[0]), int(b[1]) print(max(abs(x1 - x2), abs(y1 - y2))) x1 += 1 x2 += 1 x = x1 y = y1 while (x != x2 or y != y2): if x < x2 and y > y2: print('RD') x += 1 y -= 1 if x > x2 and y > y2: print('LD') x -= 1 y -= 1 if x < x2 and y < y2: print('RU') x += 1 y += 1 if x > x2 and y < y2: print('LU') x -= 1 y += 1 if x == x2: if y > y2: print('D') y -= 1 elif y2 > y: print('U') y += 1 if y == y2: if x > x2: print('L') x -= 1 elif x2 > x: print('R') x += 1 # Tue Jul 11 2023 12:37:18 GMT+0300 (Moscow Standard Time) ```
3.907
137
B
Permutation
PROGRAMMING
1,000
[ "greedy" ]
null
null
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Print the only number — the minimum number of changes needed to get the permutation.
[ "3\n3 1 2\n", "2\n2 2\n", "5\n5 3 3 3 1\n" ]
[ "0\n", "1\n", "2\n" ]
The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
1,000
[ { "input": "3\n3 1 2", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "5\n5 3 3 3 1", "output": "2" }, { "input": "5\n6 6 6 6 6", "output": "5" }, { "input": "10\n1 1 2 2 8 8 7 7 9 9", "output": "5" }, { "input": "8\n9 8 7 6 5 4 3 2", "output": "1" }, { "input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5", "output": "10" }, { "input": "1\n1", "output": "0" }, { "input": "1\n5000", "output": "1" }, { "input": "4\n5000 5000 5000 5000", "output": "4" }, { "input": "5\n3366 3461 4 5 4370", "output": "3" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "0" }, { "input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9", "output": "7" }, { "input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974", "output": "10" }, { "input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5", "output": "0" }, { "input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142", "output": "15" }, { "input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27", "output": "14" }, { "input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64", "output": "18" }, { "input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604", "output": "70" }, { "input": "1\n2", "output": "1" }, { "input": "2\n5000 5000", "output": "2" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3 4", "output": "2" }, { "input": "10\n1 2 3 4 5 6 7 1000 10 10", "output": "2" } ]
1,608,803,378
2,147,483,647
Python 3
OK
TESTS
48
280
819,200
from collections import Counter n = int(input()) arr = list(map(int, input().split())) c = Counter(arr) count = 0 for i in range(1, n+1): if i not in c: count += 1 print(count)
Title: Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). Input Specification: The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). Output Specification: Print the only number — the minimum number of changes needed to get the permutation. Demo Input: ['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n'] Demo Output: ['0\n', '1\n', '2\n'] Note: The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
```python from collections import Counter n = int(input()) arr = list(map(int, input().split())) c = Counter(arr) count = 0 for i in range(1, n+1): if i not in c: count += 1 print(count) ```
3
526
A
King of Thieves
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level. A dungeon consists of *n* segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'. One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number *i*1, he can make a sequence of jumps through the platforms *i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**k*, if *i*2<=-<=*i*1<==<=*i*3<=-<=*i*2<==<=...<==<=*i**k*<=-<=*i**k*<=-<=1. Of course, all segments *i*1,<=*i*2,<=... *i**k* should be exactly the platforms, not pits. Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence *i*1,<=*i*2,<=...,<=*i*5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level. Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'.
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
[ "16\n.**.*..*.***.**.\n", "11\n.*.*...*.*.\n" ]
[ "yes", "no" ]
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
500
[ { "input": "16\n.**.*..*.***.**.", "output": "yes" }, { "input": "11\n.*.*...*.*.", "output": "no" }, { "input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.", "output": "yes" }, { "input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**", "output": "yes" }, { "input": "56\n**.*..*...***.*.**.**..**.*.*.*.**...*.**.**....*...**..", "output": "yes" }, { "input": "64\n***.*...*...*.***.....*.....**.*****.*.*...*..*.*..***..*...***.", "output": "yes" }, { "input": "99\n.*..**..*..*..**...***.****.*...*....*****.....**..****.*..*....****..**..*****..*....**.*.**..**..", "output": "yes" }, { "input": "89\n..**..**..*.********....*.*****.**.****...*......*******..*.**.*****..*..****....*...**..", "output": "yes" }, { "input": "99\n..*.*..**.*.*.******.*.*.**.**.**.*..**.*.*****..*.*.****.*....**....*****.....***..**....***.*.*.*", "output": "yes" }, { "input": "5\n*****", "output": "yes" }, { "input": "10\n.*.*.*.*.*", "output": "yes" }, { "input": "51\n....****....*........*.*..**........*....****....*.", "output": "no" }, { "input": "98\n.**..**.*****..***...*.**..*..*....*******..**....*.****.**.*.....*.**..***.**..***.*******..****.", "output": "yes" }, { "input": "45\n.***..******....***..**..*.*.*.**..**..*.**..", "output": "yes" }, { "input": "67\n..**.*...*.....****.***.**.*....***..***.*..***.....*******.....*.*", "output": "yes" }, { "input": "97\n...*..*...*******.*.**..**..******.*.*..*****.*...***.*.**.**.**..**.******.****.*.***.**..*...**", "output": "yes" }, { "input": "87\n*..*..***.**.*...****...*....***....***......*..*.*.*****.**..*.***...*.****..**.*..***", "output": "yes" }, { "input": "99\n***....*.....****.*.**.*.*.**.*.*.*..*...*..*...***..*.*...*.*...***.*.*...**.**.*******....**....*", "output": "yes" }, { "input": "90\n**....****.***..***.*.*****...*.*.***..***.******.**...***..*...*****..*.**.**...*..**...*", "output": "yes" }, { "input": "58\n**.*.*.**..******.**.*..*.**.*.*******.**.*.**.*..*****.*.", "output": "yes" }, { "input": "75\n..*.**..*.*****.......*....*.*.*..**.*.***.*.***....******.****.*.....****.", "output": "yes" }, { "input": "72\n.***.**.*.*...*****.*.*.*.*.**....**.*.**..*.*...**..***.**.**..*.**..**", "output": "yes" }, { "input": "69\n.***...*.***.**...*....*.***.*..*....**.*...**....*.*..**....**..*.**", "output": "yes" }, { "input": "42\n..*...*.*..**..*.*.*..**...**.***.*.******", "output": "yes" }, { "input": "54\n...***.*...****.*..****....*..**..**..***.*..**...**..", "output": "yes" }, { "input": "55\n...*..*.*.**..*.*....*.****..****....*..***.*****..*..*", "output": "yes" }, { "input": "57\n**...*....**.**.*.******.**..**.*.....**.***..***...**..*", "output": "yes" }, { "input": "97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.", "output": "yes" }, { "input": "42\n***.*..*.*.***...**..*..**....**..*..*...*", "output": "yes" }, { "input": "99\n**...*.*.*..*....**.***..*...***..***.**.*.....*.*....*...*.**.**.****..**..*.*..*.***....**...**.*", "output": "yes" }, { "input": "1\n.", "output": "no" }, { "input": "1\n*", "output": "no" }, { "input": "99\n.*.......................*.......................*.......................*.......................*.", "output": "yes" }, { "input": "99\n.*.......................*...............................................*.......................*.", "output": "no" }, { "input": "100\n****************************************************************************************************", "output": "yes" }, { "input": "99\n***************************************************************************************************", "output": "yes" }, { "input": "5\n.****", "output": "no" }, { "input": "5\n*.***", "output": "no" }, { "input": "5\n**.**", "output": "no" }, { "input": "5\n***.*", "output": "no" }, { "input": "5\n****.", "output": "no" }, { "input": "100\n*...............................................................................................****", "output": "no" }, { "input": "11\n.**.*..*.**", "output": "no" }, { "input": "21\n*.*...*.*...*.*...*.*", "output": "no" }, { "input": "6\n***.**", "output": "no" }, { "input": "13\n*..*..*..*..*", "output": "yes" }, { "input": "4\n****", "output": "no" }, { "input": "17\n.*..*..*.....*..*", "output": "no" }, { "input": "7\n***.***", "output": "no" }, { "input": "20\n.*..*...*....*.....*", "output": "no" }, { "input": "11\n*...**..*.*", "output": "no" }, { "input": "10\n*****....*", "output": "yes" }, { "input": "16\n*.**.**.**.*..*.", "output": "yes" }, { "input": "10\n.*.*.*.*..", "output": "no" }, { "input": "17\n*...*...*...*...*", "output": "yes" }, { "input": "15\n..........*****", "output": "yes" } ]
1,428,167,864
2,564
Python 3
WRONG_ANSWER
PRETESTS
2
62
0
import itertools n = int(input()) s = input() ok = False for i in range(n): for jump in range(1, (n - i) // 5 + 1): for c in itertools.islice(s, i, i + 5 * jump, jump): if c == '.': break else: print("yes") ok = True break if not ok: print("no")
Title: King of Thieves Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level. A dungeon consists of *n* segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'. One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number *i*1, he can make a sequence of jumps through the platforms *i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**k*, if *i*2<=-<=*i*1<==<=*i*3<=-<=*i*2<==<=...<==<=*i**k*<=-<=*i**k*<=-<=1. Of course, all segments *i*1,<=*i*2,<=... *i**k* should be exactly the platforms, not pits. Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence *i*1,<=*i*2,<=...,<=*i*5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of segments on the level. Next line contains the scheme of the level represented as a string of *n* characters '*' and '.'. Output Specification: If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes). Demo Input: ['16\n.**.*..*.***.**.\n', '11\n.*.*...*.*.\n'] Demo Output: ['yes', 'no'] Note: In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
```python import itertools n = int(input()) s = input() ok = False for i in range(n): for jump in range(1, (n - i) // 5 + 1): for c in itertools.islice(s, i, i + 5 * jump, jump): if c == '.': break else: print("yes") ok = True break if not ok: print("no") ```
0
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,679,648,713
2,147,483,647
PyPy 3-64
OK
TESTS
34
124
0
n,k = map(int, input().split(' ')) nums = list(map(str, input().split(' '))) lucky = ['4','7'] res = 0 count = 0 for i in nums: for j in i : if j in lucky : count += 1 if count <= k : res += 1 count = 0 print(res)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['3 4\n1 2 4\n', '3 2\n447 44 77\n'] Demo Output: ['3\n', '2\n'] Note: In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
```python n,k = map(int, input().split(' ')) nums = list(map(str, input().split(' '))) lucky = ['4','7'] res = 0 count = 0 for i in nums: for j in i : if j in lucky : count += 1 if count <= k : res += 1 count = 0 print(res) ```
3
842
A
Kirill And The Game
PROGRAMMING
1,200
[ "brute force", "two pointers" ]
null
null
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
[ "1 10 1 10 1\n", "1 5 6 10 1\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "1 10 1 10 1", "output": "YES" }, { "input": "1 5 6 10 1", "output": "NO" }, { "input": "1 1 1 1 1", "output": "YES" }, { "input": "1 1 1 1 2", "output": "NO" }, { "input": "1 100000 1 100000 100000", "output": "YES" }, { "input": "1 100000 1 100000 100001", "output": "NO" }, { "input": "25 10000 200 10000 5", "output": "YES" }, { "input": "1 100000 10 100000 50000", "output": "NO" }, { "input": "91939 94921 10197 89487 1", "output": "NO" }, { "input": "30518 58228 74071 77671 1", "output": "NO" }, { "input": "46646 79126 78816 91164 5", "output": "NO" }, { "input": "30070 83417 92074 99337 2", "output": "NO" }, { "input": "13494 17544 96820 99660 6", "output": "NO" }, { "input": "96918 97018 10077 86510 9", "output": "YES" }, { "input": "13046 45594 14823 52475 1", "output": "YES" }, { "input": "29174 40572 95377 97669 4", "output": "NO" }, { "input": "79894 92433 8634 86398 4", "output": "YES" }, { "input": "96022 98362 13380 94100 6", "output": "YES" }, { "input": "79446 95675 93934 96272 3", "output": "NO" }, { "input": "5440 46549 61481 99500 10", "output": "NO" }, { "input": "21569 53580 74739 87749 3", "output": "NO" }, { "input": "72289 78297 79484 98991 7", "output": "NO" }, { "input": "88417 96645 92742 98450 5", "output": "NO" }, { "input": "71841 96625 73295 77648 8", "output": "NO" }, { "input": "87969 99230 78041 94736 4", "output": "NO" }, { "input": "4 4 1 2 3", "output": "NO" }, { "input": "150 150 1 2 100", "output": "NO" }, { "input": "99 100 1 100 50", "output": "YES" }, { "input": "7 7 3 6 2", "output": "NO" }, { "input": "10 10 1 10 1", "output": "YES" }, { "input": "36 36 5 7 6", "output": "YES" }, { "input": "73 96 1 51 51", "output": "NO" }, { "input": "3 3 1 3 2", "output": "NO" }, { "input": "10000000 10000000 1 100000 10000000", "output": "YES" }, { "input": "9222174 9829060 9418763 9955619 9092468", "output": "NO" }, { "input": "70 70 1 2 50", "output": "NO" }, { "input": "100 200 1 20 5", "output": "YES" }, { "input": "1 200000 65536 65536 65537", "output": "NO" }, { "input": "15 15 1 100 1", "output": "YES" }, { "input": "10000000 10000000 1 10000000 100000", "output": "YES" }, { "input": "10 10 2 5 4", "output": "NO" }, { "input": "67 69 7 7 9", "output": "NO" }, { "input": "100000 10000000 1 10000000 100000", "output": "YES" }, { "input": "9 12 1 2 7", "output": "NO" }, { "input": "5426234 6375745 2636512 8492816 4409404", "output": "NO" }, { "input": "6134912 6134912 10000000 10000000 999869", "output": "NO" }, { "input": "3 3 1 100 1", "output": "YES" }, { "input": "10000000 10000000 10 10000000 100000", "output": "YES" }, { "input": "4 4 1 100 2", "output": "YES" }, { "input": "8 13 1 4 7", "output": "NO" }, { "input": "10 10 100000 10000000 10000000", "output": "NO" }, { "input": "5 6 1 4 2", "output": "YES" }, { "input": "1002 1003 1 2 1000", "output": "NO" }, { "input": "4 5 1 2 2", "output": "YES" }, { "input": "5 6 1 5 1", "output": "YES" }, { "input": "15 21 2 4 7", "output": "YES" }, { "input": "4 5 3 7 1", "output": "YES" }, { "input": "15 15 3 4 4", "output": "NO" }, { "input": "3 6 1 2 2", "output": "YES" }, { "input": "2 10 3 6 3", "output": "YES" }, { "input": "1 10000000 1 10000000 100000", "output": "YES" }, { "input": "8 13 1 2 7", "output": "NO" }, { "input": "98112 98112 100000 100000 128850", "output": "NO" }, { "input": "2 2 1 2 1", "output": "YES" }, { "input": "8 8 3 4 2", "output": "YES" }, { "input": "60 60 2 3 25", "output": "NO" }, { "input": "16 17 2 5 5", "output": "NO" }, { "input": "2 4 1 3 1", "output": "YES" }, { "input": "4 5 1 2 3", "output": "NO" }, { "input": "10 10 3 4 3", "output": "NO" }, { "input": "10 10000000 999999 10000000 300", "output": "NO" }, { "input": "100 120 9 11 10", "output": "YES" }, { "input": "8 20 1 3 4", "output": "YES" }, { "input": "10 14 2 3 4", "output": "YES" }, { "input": "2000 2001 1 3 1000", "output": "YES" }, { "input": "12 13 2 3 5", "output": "NO" }, { "input": "7 7 2 3 3", "output": "NO" }, { "input": "5 8 1 10000000 4", "output": "YES" }, { "input": "5 5 1 1 4", "output": "NO" }, { "input": "5 5 1 6 2", "output": "NO" }, { "input": "200 300 4000381 4000382 4000381", "output": "NO" }, { "input": "11 17 2 5 2", "output": "NO" }, { "input": "9999999 10000000 1 10000000 999997", "output": "NO" }, { "input": "7 8 2 3 3", "output": "NO" }, { "input": "7 7 3 3 2", "output": "NO" }, { "input": "15 15 2 3 7", "output": "NO" }, { "input": "65408 65408 859 859 10000000", "output": "NO" }, { "input": "1000000 10000000 1 100000 1", "output": "NO" }, { "input": "6 12 2 3 2", "output": "YES" }, { "input": "7 8 1 3 3", "output": "NO" }, { "input": "4 4 1 2 2", "output": "YES" }, { "input": "2 3 1 2 2", "output": "YES" }, { "input": "11 14 2 3 5", "output": "NO" }, { "input": "7 7 1 10 3", "output": "NO" }, { "input": "49 50 1 2 27", "output": "NO" }, { "input": "1 10000000 1 10000000 123456", "output": "YES" }, { "input": "100000 10000000 100 10000000 100000", "output": "YES" }, { "input": "17 19 2 3 8", "output": "NO" }, { "input": "4 6 3 9 1", "output": "YES" }, { "input": "19 20 6 7 3", "output": "NO" }, { "input": "5000000 10000000 1 4999999 1", "output": "NO" } ]
1,559,292,479
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
0
l, r, x, y, k = [float(i) for i in input().split()] possible = False for a in range(int(l), int(r + 1)): for b in range(int(x), int(y + 1)): if (a / b) == k: possible = True if possible == True: print("YES") else: print("NO")
Title: Kirill And The Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? Input Specification: First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). Output Specification: Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register. Demo Input: ['1 10 1 10 1\n', '1 5 6 10 1\n'] Demo Output: ['YES', 'NO'] Note: none
```python l, r, x, y, k = [float(i) for i in input().split()] possible = False for a in range(int(l), int(r + 1)): for b in range(int(x), int(y + 1)): if (a / b) == k: possible = True if possible == True: print("YES") else: print("NO") ```
0
142
A
Help Farmer
PROGRAMMING
1,600
[ "brute force", "math" ]
null
null
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks. At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*. Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks.
The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109).
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
[ "4\n", "7\n", "12\n" ]
[ "28 41\n", "47 65\n", "48 105\n" ]
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks.
500
[ { "input": "4", "output": "28 41" }, { "input": "7", "output": "47 65" }, { "input": "12", "output": "48 105" }, { "input": "1", "output": "17 17" }, { "input": "6", "output": "34 57" }, { "input": "8", "output": "40 73" }, { "input": "9", "output": "41 81" }, { "input": "14", "output": "58 121" }, { "input": "15", "output": "55 129" }, { "input": "16", "output": "56 137" }, { "input": "18", "output": "57 153" }, { "input": "20", "output": "64 169" }, { "input": "299999771", "output": "1499998867 2399998177" }, { "input": "54", "output": "106 441" }, { "input": "96", "output": "144 777" }, { "input": "348", "output": "396 2793" }, { "input": "748", "output": "487 5993" }, { "input": "908", "output": "1840 7273" }, { "input": "1026", "output": "591 8217" }, { "input": "1985", "output": "3601 15889" }, { "input": "4472", "output": "1603 35785" }, { "input": "20845", "output": "8873 166769" }, { "input": "50480", "output": "17884 403849" }, { "input": "62497", "output": "312497 499985" }, { "input": "646055", "output": "140995 5168449" }, { "input": "790620", "output": "316416 6324969" }, { "input": "989903", "output": "1082167 7919233" }, { "input": "7033800", "output": "210976 56270409" }, { "input": "7661860", "output": "546725 61294889" }, { "input": "7834243", "output": "8302235 62673953" }, { "input": "45134118", "output": "19223945 361072953" }, { "input": "89054701", "output": "445273517 712437617" }, { "input": "99264891", "output": "15587889 794119137" }, { "input": "127039320", "output": "1209066 1016314569" }, { "input": "206898748", "output": "1683461 1655189993" }, { "input": "231136953", "output": "539319577 1849095633" }, { "input": "257259713", "output": "2122207 2058077713" }, { "input": "286736327", "output": "290355727 2293890625" }, { "input": "311933803", "output": "1559669027 2495470433" }, { "input": "332393619", "output": "10714371 2659148961" }, { "input": "422114561", "output": "78417139 3376916497" }, { "input": "453012754", "output": "2844347 3624102041" }, { "input": "470860680", "output": "129486993 3766885449" }, { "input": "509607936", "output": "3045276 4076863497" }, { "input": "534879507", "output": "253364145 4279036065" }, { "input": "535074941", "output": "647722381 4280599537" }, { "input": "536870912", "output": "3151876 4294967305" }, { "input": "573308928", "output": "3301020 4586471433" }, { "input": "603979776", "output": "3414276 4831838217" }, { "input": "605404800", "output": "3414952 4843238409" }, { "input": "615716902", "output": "10508698 4925735225" }, { "input": "628464178", "output": "3574502 5027713433" }, { "input": "631243141", "output": "634644469 5049945137" }, { "input": "644972544", "output": "3573148 5159780361" }, { "input": "659274082", "output": "1977822262 5274192665" }, { "input": "679477248", "output": "3693060 5435817993" }, { "input": "735134400", "output": "3886608 5881075209" }, { "input": "764411904", "output": "3988228 6115295241" }, { "input": "778377600", "output": "4036708 6227020809" }, { "input": "791683200", "output": "4082888 6333465609" }, { "input": "805306368", "output": "4201476 6442450953" }, { "input": "821620800", "output": "4185636 6572966409" }, { "input": "856079286", "output": "196667409 6848634297" }, { "input": "857656800", "output": "4307008 6861254409" }, { "input": "859963392", "output": "4320292 6879707145" }, { "input": "864864000", "output": "4331048 6918912009" }, { "input": "882161280", "output": "4388720 7057290249" }, { "input": "884822400", "output": "4396766 7078579209" }, { "input": "905969664", "output": "4529412 7247757321" }, { "input": "908107200", "output": "4474050 7264857609" }, { "input": "918918000", "output": "4511288 7351344009" }, { "input": "931170240", "output": "4548514 7449361929" }, { "input": "935625600", "output": "4563150 7485004809" }, { "input": "936354996", "output": "40069269 7490839977" }, { "input": "951350400", "output": "4614600 7610803209" }, { "input": "958557600", "output": "4637398 7668460809" }, { "input": "972972000", "output": "4685478 7783776009" }, { "input": "980179200", "output": "4707050 7841433609" }, { "input": "985944960", "output": "4725040 7887559689" }, { "input": "994593600", "output": "4752650 7956748809" }, { "input": "999893227", "output": "1000183267 7999145825" }, { "input": "999893387", "output": "1000724227 7999147105" }, { "input": "999905161", "output": "1000161721 7999241297" }, { "input": "999942949", "output": "1000368197 7999543601" }, { "input": "999996583", "output": "1022096687 7999972673" }, { "input": "999999797", "output": "4999998997 7999998385" }, { "input": "999999883", "output": "4999999427 7999999073" }, { "input": "999999893", "output": "4999999477 7999999153" }, { "input": "999999929", "output": "4999999657 7999999441" }, { "input": "999999937", "output": "4999999697 7999999505" }, { "input": "999999991", "output": "1059701759 7999999937" }, { "input": "999999992", "output": "129518035 7999999945" }, { "input": "999999993", "output": "490196227 7999999953" }, { "input": "999999994", "output": "928571477 7999999961" }, { "input": "999999995", "output": "4924975 7999999969" }, { "input": "999999996", "output": "1000000044 7999999977" }, { "input": "999999997", "output": "15309947 7999999985" }, { "input": "999999998", "output": "504345691 7999999993" }, { "input": "999999999", "output": "52392027 8000000001" }, { "input": "1000000000", "output": "4770064 8000000009" } ]
1,691,165,660
2,147,483,647
PyPy 3-64
OK
TESTS
100
124
3,072,000
n = int(input()) kd = 0 d = [0] * 100010 for x in range(1, n + 1): if x * x > n: break elif n % x == 0: kd += 1 d[kd] = x if x * x < n: kd += 1 d[kd] = n // x minimum = float('inf') maximum = -1 for a in range(1, kd + 1): for b in range(1, kd + 1): if n // d[a] % d[b] != 0: continue c = n // d[a] // d[b] cur = (d[a] + 1) * (d[b] + 2) * (c + 2) - n minimum = min(minimum, cur) maximum = max(maximum, cur) print(minimum, maximum)# 1691165660.7016428
Title: Help Farmer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks. At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*. Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks. Input Specification: The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109). Output Specification: Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Demo Input: ['4\n', '7\n', '12\n'] Demo Output: ['28 41\n', '47 65\n', '48 105\n'] Note: Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks.
```python n = int(input()) kd = 0 d = [0] * 100010 for x in range(1, n + 1): if x * x > n: break elif n % x == 0: kd += 1 d[kd] = x if x * x < n: kd += 1 d[kd] = n // x minimum = float('inf') maximum = -1 for a in range(1, kd + 1): for b in range(1, kd + 1): if n // d[a] % d[b] != 0: continue c = n // d[a] // d[b] cur = (d[a] + 1) * (d[b] + 2) * (c + 2) - n minimum = min(minimum, cur) maximum = max(maximum, cur) print(minimum, maximum)# 1691165660.7016428 ```
3
149
A
Business trip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
[ "5\n1 1 1 1 2 2 3 2 2 1 1 1\n", "0\n0 0 0 0 0 0 0 1 1 2 3 0\n", "11\n1 1 4 1 1 5 1 1 4 1 1 1\n" ]
[ "2\n", "0\n", "3\n" ]
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
500
[ { "input": "5\n1 1 1 1 2 2 3 2 2 1 1 1", "output": "2" }, { "input": "0\n0 0 0 0 0 0 0 1 1 2 3 0", "output": "0" }, { "input": "11\n1 1 4 1 1 5 1 1 4 1 1 1", "output": "3" }, { "input": "15\n20 1 1 1 1 2 2 1 2 2 1 1", "output": "1" }, { "input": "7\n8 9 100 12 14 17 21 10 11 100 23 10", "output": "1" }, { "input": "52\n1 12 3 11 4 5 10 6 9 7 8 2", "output": "6" }, { "input": "50\n2 2 3 4 5 4 4 5 7 3 2 7", "output": "-1" }, { "input": "0\n55 81 28 48 99 20 67 95 6 19 10 93", "output": "0" }, { "input": "93\n85 40 93 66 92 43 61 3 64 51 90 21", "output": "1" }, { "input": "99\n36 34 22 0 0 0 52 12 0 0 33 47", "output": "2" }, { "input": "99\n28 32 31 0 10 35 11 18 0 0 32 28", "output": "3" }, { "input": "99\n19 17 0 1 18 11 29 9 29 22 0 8", "output": "4" }, { "input": "76\n2 16 11 10 12 0 20 4 4 14 11 14", "output": "5" }, { "input": "41\n2 1 7 7 4 2 4 4 9 3 10 0", "output": "6" }, { "input": "47\n8 2 2 4 3 1 9 4 2 7 7 8", "output": "7" }, { "input": "58\n6 11 7 0 5 6 3 9 4 9 5 1", "output": "8" }, { "input": "32\n5 2 4 1 5 0 5 1 4 3 0 3", "output": "9" }, { "input": "31\n6 1 0 4 4 5 1 0 5 3 2 0", "output": "9" }, { "input": "35\n2 3 0 0 6 3 3 4 3 5 0 6", "output": "9" }, { "input": "41\n3 1 3 4 3 6 6 1 4 4 0 6", "output": "11" }, { "input": "97\n0 5 3 12 10 16 22 8 21 17 21 10", "output": "5" }, { "input": "100\n21 21 0 0 4 13 0 26 0 0 0 15", "output": "6" }, { "input": "100\n0 0 16 5 22 0 5 0 25 0 14 13", "output": "7" }, { "input": "97\n17 0 10 0 0 0 18 0 14 23 15 0", "output": "6" }, { "input": "100\n0 9 0 18 7 0 0 14 33 3 0 16", "output": "7" }, { "input": "95\n5 2 13 0 15 18 17 0 6 11 0 8", "output": "9" }, { "input": "94\n11 13 0 9 15 8 8 16 3 7 1 3", "output": "11" }, { "input": "96\n8 4 12 15 8 0 4 10 6 6 12 11", "output": "11" }, { "input": "100\n5 5 3 8 6 5 0 3 3 8 1 3", "output": "-1" }, { "input": "100\n1 0 0 1 1 0 1 1 1 1 2 1", "output": "-1" }, { "input": "100\n6 3 2 0 4 1 2 2 2 2 1 1", "output": "-1" }, { "input": "0\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "-1" }, { "input": "0\n100 100 100 100 100 100 100 100 100 100 100 100", "output": "0" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100", "output": "1" }, { "input": "12\n1 1 1 1 1 1 1 1 1 1 1 1", "output": "12" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 2", "output": "12" }, { "input": "15\n10 1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "1\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "-1" } ]
1,651,412,293
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
k=int(input()) a=list(map(int,input().split())) b=sorted(a,reverse=True) suma=0 br=0 for i in b: if suma<k: suma+=i br+=1 if suma>=k: break print(br)
Title: Business trip Time Limit: None seconds Memory Limit: None megabytes Problem Description: What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. Input Specification: The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). Output Specification: Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. Demo Input: ['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n'] Demo Output: ['2\n', '0\n', '3\n'] Note: Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
```python k=int(input()) a=list(map(int,input().split())) b=sorted(a,reverse=True) suma=0 br=0 for i in b: if suma<k: suma+=i br+=1 if suma>=k: break print(br) ```
0
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,603,788,704
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
42
140
0
def f(n): global k n=str(n) r=0 for i in range(len(n)-1, len(n)-k-1, -1): if n[i]=='0': r+=1 else: return r return r n,k=[int(i) for i in input().split()] i=1 s=str(n) r=0 for i in range(len(s)-1, (len(s)-k-1), -1): if s[i]=='0': r+=1 else: break if r>=k: print(s) elif int(s[-1])%2==1 and s[-1]!='5': print(s+'0'*k) else: e=1 c=n while True: if n%2==0: e=e*5 n=n//2 if f(e*c)==k: break if n%5==0: e*=2 n//=5 if f(e*c)==k: break if n%2!=0 and n%5!=0: break q=str(e*c) if f(q)==k: print(q) else: r=f(q) k-=r print(q+'0'*k)
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python def f(n): global k n=str(n) r=0 for i in range(len(n)-1, len(n)-k-1, -1): if n[i]=='0': r+=1 else: return r return r n,k=[int(i) for i in input().split()] i=1 s=str(n) r=0 for i in range(len(s)-1, (len(s)-k-1), -1): if s[i]=='0': r+=1 else: break if r>=k: print(s) elif int(s[-1])%2==1 and s[-1]!='5': print(s+'0'*k) else: e=1 c=n while True: if n%2==0: e=e*5 n=n//2 if f(e*c)==k: break if n%5==0: e*=2 n//=5 if f(e*c)==k: break if n%2!=0 and n%5!=0: break q=str(e*c) if f(q)==k: print(q) else: r=f(q) k-=r print(q+'0'*k) ```
0
507
B
Amr and Pins
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin. Help Amr to achieve his goal in minimum number of steps.
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 0 0 0 4", "output": "1" }, { "input": "1 1 1 4 4", "output": "3" }, { "input": "4 5 6 5 6", "output": "0" }, { "input": "10 20 0 40 0", "output": "1" }, { "input": "9 20 0 40 0", "output": "2" }, { "input": "5 -1 -6 -5 1", "output": "1" }, { "input": "99125 26876 -21414 14176 17443", "output": "1" }, { "input": "8066 7339 19155 -90534 -60666", "output": "8" }, { "input": "100000 -100000 -100000 100000 100000", "output": "2" }, { "input": "10 20 0 41 0", "output": "2" }, { "input": "25 -64 -6 -56 64", "output": "2" }, { "input": "125 455 450 439 721", "output": "2" }, { "input": "5 6 3 7 2", "output": "1" }, { "input": "24 130 14786 3147 2140", "output": "271" }, { "input": "125 -363 176 93 330", "output": "2" }, { "input": "1 14 30 30 14", "output": "12" }, { "input": "25 96 13 7 2", "output": "2" }, { "input": "4 100000 -100000 100000 -100000", "output": "0" }, { "input": "1 3 4 2 5", "output": "1" }, { "input": "1 -3 3 2 6", "output": "3" }, { "input": "2 7 20 13 -5", "output": "7" }, { "input": "1 1 1 1 4", "output": "2" }, { "input": "249 -54242 -30537 -45023 -89682", "output": "121" }, { "input": "4 100000 -100000 100000 -99999", "output": "1" }, { "input": "97741 23818 78751 97583 26933", "output": "1" }, { "input": "56767 -29030 51625 79823 -56297", "output": "2" }, { "input": "98260 13729 74998 23701 9253", "output": "1" }, { "input": "67377 -80131 -90254 -57320 14102", "output": "1" }, { "input": "1 100000 100000 100000 -100000", "output": "100000" }, { "input": "19312 19470 82059 58064 62231", "output": "2" }, { "input": "67398 -68747 -79056 -34193 29400", "output": "1" }, { "input": "91099 37184 -71137 75650 -3655", "output": "1" }, { "input": "46456 -2621 -23623 -98302 -99305", "output": "2" }, { "input": "100 100000 -100000 100000 -99999", "output": "1" }, { "input": "1 100000 -100000 100000 -100000", "output": "0" }, { "input": "8 0 0 0 32", "output": "2" }, { "input": "100000 100000 1 -100000 0", "output": "2" } ]
1,607,504,287
2,147,483,647
Python 3
OK
TESTS
37
93
0
import math r, x, y, x1, y1 = map(int, input().split()) print(int(-(math.sqrt((x1-x)**2 + (y1-y)**2) // (-2*r))))
Title: Amr and Pins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin. Help Amr to achieve his goal in minimum number of steps. Input Specification: Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. Output Specification: Output a single integer — minimum number of steps required to move the center of the circle to the destination point. Demo Input: ['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n'] Demo Output: ['1\n', '3\n', '0\n'] Note: In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python import math r, x, y, x1, y1 = map(int, input().split()) print(int(-(math.sqrt((x1-x)**2 + (y1-y)**2) // (-2*r)))) ```
3
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReality\nSoul\nSpace\nMind" }, { "input": "3\nblue\norange\npurple", "output": "3\nTime\nReality\nMind" }, { "input": "2\nyellow\nred", "output": "4\nPower\nSoul\nSpace\nTime" }, { "input": "1\ngreen", "output": "5\nReality\nSpace\nPower\nSoul\nMind" }, { "input": "2\npurple\ngreen", "output": "4\nReality\nMind\nSpace\nSoul" }, { "input": "1\nblue", "output": "5\nPower\nReality\nSoul\nTime\nMind" }, { "input": "2\npurple\nblue", "output": "4\nMind\nSoul\nTime\nReality" }, { "input": "2\ngreen\nblue", "output": "4\nReality\nMind\nPower\nSoul" }, { "input": "3\npurple\ngreen\nblue", "output": "3\nMind\nReality\nSoul" }, { "input": "1\norange", "output": "5\nReality\nTime\nPower\nSpace\nMind" }, { "input": "2\npurple\norange", "output": "4\nReality\nMind\nTime\nSpace" }, { "input": "2\norange\ngreen", "output": "4\nSpace\nMind\nReality\nPower" }, { "input": "3\norange\npurple\ngreen", "output": "3\nReality\nSpace\nMind" }, { "input": "2\norange\nblue", "output": "4\nTime\nMind\nReality\nPower" }, { "input": "3\nblue\ngreen\norange", "output": "3\nPower\nMind\nReality" }, { "input": "4\nblue\norange\ngreen\npurple", "output": "2\nMind\nReality" }, { "input": "1\nred", "output": "5\nTime\nSoul\nMind\nPower\nSpace" }, { "input": "2\nred\npurple", "output": "4\nMind\nSpace\nTime\nSoul" }, { "input": "2\nred\ngreen", "output": "4\nMind\nSpace\nPower\nSoul" }, { "input": "3\nred\npurple\ngreen", "output": "3\nSoul\nSpace\nMind" }, { "input": "2\nblue\nred", "output": "4\nMind\nTime\nPower\nSoul" }, { "input": "3\nred\nblue\npurple", "output": "3\nTime\nMind\nSoul" }, { "input": "3\nred\nblue\ngreen", "output": "3\nSoul\nPower\nMind" }, { "input": "4\npurple\nblue\ngreen\nred", "output": "2\nMind\nSoul" }, { "input": "2\norange\nred", "output": "4\nPower\nMind\nTime\nSpace" }, { "input": "3\nred\norange\npurple", "output": "3\nMind\nSpace\nTime" }, { "input": "3\nred\norange\ngreen", "output": "3\nMind\nSpace\nPower" }, { "input": "4\nred\norange\ngreen\npurple", "output": "2\nSpace\nMind" }, { "input": "3\nblue\norange\nred", "output": "3\nPower\nMind\nTime" }, { "input": "4\norange\nblue\npurple\nred", "output": "2\nTime\nMind" }, { "input": "4\ngreen\norange\nred\nblue", "output": "2\nMind\nPower" }, { "input": "5\npurple\norange\nblue\nred\ngreen", "output": "1\nMind" }, { "input": "1\nyellow", "output": "5\nPower\nSoul\nReality\nSpace\nTime" }, { "input": "2\npurple\nyellow", "output": "4\nTime\nReality\nSpace\nSoul" }, { "input": "2\ngreen\nyellow", "output": "4\nSpace\nReality\nPower\nSoul" }, { "input": "3\npurple\nyellow\ngreen", "output": "3\nSoul\nReality\nSpace" }, { "input": "2\nblue\nyellow", "output": "4\nTime\nReality\nPower\nSoul" }, { "input": "3\nyellow\nblue\npurple", "output": "3\nSoul\nReality\nTime" }, { "input": "3\ngreen\nyellow\nblue", "output": "3\nSoul\nReality\nPower" }, { "input": "4\nyellow\nblue\ngreen\npurple", "output": "2\nReality\nSoul" }, { "input": "2\nyellow\norange", "output": "4\nTime\nSpace\nReality\nPower" }, { "input": "3\nyellow\npurple\norange", "output": "3\nSpace\nReality\nTime" }, { "input": "3\norange\nyellow\ngreen", "output": "3\nSpace\nReality\nPower" }, { "input": "4\ngreen\nyellow\norange\npurple", "output": "2\nSpace\nReality" }, { "input": "3\nyellow\nblue\norange", "output": "3\nTime\nReality\nPower" }, { "input": "4\norange\npurple\nblue\nyellow", "output": "2\nReality\nTime" }, { "input": "4\nblue\norange\nyellow\ngreen", "output": "2\nReality\nPower" }, { "input": "5\ngreen\nyellow\norange\nblue\npurple", "output": "1\nReality" }, { "input": "3\nyellow\npurple\nred", "output": "3\nTime\nSoul\nSpace" }, { "input": "3\nred\ngreen\nyellow", "output": "3\nPower\nSoul\nSpace" }, { "input": "4\nred\npurple\ngreen\nyellow", "output": "2\nSpace\nSoul" }, { "input": "3\nred\nyellow\nblue", "output": "3\nPower\nSoul\nTime" }, { "input": "4\nblue\nyellow\nred\npurple", "output": "2\nTime\nSoul" }, { "input": "4\nblue\nyellow\nred\ngreen", "output": "2\nSoul\nPower" }, { "input": "5\nred\nyellow\ngreen\nblue\npurple", "output": "1\nSoul" }, { "input": "3\nred\nyellow\norange", "output": "3\nPower\nSpace\nTime" }, { "input": "4\norange\ngreen\nyellow\nred", "output": "2\nPower\nSpace" }, { "input": "5\norange\nred\ngreen\nyellow\npurple", "output": "1\nSpace" }, { "input": "4\nyellow\nred\norange\nblue", "output": "2\nTime\nPower" }, { "input": "5\npurple\nblue\norange\nyellow\nred", "output": "1\nTime" }, { "input": "5\norange\nblue\nyellow\nred\ngreen", "output": "1\nPower" } ]
1,653,737,112
2,147,483,647
Python 3
OK
TESTS
64
46
0
q='Power' q1='purple' w='Time' w1='green' e='Space' e1='blue' r='Soul' r1='orange' t='Reality' t1='red' y='Mind' y1='yellow' k=6 n=int(input()) for i in range(n): a=input() if q1==a: q1=' ' k=k-1 if w1==a: w1=' ' k=k-1 if e1==a: e1=' ' k=k-1 if r1==a: r1=' ' k=k-1 if t1==a: t1=' ' k=k-1 if y1==a: y1=' ' k=k-1 print(k) if (q1!=' '): print(q) if (w1!=' '): print(w) if (e1!=' '): print(e) if (r1!=' '): print(r) if (t1!=' '): print(t) if (y1!=' '): print(y)
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. Output Specification: In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
```python q='Power' q1='purple' w='Time' w1='green' e='Space' e1='blue' r='Soul' r1='orange' t='Reality' t1='red' y='Mind' y1='yellow' k=6 n=int(input()) for i in range(n): a=input() if q1==a: q1=' ' k=k-1 if w1==a: w1=' ' k=k-1 if e1==a: e1=' ' k=k-1 if r1==a: r1=' ' k=k-1 if t1==a: t1=' ' k=k-1 if y1==a: y1=' ' k=k-1 print(k) if (q1!=' '): print(q) if (w1!=' '): print(w) if (e1!=' '): print(e) if (r1!=' '): print(r) if (t1!=' '): print(t) if (y1!=' '): print(y) ```
3
251
B
Playing with Permutations
PROGRAMMING
1,800
[ "implementation", "math" ]
null
null
Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*. A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length *n*. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules: - Before the beginning of the game Petya writes permutation 1,<=2,<=...,<=*n* on the blackboard. After that Petya makes exactly *k* moves, which are described below. - During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. Let's assume that the board contains permutation *p*1,<=*p*2,<=...,<=*p**n* at the given moment. Then Petya removes the written permutation *p* from the board and writes another one instead: *p**q*1,<=*p**q*2,<=...,<=*p**q**n*. In other words, Petya applies permutation *q* (which he has got from his mother) to permutation *p*. - All actions are similar to point 1, except that Petya writes permutation *t* on the board, such that: *t**q**i*<==<=*p**i* for all *i* from 1 to *n*. In other words, Petya applies a permutation that is inverse to *q* to permutation *p*. We know that after the *k*-th move the board contained Masha's permutation *s*1,<=*s*2,<=...,<=*s**n*. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the *k*-th move. Note that the game has exactly *k* moves, that is, throughout the game the coin was tossed exactly *k* times. Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* space-separated integers *q*1,<=*q*2,<=...,<=*q**n* (1<=≤<=*q**i*<=≤<=*n*) — the permutation that Petya's got as a present. The third line contains Masha's permutation *s*, in the similar format. It is guaranteed that the given sequences *q* and *s* are correct permutations.
If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).
[ "4 1\n2 3 4 1\n1 2 3 4\n", "4 1\n4 3 1 2\n3 4 2 1\n", "4 3\n4 3 1 2\n3 4 2 1\n", "4 2\n4 3 1 2\n2 1 4 3\n", "4 1\n4 3 1 2\n2 1 4 3\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n", "NO\n" ]
In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before *k* moves were performed. In the second sample the described situation is possible, in case if after we toss a coin, we get tails. In the third sample the possible coin tossing sequence is: heads-tails-tails. In the fourth sample the possible coin tossing sequence is: heads-heads.
1,000
[ { "input": "4 1\n2 3 4 1\n1 2 3 4", "output": "NO" }, { "input": "4 1\n4 3 1 2\n3 4 2 1", "output": "YES" }, { "input": "4 3\n4 3 1 2\n3 4 2 1", "output": "YES" }, { "input": "4 2\n4 3 1 2\n2 1 4 3", "output": "YES" }, { "input": "4 1\n4 3 1 2\n2 1 4 3", "output": "NO" }, { "input": "4 3\n4 3 1 2\n2 1 4 3", "output": "NO" }, { "input": "4 3\n2 1 4 3\n4 3 1 2", "output": "NO" }, { "input": "4 1\n2 1 4 3\n2 1 4 3", "output": "YES" }, { "input": "4 2\n2 1 4 3\n2 1 4 3", "output": "NO" }, { "input": "4 2\n2 3 4 1\n1 2 3 4", "output": "NO" }, { "input": "5 3\n2 1 4 3 5\n2 1 4 3 5", "output": "NO" }, { "input": "9 10\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9", "output": "NO" }, { "input": "8 10\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8", "output": "YES" }, { "input": "8 9\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8", "output": "YES" }, { "input": "10 10\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "output": "NO" }, { "input": "10 9\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "output": "YES" }, { "input": "10 100\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "output": "NO" }, { "input": "10 99\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "output": "YES" }, { "input": "9 100\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9", "output": "NO" }, { "input": "5 99\n2 1 4 3 5\n2 1 4 3 5", "output": "NO" }, { "input": "5 1\n2 1 4 3 5\n2 1 4 3 5", "output": "YES" }, { "input": "55 30\n51 43 20 22 50 48 35 6 49 7 52 29 34 45 9 55 47 36 41 54 1 4 39 46 25 26 12 28 14 3 33 23 11 2 53 8 40 32 13 37 19 16 18 42 27 31 17 44 30 24 15 38 10 21 5\n30 31 51 22 43 32 10 38 54 53 44 12 24 14 20 34 47 11 41 15 49 4 5 36 25 26 27 28 29 1 6 55 48 46 7 52 40 16 50 37 19 13 33 39 45 8 17 23 21 18 3 42 35 9 2", "output": "NO" }, { "input": "55 30\n32 37 9 26 13 6 44 1 2 38 11 12 36 49 10 46 5 21 43 24 28 31 15 51 55 27 29 18 41 17 20 8 45 16 52 30 39 53 3 35 19 33 50 54 47 34 48 14 4 42 22 40 23 25 7\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", "output": "NO" }, { "input": "55 28\n25 13 15 37 5 7 42 9 50 8 14 21 3 30 29 38 1 51 52 20 16 27 6 41 48 4 49 32 2 44 55 10 33 34 54 23 40 26 12 31 39 28 43 46 53 19 22 35 36 47 24 17 11 45 18\n17 29 13 26 5 23 6 10 8 32 53 39 2 11 3 21 52 55 46 20 12 47 36 51 1 38 22 42 15 14 40 28 33 34 48 49 4 16 41 37 24 7 43 30 54 44 50 25 27 9 18 19 45 35 31", "output": "YES" }, { "input": "55 28\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26", "output": "YES" }, { "input": "55 28\n35 33 46 8 11 13 14 26 42 38 1 7 34 5 2 21 17 45 54 43 4 18 27 50 25 10 29 48 6 16 22 28 55 53 49 41 39 23 40 47 51 37 36 19 9 32 52 12 24 3 20 15 30 44 31\n5 52 24 16 7 27 48 21 18 8 14 28 29 12 47 53 17 31 54 41 30 55 10 35 25 4 38 46 23 34 33 3 15 6 11 20 9 26 42 37 43 45 51 19 22 50 39 32 1 49 36 40 13 44 2", "output": "YES" }, { "input": "1 1\n1\n1", "output": "NO" }, { "input": "1 2\n1\n1", "output": "NO" }, { "input": "2 3\n2 1\n2 1", "output": "NO" }, { "input": "3 100\n2 3 1\n2 3 1", "output": "YES" }, { "input": "6 3\n2 3 4 5 6 1\n2 3 4 5 6 1", "output": "YES" }, { "input": "13 2\n2 3 4 5 6 7 8 9 10 11 12 13 1\n3 4 5 6 7 8 9 10 11 12 13 1 2", "output": "YES" }, { "input": "2 99\n2 1\n2 1", "output": "NO" }, { "input": "4 3\n2 1 4 3\n2 1 4 3", "output": "NO" }, { "input": "4 50\n2 3 4 1\n3 4 1 2", "output": "YES" }, { "input": "3 99\n2 3 1\n2 3 1", "output": "YES" }, { "input": "2 2\n2 1\n1 2", "output": "NO" }, { "input": "10 29\n2 1 4 5 3 7 8 9 10 6\n2 1 5 3 4 8 9 10 6 7", "output": "YES" }, { "input": "4 11\n2 3 4 1\n2 3 4 1", "output": "YES" }, { "input": "9 3\n2 3 4 5 6 7 8 9 1\n3 4 5 6 7 8 9 1 2", "output": "NO" } ]
1,655,588,831
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
512,000
import sys from array import array def move_up(): k_ = k a = array('i', range(1, n + 1)) while k_ and a != final: k_ -= 1 tem = array('i') for i in range(n): tem.append(a[q[i] - 1]) a = tem return k_, a == final def move_down(): k_ = k a = array('i', range(1, n + 1)) while k_ and a != final: k_ -= 1 tem = array('i', [0] * n) for i in range(n): tem[q[i] - 1] = a[i] a = tem return k_, a == final input = lambda: sys.stdin.buffer.readline().decode().strip() n, k = map(int, input().split()) q = array('i', [int(x) for x in input().split()]) final = array('i', [int(x) for x in input().split()]) ans = 0 retup, retdown = move_up(), move_down() if retup[1]: if k - retup[0] == 1: if k - retup[1] > 1 and k & 1 and k >= 3: ans = 1 elif k - retup[0] > 1: if retup[0] & 1 == 0: ans = 1 elif retup[0]: if k - retup[1] == 1: if k - retup[0] > 1 and k & 1 and k >= 3: ans = 1 elif k - retup[1] > 1: if retup[1] & 1 == 0: ans = 1 print(['NO', 'YES'][ans])
Title: Playing with Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*. A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length *n*. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules: - Before the beginning of the game Petya writes permutation 1,<=2,<=...,<=*n* on the blackboard. After that Petya makes exactly *k* moves, which are described below. - During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. Let's assume that the board contains permutation *p*1,<=*p*2,<=...,<=*p**n* at the given moment. Then Petya removes the written permutation *p* from the board and writes another one instead: *p**q*1,<=*p**q*2,<=...,<=*p**q**n*. In other words, Petya applies permutation *q* (which he has got from his mother) to permutation *p*. - All actions are similar to point 1, except that Petya writes permutation *t* on the board, such that: *t**q**i*<==<=*p**i* for all *i* from 1 to *n*. In other words, Petya applies a permutation that is inverse to *q* to permutation *p*. We know that after the *k*-th move the board contained Masha's permutation *s*1,<=*s*2,<=...,<=*s**n*. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the *k*-th move. Note that the game has exactly *k* moves, that is, throughout the game the coin was tossed exactly *k* times. Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* space-separated integers *q*1,<=*q*2,<=...,<=*q**n* (1<=≤<=*q**i*<=≤<=*n*) — the permutation that Petya's got as a present. The third line contains Masha's permutation *s*, in the similar format. It is guaranteed that the given sequences *q* and *s* are correct permutations. Output Specification: If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes). Demo Input: ['4 1\n2 3 4 1\n1 2 3 4\n', '4 1\n4 3 1 2\n3 4 2 1\n', '4 3\n4 3 1 2\n3 4 2 1\n', '4 2\n4 3 1 2\n2 1 4 3\n', '4 1\n4 3 1 2\n2 1 4 3\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n', 'YES\n', 'NO\n'] Note: In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before *k* moves were performed. In the second sample the described situation is possible, in case if after we toss a coin, we get tails. In the third sample the possible coin tossing sequence is: heads-tails-tails. In the fourth sample the possible coin tossing sequence is: heads-heads.
```python import sys from array import array def move_up(): k_ = k a = array('i', range(1, n + 1)) while k_ and a != final: k_ -= 1 tem = array('i') for i in range(n): tem.append(a[q[i] - 1]) a = tem return k_, a == final def move_down(): k_ = k a = array('i', range(1, n + 1)) while k_ and a != final: k_ -= 1 tem = array('i', [0] * n) for i in range(n): tem[q[i] - 1] = a[i] a = tem return k_, a == final input = lambda: sys.stdin.buffer.readline().decode().strip() n, k = map(int, input().split()) q = array('i', [int(x) for x in input().split()]) final = array('i', [int(x) for x in input().split()]) ans = 0 retup, retdown = move_up(), move_down() if retup[1]: if k - retup[0] == 1: if k - retup[1] > 1 and k & 1 and k >= 3: ans = 1 elif k - retup[0] > 1: if retup[0] & 1 == 0: ans = 1 elif retup[0]: if k - retup[1] == 1: if k - retup[0] > 1 and k & 1 and k >= 3: ans = 1 elif k - retup[1] > 1: if retup[1] & 1 == 0: ans = 1 print(['NO', 'YES'][ans]) ```
0