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
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,695,680,136
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a = str(input()) n = 0 for i in range(0, len(a)): if a[i]!="4" or a[i]!="7": n+=1 if n=0: print("YES") else: print("NO")
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python a = str(input()) n = 0 for i in range(0, len(a)): if a[i]!="4" or a[i]!="7": n+=1 if n=0: print("YES") else: print("NO") ```
-1
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,689,245,157
2,147,483,647
PyPy 3-64
OK
TESTS
71
186
1,945,600
n=int(input()) sum=0 max=0 for i in range(0,n): x=input() var=x.split() a=int(var[0]) b=int(var[1]) sum=sum+b-a if max<sum: max=sum print(max)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python n=int(input()) sum=0 max=0 for i in range(0,n): x=input() var=x.split() a=int(var[0]) b=int(var[1]) sum=sum+b-a if max<sum: max=sum print(max) ```
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", "output": "21223442" }, { "input": "91730629", "output": "91230320" }, { "input": "420062703497", "output": "420032203402" }, { "input": "332711047202", "output": "332211042202" }, { "input": "3395184971407775", "output": "3304114021402224" }, { "input": "8464062628894325", "output": "1434032321104324" }, { "input": "164324828731963982", "output": "134324121231033012" }, { "input": "384979173822804784", "output": "314020123122104214" }, { "input": "41312150450968417", "output": "41312140440031412" }, { "input": "2156", "output": "2143" }, { "input": "1932", "output": "1032" }, { "input": "5902", "output": "4002" }, { "input": "5728", "output": "4221" }, { "input": "8537", "output": "1432" }, { "input": "55403857", "output": "44403142" }, { "input": "270739", "output": "220230" }, { "input": "28746918", "output": "21243011" }, { "input": "10279211", "output": "10220211" }, { "input": "40289679", "output": "40210320" }, { "input": "545203238506", "output": "444203231403" }, { "input": "461117063340", "output": "431112033340" }, { "input": "658492686568", "output": "341402313431" }, { "input": "857373361868", "output": "142323331131" }, { "input": "429325660016", "output": "420324330013" }, { "input": "9894448650287940", "output": "9104441340212040" }, { "input": "6354510839296263", "output": "3344410130203233" }, { "input": "6873575462224593", "output": "3123424432224403" }, { "input": "4237951492601449", "output": "4232041402301440" }, { "input": "2680352384836991", "output": "2310342314133001" }, { "input": "606187734191890310", "output": "303112234101100310" }, { "input": "351499943576823355", "output": "341400043423123344" }, { "input": "180593481782177068", "output": "110403411212122031" }, { "input": "999999999999999999", "output": "900000000000000000" }, { "input": "1000000000000000000", "output": "1000000000000000000" }, { "input": "9999", "output": "9000" }, { "input": "99", "output": "90" }, { "input": "9991", "output": "9001" } ]
1,694,766,267
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
0
n = str(input()) n = list(n) if int(n[0]) > 5 and int(n[0]) < 9: n[0] = str(9 - int(n[0])) for i in range(1, len(n)): if int(n[i]) > 5: n[i] = str(9 - int(n[i])) n = ''.join(n) print(int(n))
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. Output Specification: Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. Demo Input: ['27\n', '4545\n'] Demo Output: ['22\n', '4444\n'] Note: none
```python n = str(input()) n = list(n) if int(n[0]) > 5 and int(n[0]) < 9: n[0] = str(9 - int(n[0])) for i in range(1, len(n)): if int(n[i]) > 5: n[i] = str(9 - int(n[i])) n = ''.join(n) print(int(n)) ```
0
708
A
Letters Cyclic Shift
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation", "strings" ]
null
null
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once?
The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
[ "codeforces\n", "abacaba\n" ]
[ "bncdenqbdr\n", "aaacaba\n" ]
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> &lt; *t*<sub class="lower-index">*i*</sub>.
500
[ { "input": "codeforces", "output": "bncdenqbdr" }, { "input": "abacaba", "output": "aaacaba" }, { "input": "babbbabaababbaa", "output": "aabbbabaababbaa" }, { "input": "bcbacaabcababaccccaaaabacbbcbbaa", "output": "abaacaabcababaccccaaaabacbbcbbaa" }, { "input": "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda", "output": "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda" }, { "input": "a", "output": "z" }, { "input": "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec", "output": "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec" }, { "input": "fddfbabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe", "output": "ecceaabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaz" }, { "input": "abbabaaaaa", "output": "aaaabaaaaa" }, { "input": "bbbbbbbbbbbb", "output": "aaaaaaaaaaaa" }, { "input": "aabaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaz" }, { "input": "abaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa", "output": "aaaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa" }, { "input": "abbbbbbbabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb", "output": "aaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb" }, { "input": "aaaaa", "output": "aaaaz" }, { "input": "aaa", "output": "aaz" }, { "input": "aa", "output": "az" } ]
1,521,470,340
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
78
7,065,600
IL = lambda: list(map(int, input().split())) I = lambda: int(input()) s = list(map(ord, input())) started = False for i, ss in enumerate(s): if ss > 97: started = True if started: if ss > 97: s[i] -= 1 else: break print("".join(map(chr, s)))
Title: Letters Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once? Input Specification: The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. Output Specification: Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. Demo Input: ['codeforces\n', 'abacaba\n'] Demo Output: ['bncdenqbdr\n', 'aaacaba\n'] Note: String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> &lt; *t*<sub class="lower-index">*i*</sub>.
```python IL = lambda: list(map(int, input().split())) I = lambda: int(input()) s = list(map(ord, input())) started = False for i, ss in enumerate(s): if ss > 97: started = True if started: if ss > 97: s[i] -= 1 else: break print("".join(map(chr, s))) ```
0
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1", "output": "0 0 1" }, { "input": "5 3", "output": "0 0 5" }, { "input": "42 6", "output": "3 18 21" }, { "input": "1000000000000 1000", "output": "499500499 499500499000 500000000501" }, { "input": "999999999999 999999", "output": "499999 499998500001 500000999999" }, { "input": "732577309725 132613", "output": "2762066 366285858458 366288689201" }, { "input": "152326362626 15", "output": "4760198832 71402982480 76163181314" }, { "input": "2 1", "output": "0 0 2" }, { "input": "1000000000000 500000000000", "output": "0 0 1000000000000" }, { "input": "100000000000 50000000011", "output": "0 0 100000000000" }, { "input": "1000000000000 32416187567", "output": "15 486242813505 513757186480" }, { "input": "1000000000000 7777777777", "output": "64 497777777728 502222222208" }, { "input": "1000000000000 77777777777", "output": "6 466666666662 533333333332" }, { "input": "100000000000 578485652", "output": "86 49749766072 50250233842" }, { "input": "999999999999 10000000000", "output": "49 490000000000 509999999950" }, { "input": "7 2", "output": "1 2 4" }, { "input": "420506530901 752346673804", "output": "0 0 420506530901" }, { "input": "960375521135 321688347872", "output": "1 321688347872 638687173262" }, { "input": "1000000000000 1000000000000", "output": "0 0 1000000000000" }, { "input": "99999999999 15253636363", "output": "3 45760909089 54239090907" }, { "input": "19 2", "output": "3 6 10" }, { "input": "999999999999 1000000000000", "output": "0 0 999999999999" }, { "input": "1000000000000 5915587276", "output": "84 496909331184 503090668732" }, { "input": "1000000000000 1000000006", "output": "499 499000002994 500999996507" }, { "input": "549755813888 134217728", "output": "2047 274743689216 275012122625" }, { "input": "99999999999 3333333", "output": "14999 49996661667 50003323333" }, { "input": "9 1", "output": "2 2 5" }, { "input": "1000000000000 250000000001", "output": "1 250000000001 749999999998" }, { "input": "5 1", "output": "1 1 3" }, { "input": "3107038133 596040207", "output": "2 1192080414 1914957717" }, { "input": "1000000000000 73786977", "output": "6776 499980556152 500019437072" }, { "input": "1000000000000 73786976", "output": "6776 499980549376 500019443848" }, { "input": "1000000000000 25000000000", "output": "19 475000000000 524999999981" }, { "input": "216929598879 768233755932", "output": "0 0 216929598879" }, { "input": "1000000000000 250000000000", "output": "1 250000000000 749999999999" }, { "input": "1000000000000 100000000001", "output": "4 400000000004 599999999992" }, { "input": "100000000000 100000000001", "output": "0 0 100000000000" }, { "input": "900000000000 100281800001", "output": "4 401127200004 498872799992" }, { "input": "906028900004 109123020071", "output": "4 436492080284 469536819716" }, { "input": "1000000000000 1", "output": "250000000000 250000000000 500000000000" } ]
1,625,161,113
2,147,483,647
Python 3
OK
TESTS
44
77
0
import math n, k = map(int, input().split()) a = (math.floor(math.floor(n/2)/(k+1))) b = a*k rest = n - a - b print(a, b, rest)
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input Specification: The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. Output Specification: Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Demo Input: ['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n'] Demo Output: ['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n'] Note: none
```python import math n, k = map(int, input().split()) a = (math.floor(math.floor(n/2)/(k+1))) b = a*k rest = n - a - b print(a, b, rest) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,476,397,440
2,147,483,647
Python 3
OK
TESTS
40
77
4,608,000
s = input() la = list('hello') cp = -1 r = True for l in la: i = s.find(l, cp+1) if i == -1: r = False break cp = i print('YES' if r else '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() la = list('hello') cp = -1 r = True for l in la: i = s.find(l, cp+1) if i == -1: r = False break cp = i print('YES' if r else 'NO') ```
3.952917
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "input": "1 1 20", "output": "Yes" }, { "input": "12 14 19", "output": "No" }, { "input": "15 12 26", "output": "No" }, { "input": "2 4 8", "output": "Yes" }, { "input": "4 5 30", "output": "Yes" }, { "input": "4 5 48", "output": "Yes" }, { "input": "2 17 105", "output": "Yes" }, { "input": "10 25 282", "output": "No" }, { "input": "6 34 323", "output": "No" }, { "input": "2 47 464", "output": "Yes" }, { "input": "4 53 113", "output": "Yes" }, { "input": "6 64 546", "output": "Yes" }, { "input": "1 78 725", "output": "Yes" }, { "input": "1 84 811", "output": "Yes" }, { "input": "3 100 441", "output": "Yes" }, { "input": "20 5 57", "output": "No" }, { "input": "14 19 143", "output": "No" }, { "input": "17 23 248", "output": "No" }, { "input": "11 34 383", "output": "Yes" }, { "input": "20 47 568", "output": "Yes" }, { "input": "16 58 410", "output": "Yes" }, { "input": "11 70 1199", "output": "Yes" }, { "input": "16 78 712", "output": "Yes" }, { "input": "20 84 562", "output": "No" }, { "input": "19 100 836", "output": "Yes" }, { "input": "23 10 58", "output": "No" }, { "input": "25 17 448", "output": "Yes" }, { "input": "22 24 866", "output": "Yes" }, { "input": "24 35 67", "output": "No" }, { "input": "29 47 264", "output": "Yes" }, { "input": "23 56 45", "output": "No" }, { "input": "25 66 1183", "output": "Yes" }, { "input": "21 71 657", "output": "Yes" }, { "input": "29 81 629", "output": "No" }, { "input": "23 95 2226", "output": "Yes" }, { "input": "32 4 62", "output": "No" }, { "input": "37 15 789", "output": "Yes" }, { "input": "39 24 999", "output": "Yes" }, { "input": "38 32 865", "output": "No" }, { "input": "32 50 205", "output": "No" }, { "input": "31 57 1362", "output": "Yes" }, { "input": "38 68 1870", "output": "Yes" }, { "input": "36 76 549", "output": "No" }, { "input": "35 84 1257", "output": "No" }, { "input": "39 92 2753", "output": "Yes" }, { "input": "44 1 287", "output": "Yes" }, { "input": "42 12 830", "output": "No" }, { "input": "42 27 9", "output": "No" }, { "input": "49 40 1422", "output": "No" }, { "input": "44 42 2005", "output": "No" }, { "input": "50 55 2479", "output": "No" }, { "input": "48 65 917", "output": "No" }, { "input": "45 78 152", "output": "No" }, { "input": "43 90 4096", "output": "Yes" }, { "input": "43 94 4316", "output": "Yes" }, { "input": "60 7 526", "output": "Yes" }, { "input": "53 11 735", "output": "Yes" }, { "input": "52 27 609", "output": "Yes" }, { "input": "57 32 992", "output": "Yes" }, { "input": "52 49 421", "output": "No" }, { "input": "57 52 2634", "output": "Yes" }, { "input": "54 67 3181", "output": "Yes" }, { "input": "52 73 638", "output": "No" }, { "input": "57 84 3470", "output": "No" }, { "input": "52 100 5582", "output": "No" }, { "input": "62 1 501", "output": "Yes" }, { "input": "63 17 858", "output": "Yes" }, { "input": "70 24 1784", "output": "Yes" }, { "input": "65 32 1391", "output": "Yes" }, { "input": "62 50 2775", "output": "No" }, { "input": "62 58 88", "output": "No" }, { "input": "66 68 3112", "output": "Yes" }, { "input": "61 71 1643", "output": "No" }, { "input": "69 81 3880", "output": "No" }, { "input": "63 100 1960", "output": "Yes" }, { "input": "73 6 431", "output": "Yes" }, { "input": "75 19 736", "output": "Yes" }, { "input": "78 25 247", "output": "No" }, { "input": "79 36 2854", "output": "Yes" }, { "input": "80 43 1864", "output": "Yes" }, { "input": "76 55 2196", "output": "Yes" }, { "input": "76 69 4122", "output": "Yes" }, { "input": "76 76 4905", "output": "No" }, { "input": "75 89 3056", "output": "Yes" }, { "input": "73 100 3111", "output": "Yes" }, { "input": "84 9 530", "output": "No" }, { "input": "82 18 633", "output": "No" }, { "input": "85 29 2533", "output": "Yes" }, { "input": "89 38 2879", "output": "Yes" }, { "input": "89 49 2200", "output": "Yes" }, { "input": "88 60 4140", "output": "Yes" }, { "input": "82 68 1299", "output": "No" }, { "input": "90 76 2207", "output": "No" }, { "input": "83 84 4923", "output": "Yes" }, { "input": "89 99 7969", "output": "Yes" }, { "input": "94 9 168", "output": "No" }, { "input": "91 20 1009", "output": "No" }, { "input": "93 23 2872", "output": "Yes" }, { "input": "97 31 3761", "output": "Yes" }, { "input": "99 46 1341", "output": "Yes" }, { "input": "98 51 2845", "output": "No" }, { "input": "93 66 3412", "output": "No" }, { "input": "95 76 3724", "output": "Yes" }, { "input": "91 87 6237", "output": "Yes" }, { "input": "98 97 7886", "output": "Yes" }, { "input": "12 17 15", "output": "No" }, { "input": "93 94 95", "output": "No" }, { "input": "27 43 27", "output": "Yes" }, { "input": "17 43 68", "output": "Yes" }, { "input": "44 12 12", "output": "Yes" }, { "input": "44 50 150", "output": "Yes" }, { "input": "1 1 10000", "output": "Yes" }, { "input": "2 3 10000", "output": "Yes" }, { "input": "100 1 10", "output": "Yes" }, { "input": "3 2 1", "output": "No" }, { "input": "1 1 1", "output": "Yes" }, { "input": "9 9 10000", "output": "No" }, { "input": "2 3 9995", "output": "Yes" }, { "input": "3 5 4", "output": "No" }, { "input": "99 98 100", "output": "No" }, { "input": "6 10 2", "output": "No" }, { "input": "1 6 5", "output": "Yes" }, { "input": "1 4 3", "output": "Yes" }, { "input": "3 2 3", "output": "Yes" }, { "input": "1 7 6", "output": "Yes" }, { "input": "2 3 9871", "output": "Yes" }, { "input": "10 5 5", "output": "Yes" }, { "input": "10 8 2", "output": "No" } ]
1,585,827,631
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def extended_gcd(a,b): global g,x,y if b==0: g=a x,y=1,0 else: extended_gcd(b,a%b) temp = x # value of x is preserved x = y y = temp - ((a//b)*y) if __name__=="__main__": a,b,c=map(int,input().split()) g=x=y=int() extended_gcd(a,b) if (c%a==0) or (c%b==0) or (c%g==0): print("Yes") continue elif x<0 and y<0: print("No") elif x>0 and y>0: print("Yes")
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. Input Specification: The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Output Specification: Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Demo Input: ['4 6 15\n', '3 2 7\n', '6 11 6\n'] Demo Output: ['No\n', 'Yes\n', 'Yes\n'] Note: In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
```python def extended_gcd(a,b): global g,x,y if b==0: g=a x,y=1,0 else: extended_gcd(b,a%b) temp = x # value of x is preserved x = y y = temp - ((a//b)*y) if __name__=="__main__": a,b,c=map(int,input().split()) g=x=y=int() extended_gcd(a,b) if (c%a==0) or (c%b==0) or (c%g==0): print("Yes") continue elif x<0 and y<0: print("No") elif x>0 and y>0: print("Yes") ```
-1
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,693,001,021
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
n, k = map(int, input().split()) j = 1 for i in range(k): if j >= n: print(-1) break while n % j != 0: j += 1 j += 1 else: print(j - 1)
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python n, k = map(int, input().split()) j = 1 for i in range(k): if j >= n: print(-1) break while n % j != 0: j += 1 j += 1 else: print(j - 1) ```
0
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "414", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "144144144", "output": "YES" }, { "input": "1444", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "141414141", "output": "YES" }, { "input": "11110111", "output": "NO" }, { "input": "114114144", "output": "YES" }, { "input": "444", "output": "NO" }, { "input": "9999", "output": "NO" }, { "input": "111444", "output": "NO" }, { "input": "11114", "output": "YES" }, { "input": "41111", "output": "NO" }, { "input": "114414441", "output": "NO" }, { "input": "144414441", "output": "NO" }, { "input": "144244144", "output": "NO" }, { "input": "111111111", "output": "YES" }, { "input": "144444444", "output": "NO" }, { "input": "444444444", "output": "NO" }, { "input": "141441441", "output": "YES" }, { "input": "441", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "14444", "output": "NO" }, { "input": "11444", "output": "NO" }, { "input": "144", "output": "YES" }, { "input": "1414414", "output": "YES" }, { "input": "141444", "output": "NO" }, { "input": "14144", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "1144", "output": "YES" }, { "input": "141111444", "output": "NO" }, { "input": "14414414", "output": "YES" }, { "input": "141414144", "output": "YES" }, { "input": "1414", "output": "YES" }, { "input": "1441", "output": "YES" }, { "input": "12", "output": "NO" }, { "input": "144144141", "output": "YES" }, { "input": "144144", "output": "YES" }, { "input": "14414411", "output": "YES" }, { "input": "14414", "output": "YES" } ]
1,624,898,949
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
17
124
0
x=input() x=x.replace('144',"") x=x.replace('14',"") x=x.replace('1',"") if(len(x)==0): print("YES") else: print("NO")
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input Specification: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. Output Specification: Print "YES" if *n* is a magic number or print "NO" if it's not. Demo Input: ['114114\n', '1111\n', '441231\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python x=input() x=x.replace('144',"") x=x.replace('14',"") x=x.replace('1',"") if(len(x)==0): print("YES") else: print("NO") ```
0
36
A
Extra-terrestrial Intelligence
PROGRAMMING
1,300
[ "implementation" ]
A. Extra-terrestrial Intelligence
2
64
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s.
If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.
[ "8\n00111000\n", "7\n1001011\n", "7\n1010100\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "8\n00111000", "output": "YES" }, { "input": "7\n1001011", "output": "NO" }, { "input": "7\n1010100", "output": "YES" }, { "input": "5\n10101", "output": "YES" }, { "input": "3\n111", "output": "YES" }, { "input": "10\n0011111011", "output": "NO" }, { "input": "12\n001010101010", "output": "YES" }, { "input": "25\n1000000010000000100000001", "output": "YES" }, { "input": "30\n111110111101110111111111111111", "output": "NO" }, { "input": "50\n00101010101010101010101010101010101010101010101010", "output": "YES" }, { "input": "60\n000000000000000000100001000000001000000001000000001000000001", "output": "NO" }, { "input": "66\n000000000000000000000010011110000010000010000010000000000000000000", "output": "NO" }, { "input": "77\n10000100001010000000000001000000000000100000101000010010000000001100000000000", "output": "NO" }, { "input": "99\n000000000000000000100000010000001000000100000010000001000000100000010000001000000100000010000001000", "output": "YES" }, { "input": "100\n0000000000001000000000000000000000000000000000000010000000000000000000000000000000000000100000000000", "output": "YES" }, { "input": "100\n0010000000000000000000000000000100000000000010000000000000001000000000000000000000000000010000000000", "output": "NO" }, { "input": "5\n10111", "output": "NO" }, { "input": "100\n0000100000000000000000000000000000000000010000000000000000000000000000000000001000000000000000000000", "output": "YES" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111", "output": "NO" } ]
1,586,261,119
2,147,483,647
Python 3
OK
TESTS
20
248
307,200
ip = open("input.txt", "r") op = open("output.txt", "w") n = int(ip.readline()) signals = ip.readline() sigs = 0 signallen = len(signals) ans = True for i in range(signallen): if signals[i] == '1': if sigs == 0: sigs = 1 prev = i else: if sigs == 1: distance = i-prev sigs = 2 prev = i else: if i-prev != distance: ans = False break prev = i ip.close() if ans: op.write("YES") else: op.write("NO") op.close()
Title: Extra-terrestrial Intelligence Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. Output Specification: If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. Demo Input: ['8\n00111000\n', '7\n1001011\n', '7\n1010100\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python ip = open("input.txt", "r") op = open("output.txt", "w") n = int(ip.readline()) signals = ip.readline() sigs = 0 signallen = len(signals) ans = True for i in range(signallen): if signals[i] == '1': if sigs == 0: sigs = 1 prev = i else: if sigs == 1: distance = i-prev sigs = 2 prev = i else: if i-prev != distance: ans = False break prev = i ip.close() if ans: op.write("YES") else: op.write("NO") op.close() ```
3.935711
25
B
Phone numbers
PROGRAMMING
1,100
[ "implementation" ]
B. Phone numbers
2
256
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
[ "6\n549871\n", "7\n1198733\n" ]
[ "54-98-71", "11-987-33\n" ]
none
0
[ { "input": "6\n549871", "output": "54-98-71" }, { "input": "7\n1198733", "output": "119-87-33" }, { "input": "2\n74", "output": "74" }, { "input": "2\n33", "output": "33" }, { "input": "3\n074", "output": "074" }, { "input": "3\n081", "output": "081" }, { "input": "4\n3811", "output": "38-11" }, { "input": "5\n21583", "output": "215-83" }, { "input": "8\n33408349", "output": "33-40-83-49" }, { "input": "9\n988808426", "output": "988-80-84-26" }, { "input": "10\n0180990956", "output": "01-80-99-09-56" }, { "input": "15\n433488906230138", "output": "433-48-89-06-23-01-38" }, { "input": "22\n7135498415686025907059", "output": "71-35-49-84-15-68-60-25-90-70-59" }, { "input": "49\n2429965524999668169991253653390090510755018570235", "output": "242-99-65-52-49-99-66-81-69-99-12-53-65-33-90-09-05-10-75-50-18-57-02-35" }, { "input": "72\n491925337784111770500147619881727525570039735507439360627744863794794290", "output": "49-19-25-33-77-84-11-17-70-50-01-47-61-98-81-72-75-25-57-00-39-73-55-07-43-93-60-62-77-44-86-37-94-79-42-90" }, { "input": "95\n32543414456047900690980198395035321172843693417425457554204776648220562494524275489599199209210", "output": "325-43-41-44-56-04-79-00-69-09-80-19-83-95-03-53-21-17-28-43-69-34-17-42-54-57-55-42-04-77-66-48-22-05-62-49-45-24-27-54-89-59-91-99-20-92-10" }, { "input": "97\n9362344595153688016434451101547661156123505108492010669557671355055642365998461003851354321478898", "output": "936-23-44-59-51-53-68-80-16-43-44-51-10-15-47-66-11-56-12-35-05-10-84-92-01-06-69-55-76-71-35-50-55-64-23-65-99-84-61-00-38-51-35-43-21-47-88-98" }, { "input": "98\n65521815795893886057122984634320900545031770769333931308009346017867969790810907868670369236928568", "output": "65-52-18-15-79-58-93-88-60-57-12-29-84-63-43-20-90-05-45-03-17-70-76-93-33-93-13-08-00-93-46-01-78-67-96-97-90-81-09-07-86-86-70-36-92-36-92-85-68" }, { "input": "99\n455213856470326729480192345541970106407563996625458559297407682539801838244443866898560852503660390", "output": "455-21-38-56-47-03-26-72-94-80-19-23-45-54-19-70-10-64-07-56-39-96-62-54-58-55-92-97-40-76-82-53-98-01-83-82-44-44-38-66-89-85-60-85-25-03-66-03-90" }, { "input": "100\n4004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224", "output": "40-04-22-31-24-94-27-30-64-02-35-38-32-44-43-82-57-61-45-81-53-43-20-35-60-60-98-72-41-65-97-84-24-95-51-11-01-65-03-47-19-44-33-27-65-95-10-64-42-24" } ]
1,653,107,519
2,147,483,647
PyPy 3-64
OK
TESTS
20
92
0
a = int(input()) b = input() c = '' d = '' if a % 2 == 0: for i in range(0,a,2): c += b[i]+b[i+1]+'-' else: for i in range(0,a-3,2): d += b[i]+b[i+1]+'-' if a % 2 == 0: print(c[:-1]) else: print(d+b[-3:])
Title: Phone numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. Output Specification: Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. Demo Input: ['6\n549871\n', '7\n1198733\n'] Demo Output: ['54-98-71', '11-987-33\n'] Note: none
```python a = int(input()) b = input() c = '' d = '' if a % 2 == 0: for i in range(0,a,2): c += b[i]+b[i+1]+'-' else: for i in range(0,a-3,2): d += b[i]+b[i+1]+'-' if a % 2 == 0: print(c[:-1]) else: print(d+b[-3:]) ```
3.977
808
G
Anthem of Berland
PROGRAMMING
2,300
[ "dp", "strings" ]
null
null
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible. He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work. The anthem is the string *s* of no more than 105 small Latin letters and question marks. The most glorious victory is the string *t* of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string *t* in string *s* is maximal. Note that the occurrences of string *t* in *s* can overlap. Check the third example for clarification.
The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105). The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105). Product of lengths of strings |*s*|·|*t*| won't exceed 107.
Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters.
[ "winlose???winl???w??\nwin\n", "glo?yto?e??an?\nor\n", "??c?????\nabcab\n" ]
[ "5\n", "3\n", "2\n" ]
In the first example the resulting string *s* is "winlosewinwinlwinwin" In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary. In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab".
0
[ { "input": "winlose???winl???w??\nwin", "output": "5" }, { "input": "glo?yto?e??an?\nor", "output": "3" }, { "input": "??c?????\nabcab", "output": "2" }, { "input": "ddddd\nd", "output": "5" }, { "input": "ww?ww\nw", "output": "5" }, { "input": "?????\nn", "output": "5" }, { "input": "xznxr\nxznxr", "output": "1" }, { "input": "wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\nbhghd", "output": "10" }, { "input": "emnd?t??m?gd?t?p?s??m?dp??t???m?????m?d?ydo????????i??u?d??dp??h??d?tdp???cj?dm?dpxf?hsf??rdmt?pu?tw\ndmtdp", "output": "11" }, { "input": "t?t?t?xnu?\ntstx", "output": "1" }, { "input": "p??p??????\numpq", "output": "2" }, { "input": "irsdljdahusytoclelxidaaiaiaicaiaiaiaiiaiaiyyexmohdwmeyycaiaiaitclluaiaiaiznxweleaiaiaiixdwehyruhizbc\naiaiai", "output": "6" }, { "input": "qjcenuvdsn?ytytyt?yrznaaqeol?tyttyty?ycfaiphfmo?qpvtmhk?xzfr?tytytytytyty?oeqotyt?tyjhdhjtyt?tyyewxh\ntytyty", "output": "9" }, { "input": "zubxnxnxnxn?xixiox?oxinoxnox?xnoxxnox?xnoxixxnox?oxii?xnoxiin?noxixnoxiox?noxixxnox?noxxnoxi?xnoxinn\nxnoxi", "output": "13" }, { "input": "????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\nrcmcscoffidfyaeeanevbcfloxrhzxnitikwyidszzgmvicjupbfzhlbkzjbyidpdaeagaanokohwofzvfsvmcwvrqkvgbwnxomajvotbpzqgiyifngpnfvmtsoovrstzhtkeqamskzdmspvihochmajwkdoeozqpkdoxffhokosfqnaqshxbsfnkjsbbkxhrzgqhufq", "output": "1" }, { "input": "????ufu\nfufu", "output": "2" }, { "input": "??????c???\nabcabc", "output": "2" }, { "input": "a???????abcax\naxabcax", "output": "2" }, { "input": "cb???????a\ncbacba", "output": "2" }, { "input": "a???????bc\nabcabc", "output": "2" }, { "input": "a????ab\nabab", "output": "2" }, { "input": "pe????????????petooh\npetoohpetooh", "output": "2" }, { "input": "hacking????????????????????????hackingisfun\nhackingisfunhackingisfun", "output": "2" }, { "input": "youdontgiveup????????????????????????????????????youyoudontgiveupdoyo?youyoudontgiveupdoyou\nyoudontgiveupdoyouyoudontgiveupdoyou", "output": "2" }, { "input": "????b?b\nabab", "output": "2" }, { "input": "a\nb", "output": "0" }, { "input": "???a??????a??b?a??a????aabc??a???a?????ab???????b????????????????ab?a?????a????a??a??????b??cb?????????????b?????c????a??????????b????c????????ca?b???????c??bc????????a?b??b??a??cc?b???????a??a?ab?a?ca?a???????c????????b????b?c\nabaab", "output": "55" }, { "input": "????????baaab\naaabaaab", "output": "2" }, { "input": "baaab????????\nbaaabaaa", "output": "2" }, { "input": "??????????????????????????\nabacaba", "output": "5" } ]
1,566,122,547
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
13
3,000
52,121,600
from string import ascii_lowercase def prefix_function(s): n = len(s) pi = [0]*n for i in range(1, n): j = pi[i-1] while j>0 and s[i] != s[j]: j = pi[j-1] if s[i] == s[j]: j+=1 pi[i] = j return pi s = input() t = input() pi = prefix_function(t+'#') next = [[0]*26 for _ in range(len(t)+1)] for i in range(len(t)+1): for k,c in enumerate(ascii_lowercase): j = i while j>0 and c != (t+'#')[j]: j = pi[j-1] if c == t[j]: next[i][k] = j+1 else: next[i][k] = j dp = [[-1]*(len(t)+1) for _ in range(len(s)+1)] pivals = {0} for i,c in enumerate(s,start=1): npivals = set() if c == '?': for c in ascii_lowercase: for p in pivals: np = next[p][ord(c) - ord('a')] dp[i][np] = max(0, dp[i-1][p], dp[i][np]) npivals.add(np) if np == len(t): dp[i][np] += 1 else: for p in pivals: np = next[p][ord(c) - ord('a')] dp[i][np] = max(0, dp[i-1][p], dp[i][np]) npivals.add(np) if np == len(t): dp[i][np] += 1 pivals = npivals print(max(dp[-1]))
Title: Anthem of Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible. He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work. The anthem is the string *s* of no more than 105 small Latin letters and question marks. The most glorious victory is the string *t* of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string *t* in string *s* is maximal. Note that the occurrences of string *t* in *s* can overlap. Check the third example for clarification. Input Specification: The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105). The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105). Product of lengths of strings |*s*|·|*t*| won't exceed 107. Output Specification: Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. Demo Input: ['winlose???winl???w??\nwin\n', 'glo?yto?e??an?\nor\n', '??c?????\nabcab\n'] Demo Output: ['5\n', '3\n', '2\n'] Note: In the first example the resulting string *s* is "winlosewinwinlwinwin" In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary. In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab".
```python from string import ascii_lowercase def prefix_function(s): n = len(s) pi = [0]*n for i in range(1, n): j = pi[i-1] while j>0 and s[i] != s[j]: j = pi[j-1] if s[i] == s[j]: j+=1 pi[i] = j return pi s = input() t = input() pi = prefix_function(t+'#') next = [[0]*26 for _ in range(len(t)+1)] for i in range(len(t)+1): for k,c in enumerate(ascii_lowercase): j = i while j>0 and c != (t+'#')[j]: j = pi[j-1] if c == t[j]: next[i][k] = j+1 else: next[i][k] = j dp = [[-1]*(len(t)+1) for _ in range(len(s)+1)] pivals = {0} for i,c in enumerate(s,start=1): npivals = set() if c == '?': for c in ascii_lowercase: for p in pivals: np = next[p][ord(c) - ord('a')] dp[i][np] = max(0, dp[i-1][p], dp[i][np]) npivals.add(np) if np == len(t): dp[i][np] += 1 else: for p in pivals: np = next[p][ord(c) - ord('a')] dp[i][np] = max(0, dp[i-1][p], dp[i][np]) npivals.add(np) if np == len(t): dp[i][np] += 1 pivals = npivals print(max(dp[-1])) ```
0
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,518,699,432
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
5,632,000
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) mx1=0 mx2=0 for i in range(n): for j in range(m): if a[i]*b[j]>mx1: mx2=mx1 mx1=a[i]*b[j] else: mx2=max(mx2,a[i]*b[j]) print(mx2)
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) mx1=0 mx2=0 for i in range(n): for j in range(m): if a[i]*b[j]>mx1: mx2=mx1 mx1=a[i]*b[j] else: mx2=max(mx2,a[i]*b[j]) print(mx2) ```
0
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "output": "33" }, { "input": "4", "output": "2" }, { "input": "3", "output": "1" }, { "input": "5", "output": "2" }, { "input": "19", "output": "3" }, { "input": "20", "output": "4" }, { "input": "9880", "output": "38" }, { "input": "9879", "output": "37" }, { "input": "7770", "output": "35" }, { "input": "7769", "output": "34" }, { "input": "2925", "output": "25" }, { "input": "220", "output": "10" }, { "input": "219", "output": "9" }, { "input": "3046", "output": "25" }, { "input": "7590", "output": "34" }, { "input": "1014", "output": "17" }, { "input": "7142", "output": "34" }, { "input": "9999", "output": "38" }, { "input": "10000", "output": "38" } ]
1,689,658,891
2,147,483,647
Python 3
OK
TESTS
25
46
0
n = int(input()) h= 0 sc= 0 while sc <= n: h += 1 sc += (h* (h + 1)) // 2 print(h - 1)
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. Output Specification: Print the maximum possible height of the pyramid in the single line. Demo Input: ['1\n', '25\n'] Demo Output: ['1\n', '4\n'] Note: Illustration to the second sample:
```python n = int(input()) h= 0 sc= 0 while sc <= n: h += 1 sc += (h* (h + 1)) // 2 print(h - 1) ```
3
967
A
Mind the Gap
PROGRAMMING
1,100
[ "implementation" ]
null
null
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff.
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
[ "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n", "3 17\n0 30\n1 0\n12 0\n" ]
[ "6 1\n", "24 50\n", "0 0\n" ]
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff. In the third example Arkady can insert the takeoff even between the first landing.
500
[ { "input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1" }, { "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50" }, { "input": "3 17\n0 30\n1 0\n12 0", "output": "0 0" }, { "input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7", "output": "23 8" }, { "input": "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22", "output": "6 47" }, { "input": "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37", "output": "23 58" }, { "input": "66 20\n0 16\n0 45\n0 58\n1 6\n1 19\n2 7\n2 9\n3 9\n3 25\n3 57\n4 38\n4 58\n5 21\n5 40\n6 16\n6 19\n6 58\n7 6\n7 26\n7 51\n8 13\n8 36\n8 55\n9 1\n9 15\n9 33\n10 12\n10 37\n11 15\n11 34\n12 8\n12 37\n12 55\n13 26\n14 0\n14 34\n14 36\n14 48\n15 23\n15 29\n15 43\n16 8\n16 41\n16 45\n17 5\n17 7\n17 15\n17 29\n17 46\n18 12\n18 19\n18 38\n18 57\n19 32\n19 58\n20 5\n20 40\n20 44\n20 50\n21 18\n21 49\n22 18\n22 47\n23 1\n23 38\n23 50", "output": "1 40" }, { "input": "1 1\n0 0", "output": "0 2" }, { "input": "10 1\n0 2\n0 4\n0 5\n0 8\n0 9\n0 11\n0 13\n0 16\n0 19\n0 21", "output": "0 0" }, { "input": "10 1\n0 2\n0 5\n0 8\n0 11\n0 15\n0 17\n0 25\n0 28\n0 29\n0 32", "output": "0 0" }, { "input": "15 20\n0 47\n2 24\n4 19\n4 34\n5 46\n8 15\n9 8\n10 28\n17 47\n17 52\n18 32\n19 50\n20 46\n20 50\n23 21", "output": "0 0" }, { "input": "1 5\n1 0", "output": "0 0" }, { "input": "24 60\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59", "output": "25 0" }, { "input": "1 30\n0 29", "output": "1 0" }, { "input": "1 2\n3 0", "output": "0 0" }, { "input": "16 60\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "25 0" }, { "input": "1 5\n0 6", "output": "0 0" }, { "input": "2 60\n0 59\n23 59", "output": "2 0" }, { "input": "1 58\n0 1", "output": "1 0" }, { "input": "25 60\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59", "output": "25 0" }, { "input": "2 3\n0 3\n0 30", "output": "0 7" }, { "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 9", "output": "24 0" }, { "input": "1 60\n2 0", "output": "0 0" }, { "input": "2 60\n0 0\n5 0", "output": "1 1" }, { "input": "1 30\n0 31", "output": "0 0" }, { "input": "2 60\n0 59\n3 1", "output": "2 0" }, { "input": "2 60\n0 59\n5 0", "output": "2 0" }, { "input": "1 59\n0 0", "output": "1 0" }, { "input": "3 25\n0 0\n1 0\n2 0", "output": "0 26" }, { "input": "1 2\n2 3", "output": "0 0" } ]
1,525,010,015
2,315
Python 3
OK
TESTS
34
93
7,065,600
def next(h1, m1, minutes): return (h1 + (m1 + minutes) // 60, (m1 + minutes) % 60) n, s = map(int, input().split()) schedule = [] for i in range(n): schedule.append(tuple(map(int, input().split()))) if schedule[0][0] * 60 + schedule[0][1] >= s + 1: print('0 0') else: for i in range(1, len(schedule)): if (schedule[i][0] - schedule[i-1][0]) * 60 + (schedule[i][1] - schedule[i-1][1]) >= 2 * s + 2: res = next(schedule[i-1][0], schedule[i-1][1], s + 1) print(str(res[0]) + ' ' + str(res[1])) break; else: res = next(schedule[i][0], schedule[i][1], s + 1) print(str(res[0]) + ' ' + str(res[1]))
Title: Mind the Gap Time Limit: None seconds Memory Limit: None megabytes Problem Description: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff. Input Specification: The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. Output Specification: Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. Demo Input: ['6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n', '16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n', '3 17\n0 30\n1 0\n12 0\n'] Demo Output: ['6 1\n', '24 50\n', '0 0\n'] Note: In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff. In the third example Arkady can insert the takeoff even between the first landing.
```python def next(h1, m1, minutes): return (h1 + (m1 + minutes) // 60, (m1 + minutes) % 60) n, s = map(int, input().split()) schedule = [] for i in range(n): schedule.append(tuple(map(int, input().split()))) if schedule[0][0] * 60 + schedule[0][1] >= s + 1: print('0 0') else: for i in range(1, len(schedule)): if (schedule[i][0] - schedule[i-1][0]) * 60 + (schedule[i][1] - schedule[i-1][1]) >= 2 * s + 2: res = next(schedule[i-1][0], schedule[i-1][1], s + 1) print(str(res[0]) + ' ' + str(res[1])) break; else: res = next(schedule[i][0], schedule[i][1], s + 1) print(str(res[0]) + ' ' + str(res[1])) ```
3
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111", "output": "10" }, { "input": "1\n0", "output": "0" }, { "input": "8\n10101010", "output": "10000" }, { "input": "2\n10", "output": "10" }, { "input": "3\n111", "output": "1" }, { "input": "5\n11100", "output": "100" }, { "input": "2\n11", "output": "1" }, { "input": "3\n110", "output": "10" }, { "input": "50\n10010010000000000000000000000000000000001000000000", "output": "10000000000000000000000000000000000000000000000" } ]
1,699,192,887
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) t = input() c=0 for i in t: if i==0: c+=1 print(bin(2**c))
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. Output Specification: Print one string — the minimum correct string that you can obtain from the given one. Demo Input: ['4\n1001\n', '1\n1\n'] Demo Output: ['100\n', '1\n'] Note: In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
```python n = int(input()) t = input() c=0 for i in t: if i==0: c+=1 print(bin(2**c)) ```
0
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,541,493,921
2,147,483,647
Python 3
OK
TESTS
81
248
0
n=int(input()) matrix=[[int(x) for x in input().split()]for y in range(n)] m=0 z=0 d=0 p=0 for y in range(n): m=m+matrix[y][0] if m==0: p=0 else : p=p+1 for y in range(n): d=d+matrix[y][1] if d==0: p=0 else : p=p+1 for y in range(n): d=d+matrix[y][2] if m==0: p=0 else : p=p+1 if p==0: print("YES") else : print("NO") 10
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()) matrix=[[int(x) for x in input().split()]for y in range(n)] m=0 z=0 d=0 p=0 for y in range(n): m=m+matrix[y][0] if m==0: p=0 else : p=p+1 for y in range(n): d=d+matrix[y][1] if d==0: p=0 else : p=p+1 for y in range(n): d=d+matrix[y][2] if m==0: p=0 else : p=p+1 if p==0: print("YES") else : print("NO") 10 ```
3.938
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 13 4 3 2", "output": "36" }, { "input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "output": "55" }, { "input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "output": "36" }, { "input": "6\n1000 1 2000 1 3000 1", "output": "11995" }, { "input": "1\n0", "output": "0" }, { "input": "5\n1000000000 1 1000000000 1 1000000000", "output": "4999999996" }, { "input": "5\n1000000000 0 1000000000 0 1000000000", "output": "5000000000" }, { "input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0", "output": "10000000000" }, { "input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "19000000000" }, { "input": "7\n0 1000000000 0 1000000000 0 1000000000 0", "output": "6000000000" }, { "input": "4\n1000000000 -1000000000 1000000000 -1000000000", "output": "7000000000" }, { "input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "39000000000" }, { "input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000", "output": "11000000000" }, { "input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "9000000000" }, { "input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "43000000000" } ]
1,483,811,111
2,147,483,647
Python 3
OK
TESTS
76
217
22,016,000
a=int(input()) x=list(map(int,input().split())) t=abs(x[0]) if a>1: for i in range(1,a): t+=abs(x[i-1]-x[i]) print(t)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). Output Specification: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Demo Input: ['5\n1 2 3 4 5\n', '4\n1 2 2 1\n'] Demo Output: ['5', '3'] Note: In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
```python a=int(input()) x=list(map(int,input().split())) t=abs(x[0]) if a>1: for i in range(1,a): t+=abs(x[i-1]-x[i]) print(t) ```
3
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "input": "24 22 9235", "output": "34" }, { "input": "74 8 417", "output": "1" }, { "input": "972 1 203", "output": "0" }, { "input": "550 1 754", "output": "1" }, { "input": "860 1 884", "output": "1" }, { "input": "358 2 809", "output": "2" }, { "input": "33 27 216", "output": "0" }, { "input": "2940 1 9311", "output": "3" }, { "input": "4624 1 1953", "output": "0" }, { "input": "2696 2 7345", "output": "2" }, { "input": "3443 2 6701", "output": "0" }, { "input": "3 613 2275", "output": "1" }, { "input": "1 10000 10000", "output": "1" }, { "input": "10000 1 10000", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1 10000", "output": "10000" }, { "input": "34 27 10000", "output": "10" }, { "input": "2 2 9999", "output": "4999" }, { "input": "2 2 1", "output": "0" }, { "input": "6 4 36", "output": "3" }, { "input": "33 6 3005", "output": "45" }, { "input": "5 1 20", "output": "4" }, { "input": "1 2 10", "output": "5" }, { "input": "2 1 100", "output": "50" }, { "input": "10 20 10000", "output": "500" }, { "input": "8 12 12", "output": "0" } ]
1,489,911,641
2,147,483,647
Python 3
OK
TESTS
32
93
5,836,800
from fractions import gcd n,m,z = map(int , input().split()) gc = n*m//gcd(n,m) print(z//gc)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. Input Specification: The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). Output Specification: Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Demo Input: ['1 1 10\n', '1 2 5\n', '2 3 9\n'] Demo Output: ['10\n', '2\n', '1\n'] Note: Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
```python from fractions import gcd n,m,z = map(int , input().split()) gc = n*m//gcd(n,m) print(z//gc) ```
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,686,928,603
2,147,483,647
Python 3
OK
TESTS
34
92
0
m = list(map(int, input().split())) num = 0 d = dict() for i in m: d[i] = m.count(i) print(4 - len(d))
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 m = list(map(int, input().split())) num = 0 d = dict() for i in m: d[i] = m.count(i) print(4 - len(d)) ```
3
710
A
King Moves
PROGRAMMING
800
[ "implementation" ]
null
null
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wiki/King_(chess)).
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer *x* — the number of moves permitted for the king.
[ "e4\n" ]
[ "8\n" ]
none
0
[ { "input": "e4", "output": "8" }, { "input": "a1", "output": "3" }, { "input": "h8", "output": "3" }, { "input": "a4", "output": "5" }, { "input": "g7", "output": "8" }, { "input": "e1", "output": "5" }, { "input": "b2", "output": "8" }, { "input": "c7", "output": "8" }, { "input": "h6", "output": "5" }, { "input": "c8", "output": "5" }, { "input": "h2", "output": "5" }, { "input": "h5", "output": "5" }, { "input": "a8", "output": "3" }, { "input": "f8", "output": "5" }, { "input": "h1", "output": "3" }, { "input": "f2", "output": "8" }, { "input": "e8", "output": "5" }, { "input": "h3", "output": "5" }, { "input": "b8", "output": "5" }, { "input": "g8", "output": "5" }, { "input": "d8", "output": "5" }, { "input": "h4", "output": "5" }, { "input": "b1", "output": "5" }, { "input": "a2", "output": "5" } ]
1,517,596,057
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
5,632,000
t = input("") if (t == 'a1' or t == 'h1' or t == 'h8' or t == 'h1' ): print('3') else : for i in t: if (t[1]==1 or t[1]==8): print('5') else: print('8')
Title: King Moves Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wiki/King_(chess)). Input Specification: The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Specification: Print the only integer *x* — the number of moves permitted for the king. Demo Input: ['e4\n'] Demo Output: ['8\n'] Note: none
```python t = input("") if (t == 'a1' or t == 'h1' or t == 'h8' or t == 'h1' ): print('3') else : for i in t: if (t[1]==1 or t[1]==8): print('5') else: print('8') ```
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,567,446,064
2,147,483,647
Python 3
OK
TESTS
35
109
0
n = int(input()) l = list(map(int,input().split())) l.sort() for i in range(n-1): if i % 2 == 0: l.pop() else: l.pop(0) for i in l: print(i)
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 n = int(input()) l = list(map(int,input().split())) l.sort() for i in range(n-1): if i % 2 == 0: l.pop() else: l.pop(0) for i in l: print(i) ```
3
717
B
R3D3’s Summer Adventure
PROGRAMMING
2,700
[ "dp", "greedy" ]
null
null
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher. There are *n* letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help. Given the costs *c*0 and *c*1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost.
The first line of input contains three integers *n* (2<=≤<=*n*<=≤<=108), *c*0 and *c*1 (0<=≤<=*c*0,<=*c*1<=≤<=108) — the number of letters in the alphabet, and costs of '0' and '1', respectively.
Output a single integer — minimum possible total a cost of the whole alphabet.
[ "4 1 2\n" ]
[ "12\n" ]
There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12.
0
[ { "input": "4 1 2", "output": "12" }, { "input": "2 1 5", "output": "6" }, { "input": "3 1 1", "output": "5" }, { "input": "5 5 5", "output": "60" }, { "input": "4 0 0", "output": "0" }, { "input": "6 0 6", "output": "30" }, { "input": "6 6 0", "output": "30" }, { "input": "2 1 2", "output": "3" }, { "input": "100000000 1 0", "output": "99999999" }, { "input": "2 0 0", "output": "0" }, { "input": "2 100000000 100000000", "output": "200000000" }, { "input": "2 100000000 0", "output": "100000000" }, { "input": "2 0 100000000", "output": "100000000" }, { "input": "100000000 0 0", "output": "0" }, { "input": "100000000 100000000 100000000", "output": "266578227200000000" }, { "input": "100000000 100000000 0", "output": "9999999900000000" }, { "input": "100000000 0 100000000", "output": "9999999900000000" }, { "input": "2 50000000 0", "output": "50000000" }, { "input": "2 50000000 100000000", "output": "150000000" }, { "input": "2 50000000 0", "output": "50000000" }, { "input": "2 50000000 100000000", "output": "150000000" }, { "input": "100000000 50000000 0", "output": "4999999950000000" }, { "input": "100000000 50000000 100000000", "output": "191720992950000000" }, { "input": "100000000 50000000 0", "output": "4999999950000000" }, { "input": "100000000 50000000 100000000", "output": "191720992950000000" }, { "input": "96212915 66569231 66289469", "output": "170023209909758400" }, { "input": "39969092 91869601 91924349", "output": "93003696194821620" }, { "input": "26854436 29462638 67336233", "output": "30373819153055635" }, { "input": "39201451 80233602 30662934", "output": "50953283386656312" }, { "input": "92820995 96034432 40568102", "output": "158135215198065044" }, { "input": "81913246 61174868 31286889", "output": "96084588586645841" }, { "input": "74790405 66932852 48171076", "output": "111690840882243696" }, { "input": "88265295 26984472 18821097", "output": "52835608063500861" }, { "input": "39858798 77741429 44017779", "output": "59709461677488470" }, { "input": "70931513 41663344 29095671", "output": "64816798089350400" }, { "input": "68251617 52232534 34187120", "output": "75694251898945158" }, { "input": "44440915 82093126 57268128", "output": "77907273273831800" }, { "input": "61988457 90532323 72913492", "output": "130757350538583270" }, { "input": "13756397 41019327 86510346", "output": "19895886795999000" }, { "input": "84963589 37799442 20818727", "output": "63754887412974663" }, { "input": "99338896 62289589 49020203", "output": "146320678028775569" }, { "input": "1505663 3257962 1039115", "output": "60023256524142" }, { "input": "80587587 25402325 8120971", "output": "32044560697691212" }, { "input": "64302230 83635846 22670768", "output": "77790985833197594" }, { "input": "6508457 32226669 8706339", "output": "2645634460061466" }, { "input": "1389928 84918086 54850899", "output": "1953921305304795" }, { "input": "37142108 10188690 35774598", "output": "19009588918065432" }, { "input": "86813943 11824369 38451380", "output": "51645349299460766" }, { "input": "14913475 61391038 9257618", "output": "9761450207212562" }, { "input": "25721978 63666459 14214946", "output": "20847031763747988" }, { "input": "73363656 63565575 76409698", "output": "133919836504944416" }, { "input": "34291060 92893503 64680754", "output": "66960630525688676" }, { "input": "85779772 26434899 86820336", "output": "114681463889615136" }, { "input": "7347370 2098650 66077918", "output": "3070602135161752" }, { "input": "28258585 6194848 49146833", "output": "14441957862691571" }, { "input": "9678 133 5955", "output": "196970292" }, { "input": "9251 4756 2763", "output": "448302621" }, { "input": "1736 5628 2595", "output": "73441521" }, { "input": "5195 1354 2885", "output": "130236572" }, { "input": "1312 5090 9909", "output": "98808420" }, { "input": "8619 6736 9365", "output": "900966230" }, { "input": "151 7023 3093", "output": "5267919" }, { "input": "5992 2773 6869", "output": "340564941" }, { "input": "3894 9921 3871", "output": "299508763" }, { "input": "1006 9237 1123", "output": "38974261" }, { "input": "9708 3254 2830", "output": "391502526" }, { "input": "1504 1123 626", "output": "13538132" }, { "input": "8642 5709 51", "output": "135655830" }, { "input": "8954 4025 7157", "output": "641304164" }, { "input": "4730 8020 8722", "output": "484587068" }, { "input": "2500 5736 4002", "output": "136264140" }, { "input": "6699 4249 1068", "output": "196812772" }, { "input": "4755 6759 4899", "output": "336456318" }, { "input": "8447 1494 4432", "output": "298387478" }, { "input": "6995 4636 8251", "output": "561476311" }, { "input": "4295 9730 4322", "output": "346320888" }, { "input": "8584 4286 9528", "output": "738058224" }, { "input": "174 6826 355", "output": "2889605" }, { "input": "5656 7968 3400", "output": "379249528" }, { "input": "2793 175 3594", "output": "36405762" }, { "input": "2888 9056 3931", "output": "204521173" }, { "input": "6222 7124 6784", "output": "547839384" }, { "input": "8415 8714 2475", "output": "545452719" }, { "input": "2179 7307 8608", "output": "192281235" }, { "input": "1189 1829 6875", "output": "46521099" } ]
1,473,591,828
7,428
Python 3
WRONG_ANSWER
TESTS
1
46
0
import math k,l,r=map(int,input().split()) print('%g'%(math.factorial(k)/2**(r-l)))
Title: R3D3’s Summer Adventure Time Limit: None seconds Memory Limit: None megabytes Problem Description: R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher. There are *n* letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help. Given the costs *c*0 and *c*1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost. Input Specification: The first line of input contains three integers *n* (2<=≤<=*n*<=≤<=108), *c*0 and *c*1 (0<=≤<=*c*0,<=*c*1<=≤<=108) — the number of letters in the alphabet, and costs of '0' and '1', respectively. Output Specification: Output a single integer — minimum possible total a cost of the whole alphabet. Demo Input: ['4 1 2\n'] Demo Output: ['12\n'] Note: There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12.
```python import math k,l,r=map(int,input().split()) print('%g'%(math.factorial(k)/2**(r-l))) ```
0
825
A
Binary Protocol
PROGRAMMING
1,100
[ "implementation" ]
null
null
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Print the decoded number.
[ "3\n111\n", "9\n110011101\n" ]
[ "3\n", "2031\n" ]
none
0
[ { "input": "3\n111", "output": "3" }, { "input": "9\n110011101", "output": "2031" }, { "input": "1\n1", "output": "1" }, { "input": "3\n100", "output": "100" }, { "input": "5\n10001", "output": "1001" }, { "input": "14\n11001100011000", "output": "202002000" }, { "input": "31\n1000011111111100011110111111111", "output": "100090049" }, { "input": "53\n10110111011110111110111111011111110111111110111111111", "output": "123456789" }, { "input": "89\n11111111101111111110111111111011111111101111111110111111111011111111101111111110111111111", "output": "999999999" }, { "input": "10\n1000000000", "output": "1000000000" }, { "input": "2\n10", "output": "10" }, { "input": "4\n1110", "output": "30" }, { "input": "8\n10101010", "output": "11110" } ]
1,500,218,872
1,372
PyPy 3
RUNTIME_ERROR
TESTS
0
78
23,142,400
input() print(join(map(lambda x:str(x), map(lambda x: len(x),input().split('0')))))
Title: Binary Protocol Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'. Output Specification: Print the decoded number. Demo Input: ['3\n111\n', '9\n110011101\n'] Demo Output: ['3\n', '2031\n'] Note: none
```python input() print(join(map(lambda x:str(x), map(lambda x: len(x),input().split('0'))))) ```
-1
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
500
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
1,532,757,175
2,147,483,647
Python 3
OK
TESTS
53
124
0
data = list(map(int, input().split())) s = sum(data) if s % 2 == 1: print("no") else: ans = False for i in range(1, 5): for j in range(i + 1, 6): if data[0] + data[i] + data[j] == s // 2: ans = True if ans: print("yes") else: print("no")
Title: ACM ICPC Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input Specification: The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants Output Specification: Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['1 3 2 1 2 1\n', '1 1 1 1 1 99\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
```python data = list(map(int, input().split())) s = sum(data) if s % 2 == 1: print("no") else: ans = False for i in range(1, 5): for j in range(i + 1, 6): if data[0] + data[i] + data[j] == s // 2: ans = True if ans: print("yes") else: print("no") ```
3
389
B
Fox and Cross
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way.
The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'.
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
[ "5\n.#...\n####.\n.####\n...#.\n.....\n", "4\n####\n####\n####\n####\n", "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n", "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n", "3\n...\n...\n...\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ]
In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
1,000
[ { "input": "4\n####\n####\n####\n####", "output": "NO" }, { "input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.", "output": "YES" }, { "input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.", "output": "NO" }, { "input": "5\n.....\n.#...\n####.\n.####\n...#.", "output": "YES" }, { "input": "5\n#....\n###..\n.###.\n..##.\n..##.", "output": "NO" }, { "input": "10\n....#...#.\n.#.###.###\n#####.#.#.\n.#######..\n.#.##.#.#.\n######.###\n.#..#.#.#.\n.#..#####.\n##########\n.#..#...#.", "output": "YES" }, { "input": "8\n.#...##.\n##.##.#.\n#....##.\n#.###.##\n...##..#\n#..#.##.\n#..#.#..\n#....###", "output": "NO" }, { "input": "15\n.#...##.##.....\n.###.#.#.##..#.\n##.#####......#\n#....###.#..#..\n#.##.#.###.###.\n.###....#.###.#\n##.....##..#...\n.#.########...#\n##..#..##..#.##\n#...#....##....\n.......#.......\n.#..#.#.####...\n.#..#...#..###.\n#..#.#..#......\n###.....##....#", "output": "NO" }, { "input": "7\n.......\n.......\n.......\n.......\n.....#.\n....###\n.....#.", "output": "YES" }, { "input": "9\n.#.#....#\n#.#.....#\n.#..#..#.\n#.#....##\n...#...#.\n#..###.#.\n....#..##\n.#.###...\n....##..#", "output": "NO" }, { "input": "5\n#...#\n.....\n..#..\n.....\n#...#", "output": "NO" }, { "input": "3\n.#.\n#.#\n.#.", "output": "NO" }, { "input": "3\n...\n...\n..#", "output": "NO" } ]
1,684,315,054
2,147,483,647
PyPy 3-64
OK
TESTS
42
77
2,252,800
def check(a, b, n): return a>=0 and b>=0 and a<n and b<n def solve(): n = int(input()) ar = [] for i in range(n): ar.append(input()) cross = [[0]*n for _ in range(n)] addc = [(1, 0), (2, 0), (1, -1), (1, 1)] for i in range(n): for j in range(n): if ar[i][j] == "#" and cross[i][j] == 0: cross[i][j] = 1 for a, b in addc: if check(i+a, j+b, n): #print(ar[i+a][j+b], cross[i+a][j+b]) if ar[i+a][j+b] == "#" and cross[i+a][j+b] == 0: cross[i+a][j+b] = 1 else: print("NO") return else: print("NO") return print("YES") solve()
Title: Fox and Cross Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way. Input Specification: The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. Output Specification: Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". Demo Input: ['5\n.#...\n####.\n.####\n...#.\n.....\n', '4\n####\n####\n####\n####\n', '6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n', '6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n', '3\n...\n...\n...\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
```python def check(a, b, n): return a>=0 and b>=0 and a<n and b<n def solve(): n = int(input()) ar = [] for i in range(n): ar.append(input()) cross = [[0]*n for _ in range(n)] addc = [(1, 0), (2, 0), (1, -1), (1, 1)] for i in range(n): for j in range(n): if ar[i][j] == "#" and cross[i][j] == 0: cross[i][j] = 1 for a, b in addc: if check(i+a, j+b, n): #print(ar[i+a][j+b], cross[i+a][j+b]) if ar[i+a][j+b] == "#" and cross[i+a][j+b] == 0: cross[i+a][j+b] = 1 else: print("NO") return else: print("NO") return print("YES") solve() ```
3
246
A
Buggy Sorting
PROGRAMMING
900
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number *n* and array *a*. But Valera could have made a mistake, because he hasn't yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of *n* doesn't exist, print -1.
You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array.
Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1. If there are several counter-examples, consisting of *n* numbers, you are allowed to print any of them.
[ "1\n" ]
[ "-1\n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "3 2 1 " }, { "input": "4", "output": "4 3 2 1 " }, { "input": "5", "output": "5 4 3 2 1 " }, { "input": "6", "output": "6 5 4 3 2 1 " }, { "input": "7", "output": "7 6 5 4 3 2 1 " }, { "input": "8", "output": "8 7 6 5 4 3 2 1 " }, { "input": "9", "output": "9 8 7 6 5 4 3 2 1 " }, { "input": "50", "output": "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 " }, { "input": "22", "output": "22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "34", "output": "34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "50", "output": "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 " }, { "input": "12", "output": "12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "26", "output": "26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "38", "output": "38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "4", "output": "4 3 2 1 " }, { "input": "18", "output": "18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "30", "output": "30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "46", "output": "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 " }, { "input": "32", "output": "32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " } ]
1,547,271,130
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
92
0
n = int(input()) if n == 1 or n == 2: print(-1) exit() ans = [] for i in range(1,n-1): for j in range(i,n-1): ans.append(i) if ans[j]>ans[j-1]: a[j-1],a[j]=a[j-1],a[j] print(ans)
Title: Buggy Sorting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number *n* and array *a*. But Valera could have made a mistake, because he hasn't yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of *n* doesn't exist, print -1. Input Specification: You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. Output Specification: Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1. If there are several counter-examples, consisting of *n* numbers, you are allowed to print any of them. Demo Input: ['1\n'] Demo Output: ['-1\n'] Note: none
```python n = int(input()) if n == 1 or n == 2: print(-1) exit() ans = [] for i in range(1,n-1): for j in range(i,n-1): ans.append(i) if ans[j]>ans[j-1]: a[j-1],a[j]=a[j-1],a[j] print(ans) ```
-1
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111", "output": "10" }, { "input": "1\n0", "output": "0" }, { "input": "8\n10101010", "output": "10000" }, { "input": "2\n10", "output": "10" }, { "input": "3\n111", "output": "1" }, { "input": "5\n11100", "output": "100" }, { "input": "2\n11", "output": "1" }, { "input": "3\n110", "output": "10" }, { "input": "50\n10010010000000000000000000000000000000001000000000", "output": "10000000000000000000000000000000000000000000000" } ]
1,650,560,871
171
PyPy 3
OK
TESTS
14
77
0
import sys input = sys.stdin.buffer.readline def process(S): if S=='0': sys.stdout.write('0') return d = [0, 0] for c in S: d[int(c)]+=1 answer = ['1'] for i in range(d[0]): answer.append('0') answer = ''.join(answer) sys.stdout.write(answer) return n = int(input()) S = input().decode()[:-2] process(S)
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. Output Specification: Print one string — the minimum correct string that you can obtain from the given one. Demo Input: ['4\n1001\n', '1\n1\n'] Demo Output: ['100\n', '1\n'] Note: In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
```python import sys input = sys.stdin.buffer.readline def process(S): if S=='0': sys.stdout.write('0') return d = [0, 0] for c in S: d[int(c)]+=1 answer = ['1'] for i in range(d[0]): answer.append('0') answer = ''.join(answer) sys.stdout.write(answer) return n = int(input()) S = input().decode()[:-2] process(S) ```
3
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "output": "1" }, { "input": "7\n7 7 7 7 7 7 7", "output": "7" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "4" }, { "input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2", "output": "50" }, { "input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99", "output": "49" }, { "input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15", "output": "50" }, { "input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38", "output": "7" }, { "input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87", "output": "39" }, { "input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53", "output": "37" }, { "input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32", "output": "51" }, { "input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80", "output": "21" }, { "input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81", "output": "37" }, { "input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59", "output": "28" }, { "input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94", "output": "47" }, { "input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28", "output": "15" }, { "input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42", "output": "11" }, { "input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35", "output": "33" }, { "input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22", "output": "37" }, { "input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14", "output": "15" }, { "input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77", "output": "35" }, { "input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75", "output": "42" }, { "input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26", "output": "23" }, { "input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78", "output": "15" }, { "input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78", "output": "13" }, { "input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51", "output": "17" }, { "input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59", "output": "45" }, { "input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43", "output": "53" }, { "input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8", "output": "40" }, { "input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54", "output": "53" }, { "input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77", "output": "55" }, { "input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66", "output": "52" }, { "input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89", "output": "51" }, { "input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2", "output": "53" }, { "input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23", "output": "48" }, { "input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25", "output": "48" }, { "input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71", "output": "58" }, { "input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45", "output": "53" }, { "input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17", "output": "54" }, { "input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52", "output": "49" }, { "input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31", "output": "44" }, { "input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74", "output": "46" }, { "input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75", "output": "53" }, { "input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37", "output": "43" }, { "input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82", "output": "51" }, { "input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5", "output": "47" }, { "input": "1\n2", "output": "1" }, { "input": "5\n1 1 3 2 2", "output": "3" } ]
1,592,544,920
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
280
0
n=int(input()) l=list(map(int,input().split())) c1=0 c2=0 for i in l: if(i%2==0): c1+=1 else: c2+=1 if(c2%2==0): print(c1) else: print(1)
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. Output Specification: Print in the only line the only number — the sought number of ways. If there are no such ways print 0. Demo Input: ['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n'] Demo Output: ['1\n', '8\n', '1\n'] Note: In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.
```python n=int(input()) l=list(map(int,input().split())) c1=0 c2=0 for i in l: if(i%2==0): c1+=1 else: c2+=1 if(c2%2==0): print(c1) else: print(1) ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,598,416,042
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
614,400
n,m=map(int,input().split()) a=[0]*m b=[0]*m for i in range(m): a[i],b[i]=map(str,input().split()) c=list(map(str,input().split())) s=[] for i in c: for j in range(len(a)): if(a[j]==i or b[j]==i): if(len(a[j])<=len(b[j])): s.append(a[j]) else: s.append(b[j]) k=' '.join(s) print(k)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n,m=map(int,input().split()) a=[0]*m b=[0]*m for i in range(m): a[i],b[i]=map(str,input().split()) c=list(map(str,input().split())) s=[] for i in c: for j in range(len(a)): if(a[j]==i or b[j]==i): if(len(a[j])<=len(b[j])): s.append(a[j]) else: s.append(b[j]) k=' '.join(s) print(k) ```
0
290
A
Mysterious strings
PROGRAMMING
1,400
[ "*special", "implementation" ]
null
null
The input contains a single integer *a* (1<=≤<=*a*<=≤<=40). Output a single string.
The input contains a single integer *a* (1<=≤<=*a*<=≤<=40).
Output a single string.
[ "2\n", "8\n", "29\n" ]
[ "Adams\n", "Van Buren\n", "Harding\n" ]
none
0
[ { "input": "2", "output": "Adams" }, { "input": "8", "output": "Van Buren" }, { "input": "29", "output": "Harding" }, { "input": "1", "output": "Washington" }, { "input": "3", "output": "Jefferson" }, { "input": "4", "output": "Madison" }, { "input": "5", "output": "Monroe" }, { "input": "6", "output": "Adams" }, { "input": "7", "output": "Jackson" }, { "input": "9", "output": "Harrison" }, { "input": "10", "output": "Tyler" }, { "input": "11", "output": "Polk" }, { "input": "12", "output": "Taylor" }, { "input": "13", "output": "Fillmore" }, { "input": "14", "output": "Pierce" }, { "input": "15", "output": "Buchanan" }, { "input": "16", "output": "Lincoln" }, { "input": "17", "output": "Johnson" }, { "input": "18", "output": "Grant" }, { "input": "19", "output": "Hayes" }, { "input": "20", "output": "Garfield" }, { "input": "21", "output": "Arthur" }, { "input": "22", "output": "Cleveland" }, { "input": "23", "output": "Harrison" }, { "input": "24", "output": "Cleveland" }, { "input": "25", "output": "McKinley" }, { "input": "26", "output": "Roosevelt" }, { "input": "27", "output": "Taft" }, { "input": "28", "output": "Wilson" }, { "input": "30", "output": "Coolidge" }, { "input": "31", "output": "Hoover" }, { "input": "32", "output": "Roosevelt" }, { "input": "33", "output": "Truman" }, { "input": "34", "output": "Eisenhower" }, { "input": "35", "output": "Kennedy" }, { "input": "36", "output": "Johnson" }, { "input": "37", "output": "Nixon" }, { "input": "38", "output": "Ford" }, { "input": "39", "output": "Carter" }, { "input": "40", "output": "Reagan" } ]
1,580,567,612
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; string arrPresidents[40] = { "Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan" }; int main(){ int n; cin>>n; cout<<arrPresidents[n-1]; return 0; }
Title: Mysterious strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (1<=≤<=*a*<=≤<=40). Output a single string. Input Specification: The input contains a single integer *a* (1<=≤<=*a*<=≤<=40). Output Specification: Output a single string. Demo Input: ['2\n', '8\n', '29\n'] Demo Output: ['Adams\n', 'Van Buren\n', 'Harding\n'] Note: none
```python #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; string arrPresidents[40] = { "Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan" }; int main(){ int n; cin>>n; cout<<arrPresidents[n-1]; return 0; } ```
-1
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" }, { "input": "999", "output": "9" }, { "input": "100", "output": "5" }, { "input": "123", "output": "6" }, { "input": "8", "output": "8" }, { "input": "157", "output": "3" }, { "input": "289", "output": "1" }, { "input": "179", "output": "4" }, { "input": "942", "output": "0" }, { "input": "879", "output": "9" }, { "input": "394", "output": "1" }, { "input": "423", "output": "7" }, { "input": "952", "output": "3" }, { "input": "121", "output": "5" }, { "input": "613", "output": "2" }, { "input": "945", "output": "1" }, { "input": "270", "output": "6" }, { "input": "781", "output": "2" }, { "input": "453", "output": "7" }, { "input": "171", "output": "0" }, { "input": "643", "output": "2" }, { "input": "570", "output": "6" }, { "input": "750", "output": "6" }, { "input": "500", "output": "0" }, { "input": "2", "output": "2" }, { "input": "1", "output": "1" }, { "input": "108", "output": "5" }, { "input": "500", "output": "0" }, { "input": "189", "output": "9" }, { "input": "491", "output": "0" }, { "input": "191", "output": "0" } ]
1,636,228,952
2,147,483,647
Python 3
OK
TESTS
37
46
4,300,800
s = '' for i in range(1,371): s+=str(i) def solve(): n = int(input()) print(s[n-1]) for _ in range(1): solve()
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1. Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. Output Specification: Print the *n*-th digit of the line. Demo Input: ['3\n', '11\n'] Demo Output: ['3\n', '0\n'] Note: In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
```python s = '' for i in range(1,371): s+=str(i) def solve(): n = int(input()) print(s[n-1]) for _ in range(1): solve() ```
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,631,613,311
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int a[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>a[i][j]; } } int s=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ s+=a[i][j]; } } if(s==0){ cout<<"YES"; } else{ cout<<"NO"; } }
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python #include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int a[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>a[i][j]; } } int s=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ s+=a[i][j]; } } if(s==0){ cout<<"YES"; } else{ cout<<"NO"; } } ```
-1
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,608,652,505
2,147,483,647
Python 3
OK
TESTS
102
109
0
line1=input() line2=input() output=[] for i in range(len(line1)): if line1[i]==line2[i]: output.append('0') else: output.append('1') print(''.join(output))
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 line1=input() line2=input() output=[] for i in range(len(line1)): if line1[i]==line2[i]: output.append('0') else: output.append('1') print(''.join(output)) ```
3.97275
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,624,733,896
2,147,483,647
Python 3
OK
TESTS
34
154
0
n,k = [*map(int, input().split())] a = [*map(int, input().split())] print(sum(sum(c in '47' for c in str(x))<=k for x in a))
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())] a = [*map(int, input().split())] print(sum(sum(c in '47' for c in str(x))<=k for x in a)) ```
3
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" }, { "input": "8", "output": "1641" }, { "input": "9", "output": "4920" }, { "input": "10", "output": "14763" }, { "input": "15", "output": "3587226" }, { "input": "30", "output": "782663359" }, { "input": "10000000", "output": "192336614" }, { "input": "100", "output": "721510432" }, { "input": "300", "output": "327873818" }, { "input": "900", "output": "295068084" }, { "input": "1500", "output": "451187545" }, { "input": "3000", "output": "645417275" }, { "input": "5000", "output": "755610910" }, { "input": "10000", "output": "723907367" }, { "input": "50000", "output": "969527595" }, { "input": "90000", "output": "548978368" }, { "input": "99999", "output": "909741855" }, { "input": "100000", "output": "729225554" }, { "input": "300000", "output": "93822635" }, { "input": "800000", "output": "178940616" }, { "input": "1000000", "output": "266233856" }, { "input": "4000000", "output": "882155933" }, { "input": "9000000", "output": "295060537" }, { "input": "9999999", "output": "730778875" }, { "input": "1000000", "output": "266233856" }, { "input": "9999999", "output": "730778875" }, { "input": "10000000", "output": "192336614" }, { "input": "9999998", "output": "576926295" }, { "input": "30", "output": "782663359" }, { "input": "31", "output": "347990060" } ]
1,697,616,334
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
62
0
n = int(input()) mod = 10**9 + 7 dp=[0,0,0,1] for step in range(1,n+1): sumdp=sum(dp)%mod dpPrime=[sumdp]*4 dpPrime[0]-=dp[0]%mod dpPrime[1]-=dp[1]%mod dpPrime[2]-=dp[2]%mod dpPrime[3]-=dp[3]%mod dp=dpPrime print(dp[3])
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. Output Specification: Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). Demo Input: ['2\n', '4\n'] Demo Output: ['3\n', '21\n'] Note: The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
```python n = int(input()) mod = 10**9 + 7 dp=[0,0,0,1] for step in range(1,n+1): sumdp=sum(dp)%mod dpPrime=[sumdp]*4 dpPrime[0]-=dp[0]%mod dpPrime[1]-=dp[1]%mod dpPrime[2]-=dp[2]%mod dpPrime[3]-=dp[3]%mod dp=dpPrime print(dp[3]) ```
0
260
A
Adding Digits
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
[ "5 4 5\n", "12 11 1\n", "260 150 10\n" ]
[ "524848\n", "121\n", "-1\n" ]
none
500
[ { "input": "5 4 5", "output": "524848" }, { "input": "12 11 1", "output": "121" }, { "input": "260 150 10", "output": "-1" }, { "input": "78843 5684 42717", "output": "-1" }, { "input": "93248 91435 1133", "output": "-1" }, { "input": "100000 10 64479", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 21 73839", "output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99991 623 36438", "output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 334 94854", "output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99252 9827 84849", "output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99313 9833 10561", "output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "94885 55815 11417", "output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99492 58525 53481", "output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99858 28531 79193", "output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99136 47208 42607", "output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "63270 19953 5555", "output": "-1" }, { "input": "10240 128 100000", "output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "12 11 3", "output": "12100" }, { "input": "14 12 99998", "output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "1 11 3", "output": "1100" }, { "input": "3 40 1", "output": "-1" }, { "input": "150 100 10", "output": "1500000000000" }, { "input": "5 10 1", "output": "50" }, { "input": "1 15 10", "output": "15000000000" }, { "input": "3 13 2", "output": "390" } ]
1,555,519,428
2,147,483,647
PyPy 3
OK
TESTS
25
1,341
8,192,000
a, b, n = map(int, input().split()) res = -1 for d in range(10): if (a*10+d) % b == 0: res = a*10+d for i in range(1, n): res *= 10 break print(res)
Title: Adding Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. Input Specification: The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). Output Specification: In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. Demo Input: ['5 4 5\n', '12 11 1\n', '260 150 10\n'] Demo Output: ['524848\n', '121\n', '-1\n'] Note: none
```python a, b, n = map(int, input().split()) res = -1 for d in range(10): if (a*10+d) % b == 0: res = a*10+d for i in range(1, n): res *= 10 break print(res) ```
3
242
B
Big Segment
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide.
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.
[ "3\n1 1\n2 2\n3 3\n", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n" ]
[ "-1\n", "3\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "-1" }, { "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3" }, { "input": "4\n1 5\n2 2\n2 4\n2 5", "output": "1" }, { "input": "5\n3 3\n1 3\n2 2\n2 3\n1 2", "output": "2" }, { "input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8", "output": "-1" }, { "input": "3\n2 5\n3 4\n2 3", "output": "1" }, { "input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19", "output": "-1" }, { "input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3", "output": "1" }, { "input": "1\n1 100000", "output": "1" }, { "input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5", "output": "6" }, { "input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19", "output": "-1" }, { "input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8", "output": "-1" }, { "input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6", "output": "37" }, { "input": "1\n999999999 1000000000", "output": "1" }, { "input": "3\n1 20\n2 22\n3 18", "output": "-1" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "2\n100001 100008\n100005 100006", "output": "1" }, { "input": "1\n1000000 10000000", "output": "1" }, { "input": "3\n3 6\n2 4\n1 5", "output": "-1" }, { "input": "2\n3 5\n1 2", "output": "-1" } ]
1,606,393,696
2,147,483,647
Python 3
OK
TESTS
45
716
10,035,200
n = int(input()) lst = [] for i in range(n): lst.append(list(map(int, input().split()))) max_val = lst[0][0] min_val = lst[0][1] for index in range(len(lst)): if lst[index][0] <= min_val: min_val = lst[index][0] if lst[index][1] >= max_val: max_val = lst[index][1] if [min_val, max_val] in lst: print(lst.index([min_val, max_val]) + 1) else: print(-1)
Title: Big Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide. Output Specification: Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input. Demo Input: ['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n'] Demo Output: ['-1\n', '3\n'] Note: none
```python n = int(input()) lst = [] for i in range(n): lst.append(list(map(int, input().split()))) max_val = lst[0][0] min_val = lst[0][1] for index in range(len(lst)): if lst[index][0] <= min_val: min_val = lst[index][0] if lst[index][1] >= max_val: max_val = lst[index][1] if [min_val, max_val] in lst: print(lst.index([min_val, max_val]) + 1) else: print(-1) ```
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,674,685,360
2,147,483,647
Python 3
OK
TESTS
20
46
0
count = int(input()) for i in range(count): i = input() if len(i) <= 10: print(i) else: print(i[0] + str(len(i) - 2) + i[-1])
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 count = int(input()) for i in range(count): i = input() if len(i) <= 10: print(i) else: print(i[0] + str(len(i) - 2) + i[-1]) ```
3.977
899
C
Dividing the numbers
PROGRAMMING
1,300
[ "constructive algorithms", "graphs", "math" ]
null
null
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
[ "4\n", "2\n" ]
[ "0\n2 1 4 \n", "1\n1 1 \n" ]
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
1,500
[ { "input": "4", "output": "0\n2 1 4 " }, { "input": "2", "output": "1\n1 1 " }, { "input": "3", "output": "0\n1\n3 " }, { "input": "5", "output": "1\n3\n1 2 5 " }, { "input": "59998", "output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "60000", "output": "0\n30000 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59991", "output": "0\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59989", "output": "1\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "6", "output": "1\n3 1 4 5 " }, { "input": "7", "output": "0\n3\n1 6 7 " }, { "input": "8", "output": "0\n4 1 4 5 8 " }, { "input": "9", "output": "1\n5\n1 2 3 8 9 " }, { "input": "10", "output": "1\n5 1 4 5 8 9 " }, { "input": "11", "output": "0\n5\n1 2 9 10 11 " }, { "input": "12", "output": "0\n6 1 4 5 8 9 12 " }, { "input": "13", "output": "1\n7\n1 2 3 4 11 12 13 " }, { "input": "14", "output": "1\n7 1 4 5 8 9 12 13 " }, { "input": "15", "output": "0\n7\n1 2 3 12 13 14 15 " }, { "input": "16", "output": "0\n8 1 4 5 8 9 12 13 16 " }, { "input": "17", "output": "1\n9\n1 2 3 4 5 14 15 16 17 " }, { "input": "18", "output": "1\n9 1 4 5 8 9 12 13 16 17 " }, { "input": "19", "output": "0\n9\n1 2 3 4 15 16 17 18 19 " }, { "input": "20", "output": "0\n10 1 4 5 8 9 12 13 16 17 20 " }, { "input": "21", "output": "1\n11\n1 2 3 4 5 6 17 18 19 20 21 " }, { "input": "22", "output": "1\n11 1 4 5 8 9 12 13 16 17 20 21 " }, { "input": "23", "output": "0\n11\n1 2 3 4 5 18 19 20 21 22 23 " }, { "input": "24", "output": "0\n12 1 4 5 8 9 12 13 16 17 20 21 24 " }, { "input": "59999", "output": "0\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59997", "output": "1\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59996", "output": "0\n29998 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59995", "output": "0\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59994", "output": "1\n29997 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59993", "output": "1\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59992", "output": "0\n29996 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59990", "output": "1\n29995 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "100", "output": "0\n50 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 " }, { "input": "1000", "output": "0\n500 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..." }, { "input": "10001", "output": "1\n5001\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "103", "output": "0\n51\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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 " }, { "input": "1002", "output": "1\n501 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..." }, { "input": "31724", "output": "0\n15862 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "2032", "output": "0\n1016 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "42620", "output": "0\n21310 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "18076", "output": "0\n9038 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "53520", "output": "0\n26760 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "37193", "output": "1\n18597\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "12645", "output": "1\n6323\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "53237", "output": "1\n26619\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "28693", "output": "1\n14347\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "4145", "output": "1\n2073\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "36042", "output": "1\n18021 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "16646", "output": "1\n8323 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "57238", "output": "1\n28619 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "27542", "output": "1\n13771 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "8146", "output": "1\n4073 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "46659", "output": "0\n23329\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "27259", "output": "0\n13629\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "2715", "output": "0\n1357\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "38159", "output": "0\n19079\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "18759", "output": "0\n9379\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." } ]
1,513,539,355
2,147,483,647
Python 3
OK
TESTS
60
124
7,782,400
n=int(input()) l=list(range(1,n+1)) r=[] if n%4==0: r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) print(0) print(len(r), *r) if n%4==2 and n!=2: r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) print(1) print(len(r), *r) if n%4==1: r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) # print(r) m=(n+1)//2 if (m//2)%2!=0: m=m//2 else: m=(m+1)//2 r.remove(m) print(1) print(len(r), *r) if n%4==3: n+=1 r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) r.remove(n) r.append(n//2) print(0) print(len(r), *r) if n==2: print(1) print(1, 1)
Title: Dividing the numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. Output Specification: Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. Demo Input: ['4\n', '2\n'] Demo Output: ['0\n2 1 4 \n', '1\n1 1 \n'] Note: In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
```python n=int(input()) l=list(range(1,n+1)) r=[] if n%4==0: r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) print(0) print(len(r), *r) if n%4==2 and n!=2: r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) print(1) print(len(r), *r) if n%4==1: r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) # print(r) m=(n+1)//2 if (m//2)%2!=0: m=m//2 else: m=(m+1)//2 r.remove(m) print(1) print(len(r), *r) if n%4==3: n+=1 r=list(range(1,n//2,2)) + list(range(n,n//2,-2)) r.remove(n) r.append(n//2) print(0) print(len(r), *r) if n==2: print(1) print(1, 1) ```
3
688
B
Lovely Palindromes
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Print the *n*-th even-length palindrome number.
[ "1\n", "10\n" ]
[ "11\n", "1001\n" ]
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
1,000
[ { "input": "1", "output": "11" }, { "input": "10", "output": "1001" }, { "input": "11", "output": "1111" }, { "input": "12", "output": "1221" }, { "input": "100", "output": "100001" }, { "input": "1321", "output": "13211231" }, { "input": "2", "output": "22" }, { "input": "3", "output": "33" }, { "input": "4", "output": "44" }, { "input": "5", "output": "55" }, { "input": "6", "output": "66" }, { "input": "7", "output": "77" }, { "input": "8", "output": "88" }, { "input": "9", "output": "99" }, { "input": "13", "output": "1331" }, { "input": "14", "output": "1441" }, { "input": "15", "output": "1551" }, { "input": "16", "output": "1661" }, { "input": "17", "output": "1771" }, { "input": "18", "output": "1881" }, { "input": "19", "output": "1991" }, { "input": "20", "output": "2002" }, { "input": "26550", "output": "2655005562" }, { "input": "16137", "output": "1613773161" }, { "input": "91471", "output": "9147117419" }, { "input": "41242", "output": "4124224214" }, { "input": "30866", "output": "3086666803" }, { "input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116", "output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444" }, { "input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252", "output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087" }, { "input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913", "output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422" }, { "input": "123451", "output": "123451154321" } ]
1,685,527,550
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
409,600
from sys import stdin,stdout # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(int(1e5)) #input,print = stdin.readline,stdout.write n = input() print(n+n[::-1])
Title: Lovely Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). Output Specification: Print the *n*-th even-length palindrome number. Demo Input: ['1\n', '10\n'] Demo Output: ['11\n', '1001\n'] Note: The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
```python from sys import stdin,stdout # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(int(1e5)) #input,print = stdin.readline,stdout.write n = input() print(n+n[::-1]) ```
3
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68" }, { "input": "1000000000", "output": "666666667" }, { "input": "5", "output": "3" }, { "input": "6", "output": "4" }, { "input": "999999999", "output": "666666666" }, { "input": "999999998", "output": "666666665" }, { "input": "999999997", "output": "666666665" }, { "input": "999999996", "output": "666666664" }, { "input": "999999995", "output": "666666663" }, { "input": "999999994", "output": "666666663" }, { "input": "999999993", "output": "666666662" }, { "input": "999999992", "output": "666666661" }, { "input": "999999991", "output": "666666661" }, { "input": "1000", "output": "667" }, { "input": "10000", "output": "6667" }, { "input": "100000", "output": "66667" }, { "input": "1000000", "output": "666667" }, { "input": "10000000", "output": "6666667" }, { "input": "100000000", "output": "66666667" }, { "input": "7", "output": "5" } ]
1,611,411,429
2,147,483,647
Python 3
OK
TESTS
26
62
0
def solve(n): if n == 1: return 1 return n-round(n/3) def main(): n =int(input()) print(solve(n)) main()
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. Output Specification: Print the maximum possible number of times Artem can give presents to Masha. Demo Input: ['1\n', '2\n', '3\n', '4\n'] Demo Output: ['1\n', '1\n', '2\n', '3\n'] Note: In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
```python def solve(n): if n == 1: return 1 return n-round(n/3) def main(): n =int(input()) print(solve(n)) main() ```
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, { "input": "3\n1\n5", "output": "20" }, { "input": "6\n7\n1", "output": "48" }, { "input": "1\n8\n3", "output": "27" }, { "input": "9\n7\n2", "output": "126" }, { "input": "1\n1\n10", "output": "20" }, { "input": "9\n1\n1", "output": "18" }, { "input": "10\n5\n6", "output": "300" }, { "input": "8\n9\n7", "output": "504" }, { "input": "4\n2\n10", "output": "80" }, { "input": "2\n8\n3", "output": "48" }, { "input": "3\n5\n7", "output": "105" }, { "input": "1\n10\n1", "output": "12" }, { "input": "2\n2\n2", "output": "8" }, { "input": "5\n6\n1", "output": "35" }, { "input": "10\n1\n1", "output": "20" }, { "input": "1\n6\n1", "output": "8" }, { "input": "1\n9\n1", "output": "11" }, { "input": "2\n1\n2", "output": "6" }, { "input": "2\n6\n1", "output": "14" }, { "input": "9\n2\n1", "output": "27" }, { "input": "1\n9\n2", "output": "20" }, { "input": "1\n3\n1", "output": "5" }, { "input": "2\n1\n1", "output": "4" } ]
1,694,619,193
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
a,b,c=input().split() a=int(a) b=int(b) c=int(c) list1=[] list1.append(a+b+c) list1.append(a*b*c) list1.append((a+b)*c) list1.append(a*(b+c)) list1.append(a+(b*c)) list1.append((a*b)+c) print(max(list1))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python a,b,c=input().split() a=int(a) b=int(b) c=int(c) list1=[] list1.append(a+b+c) list1.append(a*b*c) list1.append((a+b)*c) list1.append(a*(b+c)) list1.append(a+(b*c)) list1.append((a*b)+c) print(max(list1)) ```
-1
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "480", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "49", "output": "YES" }, { "input": "56", "output": "YES" }, { "input": "124", "output": "YES" }, { "input": "1000", "output": "YES" }, { "input": "999", "output": "NO" }, { "input": "298", "output": "NO" }, { "input": "274", "output": "NO" }, { "input": "998", "output": "NO" }, { "input": "42", "output": "YES" }, { "input": "788", "output": "YES" }, { "input": "70", "output": "YES" }, { "input": "444", "output": "YES" }, { "input": "777", "output": "YES" }, { "input": "799", "output": "YES" }, { "input": "25", "output": "NO" }, { "input": "882", "output": "YES" }, { "input": "88", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "YES" }, { "input": "94", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "141", "output": "YES" } ]
1,690,492,279
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
124
1,638,400
x=int(input()) d = False s= True for n in range(1001): y=str(n) for i in range(len(y)): if y[i] != '4' : if y[i] !='7': continue else: if x % n ==0: print("YES") d = True break if d: break s = False if not d: print("NO")
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. Output Specification: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['47\n', '16\n', '78\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
```python x=int(input()) d = False s= True for n in range(1001): y=str(n) for i in range(len(y)): if y[i] != '4' : if y[i] !='7': continue else: if x % n ==0: print("YES") d = True break if d: break s = False if not d: print("NO") ```
0
180
C
Letter
PROGRAMMING
1,400
[ "dp" ]
null
null
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters. To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
[ "PRuvetSTAaYA\n", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "helloworld\n" ]
[ "5\n", "0\n", "0\n" ]
none
0
[ { "input": "PRuvetSTAaYA", "output": "5" }, { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0" }, { "input": "helloworld", "output": "0" }, { "input": "P", "output": "0" }, { "input": "t", "output": "0" }, { "input": "XdJ", "output": "1" }, { "input": "FSFlNEelYY", "output": "3" }, { "input": "lgtyasficu", "output": "0" }, { "input": "WYKUDTDDBT", "output": "0" }, { "input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd", "output": "0" }, { "input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu", "output": "43" }, { "input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR", "output": "13" }, { "input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi", "output": "27" }, { "input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn", "output": "31" } ]
1,546,786,038
2,147,483,647
PyPy 3
OK
TESTS
40
280
1,126,400
s=input() mina=c=0 for i in range(len(s)): if ord(s[i])>=97: mina=min(c+1,mina) c+=1 else: mina=min(mina+1,c) print(mina)
Title: Letter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters. To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. Input Specification: The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. Output Specification: Print a single number — the least number of actions needed to make the message fancy. Demo Input: ['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n'] Demo Output: ['5\n', '0\n', '0\n'] Note: none
```python s=input() mina=c=0 for i in range(len(s)): if ord(s[i])>=97: mina=min(c+1,mina) c+=1 else: mina=min(mina+1,c) print(mina) ```
3
349
B
Color the Fence
PROGRAMMING
1,700
[ "data structures", "dp", "greedy", "implementation" ]
null
null
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence.
The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105).
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
[ "5\n5 4 3 2 1 2 3 4 5\n", "2\n9 11 1 12 5 8 9 10 6\n", "0\n1 1 1 1 1 1 1 1 1\n" ]
[ "55555\n", "33\n", "-1\n" ]
none
1,000
[ { "input": "5\n5 4 3 2 1 2 3 4 5", "output": "55555" }, { "input": "2\n9 11 1 12 5 8 9 10 6", "output": "33" }, { "input": "0\n1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "50\n5 3 10 2 2 4 3 6 5", "output": "5555555555555555555555555" }, { "input": "22\n405 343 489 474 385 23 100 94 276", "output": "-1" }, { "input": "62800\n867 936 2 888 474 530 287 822 220", "output": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..." }, { "input": "27\n836 637 966 929 82 678 213 465 688", "output": "-1" }, { "input": "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000", "output": "9999999999" }, { "input": "898207\n99745 99746 99748 99752 99760 99776 99808 99872 100000", "output": "987654321" }, { "input": "80910\n64537 83748 97081 82722 12334 3056 9491 59130 28478", "output": "66666666666666666666666666" }, { "input": "120081\n11268 36403 73200 12674 83919 74218 74172 91581 68432", "output": "4444411111" }, { "input": "839851\n29926 55862 57907 51153 56350 86145 1909 22622 89861", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "751233\n69761 51826 91095 73642 98995 93262 377 38818 97480", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "306978\n95955 99204 81786 41258 96065 46946 64532 36297 70808", "output": "88888888" }, { "input": "366313\n18486 12701 92334 95391 61480 14118 20465 69784 13592", "output": "9999999999922222222222222222" }, { "input": "320671\n95788 46450 97582 95928 47742 15508 10466 10301 38822", "output": "8888888888888888888888888888888" }, { "input": "913928\n80373 47589 53204 68236 44060 97485 82241 44149 59825", "output": "99888888888888855555" }, { "input": "630384\n19652 11530 20316 3161 87360 64207 74067 77894 81452", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "95\n22076 12056 63350 12443 43123 585 52908 18372 96799", "output": "-1" }, { "input": "271380\n19135 80309 23783 48534 98990 37278 85258 67602 40288", "output": "11111111111111" }, { "input": "80085\n56973 29725 30219 17439 53162 6051 41388 35555 39392", "output": "6666666666666" }, { "input": "201332\n20008 22829 30296 1967 32154 67760 11437 90972 79865", "output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "3402\n64151 98148 81468 82342 48823 93464 5989 58868 77138", "output": "-1" }, { "input": "432544\n95724 98294 23292 24174 57778 95072 81898 50019 86824", "output": "444444444444444333" }, { "input": "1000000\n1 1 1 1 1 1 1 1 1", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "1000000\n2 2 2 2 2 2 2 2 2", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "1000000\n2 3 2 2 3 2 2 3 2", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "999999\n2 3 2 2 3 2 2 3 3", "output": "9777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "153\n85 91 28 53 29 30 92 36 89", "output": "86653" }, { "input": "26531\n64 93 48 49 86 57 93 60 96", "output": "8864433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..." }, { "input": "17186\n50 90 76 51 91 54 71 90 73", "output": "9666411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "11213\n51 82 49 50 99 52 69 96 85", "output": "964433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "20075\n57 42 99 45 56 80 76 71 63", "output": "954422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "21069\n31 19 49 30 28 43 21 25 28", "output": "9872222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222..." }, { "input": "4822\n35 36 21 13 34 36 14 16 20", "output": "9877444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" } ]
1,642,123,013
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
92
0
v = int(input()) s = input().split() s = [int(i) for i in s] mini = max(s) mp = 0 for i in range(9): if(s[i]<=mini): mini = min(mini,s[i]) mp = (i+1) if(v == 0 or v<mini): print(-1) else: t = '' while(v>0): v -= mini t += str(mp) print(t)
Title: Color the Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence. Input Specification: The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). Output Specification: Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. Demo Input: ['5\n5 4 3 2 1 2 3 4 5\n', '2\n9 11 1 12 5 8 9 10 6\n', '0\n1 1 1 1 1 1 1 1 1\n'] Demo Output: ['55555\n', '33\n', '-1\n'] Note: none
```python v = int(input()) s = input().split() s = [int(i) for i in s] mini = max(s) mp = 0 for i in range(9): if(s[i]<=mini): mini = min(mini,s[i]) mp = (i+1) if(v == 0 or v<mini): print(-1) else: t = '' while(v>0): v -= mini t += str(mp) print(t) ```
0
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "534204", "output": "106841" }, { "input": "469569", "output": "93914" }, { "input": "502877", "output": "100576" }, { "input": "942212", "output": "188443" }, { "input": "97", "output": "20" }, { "input": "53", "output": "11" }, { "input": "89", "output": "18" }, { "input": "574", "output": "115" }, { "input": "716", "output": "144" }, { "input": "729", "output": "146" }, { "input": "8901", "output": "1781" }, { "input": "3645", "output": "729" }, { "input": "4426", "output": "886" }, { "input": "46573", "output": "9315" }, { "input": "86380", "output": "17276" }, { "input": "94190", "output": "18838" }, { "input": "999990", "output": "199998" }, { "input": "999991", "output": "199999" }, { "input": "999992", "output": "199999" }, { "input": "999993", "output": "199999" }, { "input": "999994", "output": "199999" }, { "input": "999995", "output": "199999" }, { "input": "999996", "output": "200000" }, { "input": "999997", "output": "200000" }, { "input": "999998", "output": "200000" } ]
1,699,053,554
2,147,483,647
Python 3
OK
TESTS
34
46
0
import math x = int(input()) print(math.ceil(x/5))
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. Input Specification: The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. Output Specification: Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. Demo Input: ['5\n', '12\n'] Demo Output: ['1\n', '3\n'] Note: In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
```python import math x = int(input()) print(math.ceil(x/5)) ```
3
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 2 5 3 4", "output": "chest" }, { "input": "8\n7 2 9 10 3 8 10 6", "output": "chest" }, { "input": "9\n5 4 2 3 4 4 5 2 2", "output": "chest" }, { "input": "10\n4 9 8 5 3 8 8 10 4 2", "output": "biceps" }, { "input": "11\n10 9 7 6 1 3 9 7 1 3 5", "output": "chest" }, { "input": "12\n24 22 6 16 5 21 1 7 2 19 24 5", "output": "chest" }, { "input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "output": "chest" }, { "input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7", "output": "back" }, { "input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12", "output": "chest" }, { "input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8", "output": "biceps" }, { "input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19", "output": "chest" }, { "input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21", "output": "back" }, { "input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24", "output": "chest" }, { "input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20", "output": "chest" }, { "input": "1\n10", "output": "chest" }, { "input": "2\n15 3", "output": "chest" }, { "input": "3\n21 11 19", "output": "chest" }, { "input": "4\n19 24 13 15", "output": "chest" }, { "input": "5\n4 24 1 9 19", "output": "biceps" }, { "input": "6\n6 22 24 7 15 24", "output": "back" }, { "input": "7\n10 8 23 23 14 18 14", "output": "chest" }, { "input": "8\n5 16 8 9 17 16 14 7", "output": "biceps" }, { "input": "9\n12 3 10 23 6 4 22 13 12", "output": "chest" }, { "input": "10\n1 9 20 18 20 17 7 24 23 2", "output": "back" }, { "input": "11\n22 25 8 2 18 15 1 13 1 11 4", "output": "biceps" }, { "input": "12\n20 12 14 2 15 6 24 3 11 8 11 14", "output": "chest" }, { "input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18", "output": "back" }, { "input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22", "output": "biceps" }, { "input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6", "output": "back" }, { "input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14", "output": "chest" }, { "input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10", "output": "biceps" }, { "input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17", "output": "chest" }, { "input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14", "output": "back" }, { "input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6", "output": "back" }, { "input": "1\n19", "output": "chest" }, { "input": "2\n1 7", "output": "biceps" }, { "input": "3\n18 18 23", "output": "back" }, { "input": "4\n12 15 1 13", "output": "chest" }, { "input": "5\n11 14 25 21 21", "output": "biceps" }, { "input": "6\n11 9 12 11 22 18", "output": "biceps" }, { "input": "7\n11 1 16 20 21 25 20", "output": "chest" }, { "input": "8\n1 2 20 9 3 22 17 4", "output": "back" }, { "input": "9\n19 2 10 19 15 20 3 1 13", "output": "back" }, { "input": "10\n11 2 11 8 21 16 2 3 19 9", "output": "back" }, { "input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24", "output": "chest" }, { "input": "12\n4 24 21 3 13 24 22 13 12 21 1 15", "output": "back" }, { "input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3", "output": "biceps" }, { "input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11", "output": "biceps" }, { "input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17", "output": "back" }, { "input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17", "output": "chest" }, { "input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8", "output": "chest" }, { "input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22", "output": "chest" }, { "input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24", "output": "chest" }, { "input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23", "output": "biceps" }, { "input": "1\n19", "output": "chest" }, { "input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22", "output": "biceps" } ]
1,575,541,623
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
216
0
n = int(input()) x = list(map(int,input().split())) c, bi, ba = 0, 0, 0 for i in range(1,n+1): if i%3==0: ba += i elif i%2==0: bi += i else: c += i ex = {'ba1':'back','bi1':'biceps','c1':'chest'} o = max(bi,ba,c) if o==ba: print(ex['ba1']) elif o==bi: print(ex['bi1']) else: print(ex['c1'])
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. Output Specification: Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. Demo Input: ['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n'] Demo Output: ['biceps\n', 'back\n', 'chest\n'] Note: In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
```python n = int(input()) x = list(map(int,input().split())) c, bi, ba = 0, 0, 0 for i in range(1,n+1): if i%3==0: ba += i elif i%2==0: bi += i else: c += i ex = {'ba1':'back','bi1':'biceps','c1':'chest'} o = max(bi,ba,c) if o==ba: print(ex['ba1']) elif o==bi: print(ex['bi1']) else: print(ex['c1']) ```
0
965
C
Greedy Arkady
PROGRAMMING
2,000
[ "math" ]
null
null
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away. Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting. Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$.
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.
Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$.
[ "20 4 5 2\n", "30 9 4 1\n" ]
[ "8\n", "4\n" ]
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total. Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times. In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.
1,500
[ { "input": "20 4 5 2", "output": "8" }, { "input": "30 9 4 1", "output": "4" }, { "input": "2 2 1 1", "output": "1" }, { "input": "42 20 5 29", "output": "5" }, { "input": "1000000000000000000 135 1000000000000000 1000", "output": "8325624421831635" }, { "input": "100 33 100 100", "output": "100" }, { "input": "1000000000 1000000000 1000000000 1000", "output": "1000000000" }, { "input": "1000000000 32428 1000000000 1000", "output": "1000000000" }, { "input": "1000000000 324934 1000 1000", "output": "4000" }, { "input": "1000000000000000000 32400093004 10000000 1000", "output": "40000000" }, { "input": "885 2 160 842", "output": "504" }, { "input": "216 137 202 208", "output": "202" }, { "input": "72 66 28 9", "output": "28" }, { "input": "294 4 13 8", "output": "80" }, { "input": "9 2 2 3", "output": "4" }, { "input": "31 3 2 8", "output": "10" }, { "input": "104 2 5 11", "output": "50" }, { "input": "1000000000000000000 1000000000000000000 1000 1000", "output": "1000" }, { "input": "1000000000000000000 100000000000000000 1 1000", "output": "10" }, { "input": "23925738098196565 23925738098196565 23925738098196565 1000", "output": "23925738098196565" }, { "input": "576460752303423488 576460752303423488 351082447248993993 1000", "output": "351082447248993993" }, { "input": "962768465676381898 72057594037927936 586039918340257175 256", "output": "586039918340257175" }, { "input": "1000000000000000000 1000000000000000000 10 1000", "output": "10" }, { "input": "23925738098196565 23925738098196565 1 1000", "output": "1" }, { "input": "1000000000000000000 1000000000000000000 1 1000", "output": "1" } ]
1,524,680,566
2,866
Python 3
WRONG_ANSWER
PRETESTS
4
77
7,065,600
n, k, M, D = list(map(int, input().split(" "))) gain = M for i in range(2, D + 1): x = n // ((i - 1) * k + 1) if x > M: break if x * i > gain: gain = x * i print(gain)
Title: Greedy Arkady Time Limit: None seconds Memory Limit: None megabytes Problem Description: $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away. Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting. Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$. Input Specification: The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies. Output Specification: Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$. Demo Input: ['20 4 5 2\n', '30 9 4 1\n'] Demo Output: ['8\n', '4\n'] Note: In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total. Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times. In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.
```python n, k, M, D = list(map(int, input().split(" "))) gain = M for i in range(2, D + 1): x = n // ((i - 1) * k + 1) if x > M: break if x * i > gain: gain = x * i print(gain) ```
0
631
A
Interview
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109).
Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
[ "5\n1 2 4 3 2\n2 3 3 12 1\n", "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n" ]
[ "22", "46" ]
Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5. In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9.
500
[ { "input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22" }, { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46" }, { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116", "output": "254" }, { "input": "20\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64", "output": "128" }, { "input": "1\n1000000000\n1000000000", "output": "2000000000" }, { "input": "1\n0\n0", "output": "0" }, { "input": "2\n7 16\n16 7", "output": "46" }, { "input": "4\n6 0 0 0\n0 0 0 1", "output": "7" }, { "input": "8\n1 2 4 8 16 32 64 128\n1 2 4 8 16 32 64 128", "output": "510" }, { "input": "1\n2\n3", "output": "5" }, { "input": "1\n4\n3", "output": "7" }, { "input": "1\n1\n1", "output": "2" } ]
1,593,425,309
2,147,483,647
Python 3
OK
TESTS
27
124
6,963,200
n = int(input()) a = input().split() b = input().split() or_a = 0 or_b = 0 for i in range(n): or_a |= int(a[i]) or_b |= int(b[i]) print(or_a + or_b)
Title: Interview Time Limit: None seconds Memory Limit: None megabytes Problem Description: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). Output Specification: Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Demo Input: ['5\n1 2 4 3 2\n2 3 3 12 1\n', '10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n'] Demo Output: ['22', '46'] Note: Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5. In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9.
```python n = int(input()) a = input().split() b = input().split() or_a = 0 or_b = 0 for i in range(n): or_a |= int(a[i]) or_b |= int(b[i]) print(or_a + or_b) ```
3
716
B
Complete the Word
PROGRAMMING
1,300
[ "greedy", "two pointers" ]
null
null
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.
[ "ABC??FGHIJK???OPQR?TUVWXY?\n", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n", "??????????????????????????\n", "AABCDEFGHIJKLMNOPQRSTUVW??M\n" ]
[ "ABCDEFGHIJKLMNOPQRZTUVWXYS", "-1", "MNBVCXZLKJHGFDSAQPWOEIRUYT", "-1" ]
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
1,000
[ { "input": "ABC??FGHIJK???OPQR?TUVWXY?", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "output": "-1" }, { "input": "??????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AABCDEFGHIJKLMNOPQRSTUVW??M", "output": "-1" }, { "input": "QWERTYUIOPASDFGHJKL???????", "output": "QWERTYUIOPASDFGHJKLBCMNVXZ" }, { "input": "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z", "output": "ABABABBABAAAAAAAAAAAAABABABABAAAAAAAAAAAAABABABABADEFGHIMNOKLCSJBPQRTUVWXYZ" }, { "input": "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N", "output": "QAEATAUAOAAADAGAJALAXAVAMMQBECTFUHOIAKDPGRJSLWXYVZN" }, { "input": "???????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZA" }, { "input": "EJMGJAXCHXYIKZSQKUGRCLSTWDLNCVZIGXGWILAVFBEIGOHWGVEPRJTHWEDQRPOVZUQOSRVTIHFFHJMCLOWGHCIGJBCAAVBJFMJEFTEGFXZFVRZOXAFOFVXRAIZEWIKILFLYDZVDADYWYWYJXAGDFGNZBQKKKTGWPINLCDBZVULROGAKEKXXTWNYKQBMLQMQRUYOWUTWMNTJVGUXENHXWMFWMSBKVNGXSNFFTRTTGEGBBHMFZTKNJQDYUQOXVDWTDHZCCQNYYIOFPMKYQIGEEYBCKBAYVCTWARVMHIENKXKFXNXEFUHUNRQPEDFUBMKNQOYCQHGTLRHLWUAVZJDRBRTSVQHBKRDJFKKYEZAJWJKATRFZLNELPYGFUIWBXLIWVTHUILJHTQKDGRNCFTFELCOQPJDBYSPYJOUDKIFRCKEMJPUXTTAMHVENEVMNTZLUYSUALQOUPPRLZHCYICXAQFFRQZAAJNFKVRJDMDXFTBRJSAAHTSVG", "output": "-1" }, { "input": "SVBWLLLPMPJUQVIGVXPCKMPEBPWMYORVTYELJOQGKEOJVCRBUJOOKQZQBYJIBCSHGSDBTIIMNGAXAQJRHHKQFAJSOJLAYRKWBASMLBQVUPPQWDGAVKDLFHEHVVWGSYQHYCPDIECHBTOIFYUFGKWIIMCKEBLECHCETBQMJPBPPGDHRLJIIMVJBZDRSDWWEJASQFRSCLOBAOLZQDPEZWDLMYTGDLUHCJMTXVURWQFCFDIGSUADTFMNGVHRYHQKWBGWWLQJQSFSWXGWIYUTSBUNZFDONBCFTGWTTQIISXJZUWSZWXXFMNB?UWPOWVWIWMBAPXYMGTRSGWMQRXULCMDTUKZS?CNMBRIYDZCUQWAKYQLLJLTXSVMUAYZHVBZFYBABBECIADQPUPZVVYHTGKOWKDNEUYPBTNUSQLLQRODUXFMSYUYIQGERINAPZWL?VKBVQJQLUJGDPFHNVXXSNOWHBZPMLOXVC?IEUMVLIBYLEATFUTILPPTP", "output": "-1" }, { "input": "DMWSBHPGSJJD?EEV?CYAXQCCGNNQWNN?OMEDD?VC?CTKNQQPYXKKJFAYMJ?FMPXXCLKOL?OTRCE", "output": "-1" }, { "input": "EOYJRKFABJIUOZILSHHCXIFQTXAVXJOVTQCDHXPNYPW?RVRKTB?OVXEL?NQHMZZXJLGSA?OTFSZQBV?SBHGKPJPCIQMLRSYDCFPYMEMXUEVHANXELHKSKNLGHGDCYMURXQRWMHEYXXCMGMUFZIPVOZQQBJGVKESTCDZCWFUCSGGIRWMXYXJLFLGUXQAWLZIKFUTVYDGKBVKBKXTICIKHXWFVJRHNMYRJZYNNYXMUOFERZPY?AJKSMUCTLOFH?LV?EHHCHKBHOJZAHFKJHHZJKZIEYAOAPDQRIUWDBMJGOOSNWN?CBKUXJCTEWVTRBDCNFMGBJUAODCCZVPZBQJNIRJVVF?QBWBV?AXOVOYNAWSKUVPHWJK?YPYOKTVFBWAGCC?JOWPPCAZDOYETAYYECWWURYHY?SJHMSJXDIMXFOTUWJLYDKCHOAPLFYPMFYFRNRKWY?CBPLQJJJ?BJYGBJT?FV?VDQEQAUFWZSOJHZFBVEALMMT?XP", "output": "-1" }, { "input": "E?BIVQUPQQEJNMINFD?NKV?IROHPTGUIPMEVYPII?LZJMRI?FTKKKBHPOVQZZSAPDDWVSPVHOBT", "output": "-1" }, { "input": "FDQHJSNDDXHJLWVZVXJZUGKVHWCZVRWVZTIURLMJNGAMCUBDGVSIDEYRJZOLDISDNTOEKLSNLBSOQZLJVPAMLEBAVUNBXNKMLZBGJJQCGCSKBFSEEDXEVSWGZHFJIZJESPZIKIONJWTFFYYZKIDBSDNPJVAUHQMRFKIJWCEGTBVZHWZEKLPHGZVKZFAFAQRNKHGACNRTSXQKKCYBMEMKNKKSURKHOSMEVUXNGOCVCLVVSKULGBKFPCEKVRAJMBWCFFFSCCNDOSEKXEFFZETTUZHMQETWCVZASTTULYOPBNMOMXMVUEEEYZHSMRPAEIHUKNPNJTARJKQKIOXDJASSQPQQHEQIQJQLVPIJRCFVOVECHBOCRYWQEDXZLJXUDZUBFTRWEWNYTSKGDBEBWFFLMUYWELNVAAXSMKYEZXQFKKHJTZKMKMYOBTVXAOVBRMAMHTBDDYMDGQYEEBYZUBMUCKLKXCZGTWVZAYJOXZVGUYNXOVAPXQVE", "output": "-1" }, { "input": "KMNTIOJTLEKZW?JALAZYWYMKWRXTLAKNMDJLICZMETAKHVPTDOLAPCGHOEYSNIUJZVLPBTZ?YSR", "output": "-1" }, { "input": "?MNURVAKIVSOGITVJZEZCAOZEFVNZERAHVNCVCYKTJVEHK?ZMDL?CROLIDFSG?EIFHYKELMQRBVLE?CERELHDVFODJ?LBGJVFPO?CVMPBW?DPGZMVA?BKPXQQCRMKHJWDNAJSGOTGLBNSWMXMKAQ?MWMXCNRSGHTL?LGLAHSDHAGZRGTNDFI?KJ?GSAWOEPOENXTJCVJGMYOFIQKKDWOCIKPGCMFEKNEUPFGBCBYQCM?EQSAX?HZ?MFKAUHOHRKZZSIVZCAKYIKBDJYOCZJRYNLSOKGAEGQRQ?TBURXXLHAFCNVGAUVWBXZILMHWSBYJTIMWPNEGATPURPTJYFWKHRL?QPYUQ?HKDDHWAHOWUSONQKSZFIYFMFUJAMIYAMPNBGVPJSDFDFSAHDWWGEAKXLHBURNTIMCUZIAFAOCVNKPJRNLNGSJVMGKQ?IFQSRHTZGKHGXFJBDGPLCUUMEWNOSCONIVCLAOAPPSFFLCPRIXTKNBSSOVM", "output": "-1" }, { "input": "MRHKVVRBFEIFWIZGWCATJPBSZWNYANEWSSEVFQUUVNJKQOKVIGYBPFSZFTBUCNQEJEYVOWSPYER", "output": "-1" }, { "input": "CNRFBWKRTQTDFOMIGPPGDBHPRNRXFASDDBCZXHORGXDRSIORLJEROJBLLEHLNBILBPX?KHQLCOUPTKUADCDNHNBWMVNUUVUFPIRXSPNUCCRLJTDSUIUDLBKNKMXSAVBJDUGWIMNBIUWJX?TCBDEBNDYUGPS?MQSSEIIUGEE?XXKW?CMFQMWUAEXTSZNNOCPHBAEAKWALYBBMUMQZXUKTQPWNMZKIDECWIZFHKQIUJZRSBZPQFUQNVKQZMYJDHXZWXFHIZ?HWPIPIWV?JMIYKEJDNPMKTTOY?NTOMZZXTNMWQENYRWFYM?WLJJFCIJSETZSJORBZZHAFWYKGQJAPYQQXUWROOZUDOJJLNCDRSGUKYAZLLENGUICGOYPLJQ?POSKHPMOFJMAOXCITWWL?LOEDKHZPQFZZCTB?JYZNXZSDREAMGGXHMCFTQNOUALEYHULSDQVOXZIWFHNNHHG?FYUOCQNKBLFGGZ?YNFNVLRMENYBDWMDSP", "output": "-1" }, { "input": "KSRVTPFVRJWNPYUZMXBRLKVXIQPPBYVSYKRQPNGKTKRPFMKLIYFACFKBIQGPAXLEUESVGPBBXLY", "output": "-1" }, { "input": "LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJEJSRBYREOZKHEXTBAXPTISPGIPOYBFFEJNAKKXAEPNGKWYGEJTNEZIXAWRSCEIRTKNEWSKSGKNIKDEOVXGYVEVFRGTNDFNWIFDRZQEJQZYIWNZXCONVZAKKKETPTPPXZMIVDWPGXOFODRNJZBATKGXAPXYHTUUFFASCHOLSMVSWBIJBAENEGNQTWKKOJUYQNXWDCDXBXBJOOWETWLQMGKHAJEMGXMYNVEHRAEGZOJJQPZGYRHXRNKMSWFYDIZLIBUTSKIKGQJZLGZQFJVIMNOHNZJKWVVPFMFACVXKJKTBZRXRZDJKSWSXBBKWIKEICSZEIPTOJCKJQYYPNUPRNPQNNCVITNXPLAKQBYAIQGNAHXDUQWQLYN", "output": "-1" }, { "input": "PVCKCT?KLTFPIBBIHODCAABEQLJKQECRUJUSHSXPMBEVBKHQTIKQLBLTIRQZPOGPWMMNWWCUKAD", "output": "-1" }, { "input": "BRTYNUVBBWMFDSRXAMLNSBIN???WDDQVPCSWGJTHLRAKTPFKGVLHAKNRIEYIDDRDZLLTBRKXRVRSPBSLXIZRRBEVMHJSAFPLZAIHFVTTEKDO?DYWKILEYRM?VHSEQCBYZZRZMICVZRYA?ONCSZOPGZUMIHJQJPIFX?YJMIERCMKTSFTDZIKEZPLDEOOCJLQIZ?RPHUEQHPNNSBRQRTDGLWNSCZ?WQVIZPTOETEXYI?DRQUOMREPUTOAJKFNBGYNWMGCAOELXEPLLZEYHTVLT?ETJJXLHJMAUDQESNQ?ZCGNDGI?JSGUXQV?QAWQIYKXBKCCSWNRTGHPZF?CSWDQSAZIWQNHOWHYAEZNXRMPAZEQQPPIBQQJEDHJEDHVXNEDETEN?ZHEPJJ?VVDYGPJUWGCBMB?ANFJHJXQVAJWCAZEZXZX?BACPPXORNENMCRMQPIYKNPHX?NSKGEABWWVLHQ?ESWLJUPQJSFIUEGMGHEYVLYEDWJG?L", "output": "-1" }, { "input": "TESTEIGHTYFOUR", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "-1" }, { "input": "?????????????????????????", "output": "-1" }, { "input": "Q?RYJPGLNQ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYS" }, { "input": "AACDEFGHIJKLMNOPQRZTUVWXYS", "output": "-1" }, { "input": "ZA?ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "ZAZABCDEFGHIJKLMNOPQRSTUVWXY" }, { "input": "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYYYZABC", "output": "-1" }, { "input": "????", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS??", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYSAA" }, { "input": "A", "output": "-1" }, { "input": "NKBDABACEFGGGIJLLLLMMMOMPQWZSSRHHTTUWUWVXYY", "output": "-1" }, { "input": "AA", "output": "-1" }, { "input": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXA?CDEFGHIJKLMNOPQRSTUVWXYZ", "output": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "???DEFGHIJKL??L?PQRSTUVW???", "output": "-1" }, { "input": "?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A", "output": "-1" }, { "input": "A?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA???????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????", "output": "-1" }, { "input": "ZXXCVBNMLKJHGFDSAQWWERTYUIOP", "output": "-1" }, { "input": "ABCA???????????????????????", "output": "ABCADEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AB", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "BCDEFGHIAJKLMNOPQARSTUVWXYZ", "output": "-1" }, { "input": "AABBCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "-1" }, { "input": "???AA????????????????????BB???", "output": "-1" }, { "input": "ABC??FGAHIJ??MNOPQRST??WXYZ", "output": "ABCDEFGAHIJKLMNOPQRSTUVWXYZ" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBN", "output": "-1" }, { "input": "??????AAAAAAAAAAAAAAAAAAAABBBBB??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSFFFFFFF?????????DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??????WWWWWWWWWWEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRRRRRRHHHHHHHHHH?????", "output": "-1" } ]
1,572,287,348
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
124
0
s=input() if len(s) < 26: print("-1") possible=False for i in range(len(s)-25): cur="" possible=True for j in range(i, i+26): if s[j] in cur: possible=False break elif s[j] != "?": cur += s[j] else: cur += "*" if possible: for m in range(65,90): if cur.find(chr(m)) == -1: cur=cur.replace("*",chr(m),1) print(cur.replace("*","Z")) quit() if not possible: print("-1")
Title: Complete the Word Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input Specification: The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output Specification: If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Demo Input: ['ABC??FGHIJK???OPQR?TUVWXY?\n', 'WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n', '??????????????????????????\n', 'AABCDEFGHIJKLMNOPQRSTUVW??M\n'] Demo Output: ['ABCDEFGHIJKLMNOPQRZTUVWXYS', '-1', 'MNBVCXZLKJHGFDSAQPWOEIRUYT', '-1'] Note: In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
```python s=input() if len(s) < 26: print("-1") possible=False for i in range(len(s)-25): cur="" possible=True for j in range(i, i+26): if s[j] in cur: possible=False break elif s[j] != "?": cur += s[j] else: cur += "*" if possible: for m in range(65,90): if cur.find(chr(m)) == -1: cur=cur.replace("*",chr(m),1) print(cur.replace("*","Z")) quit() if not possible: print("-1") ```
0
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,689,815,995
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n, m = list(map(int, input().split())) ans = 0 b = [] a = [int(i) for i in input().split()] a.sort() for i in range(m): b.append(a[i]) for k in range(len(b)): if b[k] < 0: ans += abs(b[k]) elif b[k] == 0: ans += 0 else: ans += -(b[k]) print(ans)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python n, m = list(map(int, input().split())) ans = 0 b = [] a = [int(i) for i in input().split()] a.sort() for i in range(m): b.append(a[i]) for k in range(len(b)): if b[k] < 0: ans += abs(b[k]) elif b[k] == 0: ans += 0 else: ans += -(b[k]) print(ans) ```
0
903
A
Hungry Student Problem
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken. Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks. Help Ivan to answer this question for several values of *x*!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases. The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
[ "2\n6\n5\n" ]
[ "YES\nNO\n" ]
In the first example Ivan can buy two small portions. In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
0
[ { "input": "2\n6\n5", "output": "YES\nNO" }, { "input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100", "output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" }, { "input": "3\n6\n6\n6", "output": "YES\nYES\nYES" }, { "input": "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n1\n52\n76", "output": "NO\nYES\nYES" }, { "input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" }, { "input": "3\n3\n2\n1", "output": "YES\nNO\nNO" }, { "input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" } ]
1,593,500,077
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
20,172,800
for _ in range(int(input())): x = int(input()) if x%3==0 or x%7==0: print('YES') else: tmp = x//7 flag = True while (x-tmp)%3!=0: tmp -= 7 if tmp<=0: flag = False break if flag: print('YES') else: print('NO')
Title: Hungry Student Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken. Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks. Help Ivan to answer this question for several values of *x*! Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases. The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. Output Specification: Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. Demo Input: ['2\n6\n5\n'] Demo Output: ['YES\nNO\n'] Note: In the first example Ivan can buy two small portions. In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
```python for _ in range(int(input())): x = int(input()) if x%3==0 or x%7==0: print('YES') else: tmp = x//7 flag = True while (x-tmp)%3!=0: tmp -= 7 if tmp<=0: flag = False break if flag: print('YES') else: print('NO') ```
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into?
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow", "output": "49" }, { "input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "output": "50" }, { "input": "ijvxljt", "output": "7" }, { "input": "fyhcncnchyf", "output": "10" }, { "input": "ffffffffffff", "output": "0" }, { "input": "fyhcncfsepqj", "output": "12" }, { "input": "ybejrrlbcinttnicblrrjeby", "output": "23" }, { "input": "yyyyyyyyyyyyyyyyyyyyyyyyy", "output": "0" }, { "input": "ybejrrlbcintahovgjddrqatv", "output": "25" }, { "input": "oftmhcmclgyqaojljoaqyglcmchmtfo", "output": "30" }, { "input": "oooooooooooooooooooooooooooooooo", "output": "0" }, { "input": "oftmhcmclgyqaojllbotztajglsmcilv", "output": "32" }, { "input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg", "output": "35" }, { "input": "gggggggggggggggggggggggggggggggggggg", "output": "0" }, { "input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk", "output": "36" }, { "input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf", "output": "40" }, { "input": "fffffffffffffffffffffffffffffffffffffffffff", "output": "0" }, { "input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy", "output": "43" }, { "input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "output": "0" }, { "input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy", "output": "49" }, { "input": "a", "output": "0" }, { "input": "abca", "output": "4" }, { "input": "aaaaabaaaaa", "output": "10" }, { "input": "aba", "output": "2" }, { "input": "asaa", "output": "4" }, { "input": "aabaa", "output": "4" }, { "input": "aabbaa", "output": "5" }, { "input": "abcdaaa", "output": "7" }, { "input": "aaholaa", "output": "7" }, { "input": "abcdefghijka", "output": "12" }, { "input": "aaadcba", "output": "7" }, { "input": "aaaabaaaa", "output": "8" }, { "input": "abaa", "output": "4" }, { "input": "abcbaa", "output": "6" }, { "input": "ab", "output": "2" }, { "input": "l", "output": "0" }, { "input": "aaaabcaaaa", "output": "10" }, { "input": "abbaaaaaabba", "output": "11" }, { "input": "abaaa", "output": "5" }, { "input": "baa", "output": "3" }, { "input": "aaaaaaabbba", "output": "11" }, { "input": "ccbcc", "output": "4" }, { "input": "bbbaaab", "output": "7" }, { "input": "abaaaaaaaa", "output": "10" }, { "input": "abaaba", "output": "5" }, { "input": "aabsdfaaaa", "output": "10" }, { "input": "aaaba", "output": "5" }, { "input": "aaabaaa", "output": "6" }, { "input": "baaabbb", "output": "7" }, { "input": "ccbbabbcc", "output": "8" }, { "input": "cabc", "output": "4" }, { "input": "aabcd", "output": "5" }, { "input": "abcdea", "output": "6" }, { "input": "bbabb", "output": "4" }, { "input": "aaaaabababaaaaa", "output": "14" }, { "input": "bbabbb", "output": "6" }, { "input": "aababd", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaaaaaaabbba", "output": "12" }, { "input": "aabca", "output": "5" }, { "input": "aaabccbaaa", "output": "9" }, { "input": "aaaaaaaaaaaaaaaaaaaab", "output": "21" }, { "input": "babb", "output": "4" }, { "input": "abcaa", "output": "5" }, { "input": "qwqq", "output": "4" }, { "input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa", "output": "48" }, { "input": "aaab", "output": "4" }, { "input": "aaaaaabaaaaa", "output": "12" }, { "input": "wwuww", "output": "4" }, { "input": "aaaaabcbaaaaa", "output": "12" }, { "input": "aaabbbaaa", "output": "8" }, { "input": "aabcbaa", "output": "6" }, { "input": "abccdefccba", "output": "11" }, { "input": "aabbcbbaa", "output": "8" }, { "input": "aaaabbaaaa", "output": "9" }, { "input": "aabcda", "output": "6" }, { "input": "abbca", "output": "5" }, { "input": "aaaaaabbaaa", "output": "11" }, { "input": "sssssspssssss", "output": "12" }, { "input": "sdnmsdcs", "output": "8" }, { "input": "aaabbbccbbbaaa", "output": "13" }, { "input": "cbdbdc", "output": "6" }, { "input": "abb", "output": "3" }, { "input": "abcdefaaaa", "output": "10" }, { "input": "abbbaaa", "output": "7" }, { "input": "v", "output": "0" }, { "input": "abccbba", "output": "7" }, { "input": "axyza", "output": "5" }, { "input": "abcdefgaaaa", "output": "11" }, { "input": "aaabcdaaa", "output": "9" }, { "input": "aaaacaaaa", "output": "8" }, { "input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa", "output": "42" }, { "input": "abbbaa", "output": "6" }, { "input": "abcdee", "output": "6" }, { "input": "oom", "output": "3" }, { "input": "aabcaa", "output": "6" }, { "input": "abba", "output": "3" }, { "input": "aaca", "output": "4" }, { "input": "aacbca", "output": "6" }, { "input": "ababa", "output": "4" }, { "input": "abcda", "output": "5" }, { "input": "cccaaccc", "output": "7" }, { "input": "aaabcda", "output": "7" }, { "input": "aa", "output": "0" }, { "input": "aabaaaa", "output": "7" }, { "input": "abbaaaa", "output": "7" }, { "input": "aaabcbaaa", "output": "8" }, { "input": "aabba", "output": "5" }, { "input": "xyxx", "output": "4" }, { "input": "aaaaaaaaaaaabc", "output": "14" }, { "input": "bbaaaabb", "output": "7" }, { "input": "aaabaa", "output": "6" }, { "input": "sssssabsssss", "output": "12" }, { "input": "bbbaaaabbb", "output": "9" }, { "input": "abbbbaaaa", "output": "9" }, { "input": "wwufuww", "output": "6" }, { "input": "oowoo", "output": "4" }, { "input": "cccaccc", "output": "6" }, { "input": "aaa", "output": "0" }, { "input": "bbbcc", "output": "5" }, { "input": "abcdef", "output": "6" }, { "input": "abbba", "output": "4" }, { "input": "aab", "output": "3" }, { "input": "aaba", "output": "4" }, { "input": "azbyaaa", "output": "7" }, { "input": "oooooiooooo", "output": "10" }, { "input": "aabbbbbaaaaaa", "output": "13" } ]
1,611,846,605
2,147,483,647
PyPy 3
OK
TESTS
133
108
0
s=input() while(1): if(len(s)==1): print(0) break elif(s==s[::-1]): s=s[1:] else: print(len(s)) break
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into? Input Specification: The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. Output Specification: If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique. Demo Input: ['mew\n', 'wuffuw\n', 'qqqqqqqq\n'] Demo Output: ['3\n', '5\n', '0\n'] Note: "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
```python s=input() while(1): if(len(s)==1): print(0) break elif(s==s[::-1]): s=s[1:] else: print(len(s)) break ```
3
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it.
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" }, { "input": "9", "output": "10" }, { "input": "1", "output": "0" }, { "input": "0", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "10" }, { "input": "7", "output": "10" }, { "input": "8", "output": "10" }, { "input": "19", "output": "20" }, { "input": "100", "output": "100" }, { "input": "997", "output": "1000" }, { "input": "9994", "output": "9990" }, { "input": "10002", "output": "10000" }, { "input": "100000", "output": "100000" }, { "input": "99999", "output": "100000" }, { "input": "999999999", "output": "1000000000" }, { "input": "999999998", "output": "1000000000" }, { "input": "999999995", "output": "999999990" }, { "input": "999999990", "output": "999999990" }, { "input": "1000000", "output": "1000000" }, { "input": "1000010", "output": "1000010" }, { "input": "10000010", "output": "10000010" }, { "input": "100000011", "output": "100000010" }, { "input": "400000003", "output": "400000000" }, { "input": "234234", "output": "234230" }, { "input": "675621", "output": "675620" }, { "input": "43532", "output": "43530" }, { "input": "4576453", "output": "4576450" }, { "input": "65754674", "output": "65754670" }, { "input": "3245526", "output": "3245530" }, { "input": "123445", "output": "123440" }, { "input": "234217", "output": "234220" }, { "input": "23451218", "output": "23451220" }, { "input": "1231239", "output": "1231240" }, { "input": "1923140", "output": "1923140" }, { "input": "307910310", "output": "307910310" }, { "input": "780961030", "output": "780961030" }, { "input": "103509421", "output": "103509420" }, { "input": "576560141", "output": "576560140" }, { "input": "48851642", "output": "48851640" }, { "input": "226935072", "output": "226935070" }, { "input": "844450763", "output": "844450760" }, { "input": "22534183", "output": "22534180" }, { "input": "640049874", "output": "640049870" }, { "input": "818133304", "output": "818133300" }, { "input": "730616285", "output": "730616280" }, { "input": "613732415", "output": "613732410" }, { "input": "380991216", "output": "380991220" }, { "input": "559074636", "output": "559074640" }, { "input": "176590327", "output": "176590330" }, { "input": "354673757", "output": "354673760" }, { "input": "267156738", "output": "267156740" }, { "input": "150272868", "output": "150272870" }, { "input": "62755859", "output": "62755860" }, { "input": "945871979", "output": "945871980" }, { "input": "46", "output": "50" }, { "input": "999", "output": "1000" }, { "input": "1397", "output": "1400" } ]
1,651,064,967
2,147,483,647
Python 3
OK
TESTS
64
46
0
n=int(input()) k=n%10 if k>0 and k<6: print(n-k) if k==0: print(n) if k>5 and k<10: print (n+10-k)
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. Input Specification: The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. Output Specification: Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Demo Input: ['5\n', '113\n', '1000000000\n', '5432359\n'] Demo Output: ['0\n', '110\n', '1000000000\n', '5432360\n'] Note: In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
```python n=int(input()) k=n%10 if k>0 and k<6: print(n-k) if k==0: print(n) if k>5 and k<10: print (n+10-k) ```
3
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input": "3 2 W\nOO\nWW\nWW", "output": "1" }, { "input": "3 3 U\nUOO\nUVV\nUVV", "output": "2" }, { "input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.", "output": "1" }, { "input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ", "output": "2" }, { "input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN", "output": "3" }, { "input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J", "output": "3" }, { "input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB", "output": "2" }, { "input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..", "output": "3" }, { "input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA", "output": "4" }, { "input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY", "output": "6" }, { "input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA", "output": "4" } ]
1,539,460,051
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
// lose small or win big. #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using ll = int64_t; using ld = long double; using ull = uint64_t; using namespace std; using namespace __gnu_pbds; typedef vector <int> vi; typedef pair <int, int> ii; const int INF = 1 << 30; #define maxn 100010 int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; int main() { #ifdef BZ freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(6); int n, m; char c; cin >> n >> m >> c; vector <string> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } vector <vi> b(n, vi(m)); function <bool(int, int)> bound = [&](int x, int y) { return x >= 0 and y >= 0 and x < n and y < m; }; function <void(int, int, char)> flood = [&](int x, int y, char d) { if(bound(x, y) and a[x][y] == d) { a[x][y] = '.'; for(int k = 0; k < 4; k++) { flood(x + dr[k], y + dc[k], d); } } }; int ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(a[i][j] == 'R') { for(int k = 0; k < 4; k++) { int tx = i + dr[k]; int ty = j + dc[k]; if(bound(tx, ty) and a[tx][ty] != 'R' and a[tx][ty] != '.' and !b[tx][ty]) { ans++; flood(tx, ty, a[tx][ty]); } } } } } cout << ans << "\n"; }
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. Input Specification: The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. Output Specification: Print the only number — the amount of President's deputies. Demo Input: ['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n'] Demo Output: ['2\n', '0\n'] Note: none
```python // lose small or win big. #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using ll = int64_t; using ld = long double; using ull = uint64_t; using namespace std; using namespace __gnu_pbds; typedef vector <int> vi; typedef pair <int, int> ii; const int INF = 1 << 30; #define maxn 100010 int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; int main() { #ifdef BZ freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(6); int n, m; char c; cin >> n >> m >> c; vector <string> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } vector <vi> b(n, vi(m)); function <bool(int, int)> bound = [&](int x, int y) { return x >= 0 and y >= 0 and x < n and y < m; }; function <void(int, int, char)> flood = [&](int x, int y, char d) { if(bound(x, y) and a[x][y] == d) { a[x][y] = '.'; for(int k = 0; k < 4; k++) { flood(x + dr[k], y + dc[k], d); } } }; int ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(a[i][j] == 'R') { for(int k = 0; k < 4; k++) { int tx = i + dr[k]; int ty = j + dc[k]; if(bound(tx, ty) and a[tx][ty] != 'R' and a[tx][ty] != '.' and !b[tx][ty]) { ans++; flood(tx, ty, a[tx][ty]); } } } } } cout << ans << "\n"; } ```
-1
331
C1
The Great Julya Calendar
PROGRAMMING
1,100
[ "dp" ]
null
null
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!" Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3).
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
[ "24\n" ]
[ "5" ]
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
20
[ { "input": "24", "output": "5" }, { "input": "0", "output": "0" }, { "input": "3", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "2" }, { "input": "31", "output": "6" }, { "input": "701", "output": "116" }, { "input": "222", "output": "39" }, { "input": "156", "output": "28" }, { "input": "12343", "output": "1778" }, { "input": "7984", "output": "1178" }, { "input": "1000000", "output": "128207" }, { "input": "1", "output": "1" }, { "input": "3", "output": "1" }, { "input": "5", "output": "1" }, { "input": "11", "output": "3" }, { "input": "77", "output": "14" }, { "input": "216", "output": "37" }, { "input": "1468", "output": "233" }, { "input": "1995", "output": "305" }, { "input": "11010", "output": "1568" }, { "input": "47320", "output": "6746" }, { "input": "258634", "output": "35024" } ]
1,636,656,060
2,147,483,647
PyPy 3-64
OK
TESTS1
24
154
33,177,600
import sys #rrange = lambda mi, ma: range(ma-1, mi-1, -1) dp = {} def one_step(n): val = max(int(c) for c in str(n)) return n - val def solve_iter(n): res = 0 while n > 0: n = one_step(n) res += 1 return res # compute dp[m, 1, a] (go from x9a to x'9b where x' = x-1) for m in range(1, 10): for a in range(10): num = int(f"{m}9{a}") down_to = int(f"{m-1}99") steps = 0 while num > down_to: num = one_step(num) #print(num) steps += 1 dp[m, 1, a] = steps, num % 10 def steps(m, k, a): if (m, k, a) in dp: return dp[m, k, a] if m == 0: return steps(9, k-1, a) assert k > 1, (m, k, a) assert m > 0, (m, k, a) res, last = 0, a for y in range(0, 10)[::-1]: st, last = steps(max(m, y), k-1, last) res += st dp[m, k, a] = res, last return res, last for m in range(1, 10): for k in range(1, 3): for a in range(10): steps(m, k, a) #for key in sorted(dp): # print(key, dp[key]) def solve(n): a = n % 10 res = 0 def mk(): nc = n // 10 k = 0 m = 0 while nc % 10 == 9: k += 1 nc //= 10 while nc != 0: m = max(m, nc % 10) nc //= 10 return m, k while n != 0: print(n, file=sys.stderr) m, k = mk() if k == 0: #targ = ((n//100)-1)*100+99 #while n > targ: # print(n) res += 1 n = one_step(n) elif k == 1 and m == 0: res += 1 n = one_step(n) else: hops, last = steps(m, k, n % 10) if m == 0: n = ((n//10**(k))-1)*10**(k)+((10**(k-1))-1)*10+last else: n = ((n//10**(k+1))-1)*10**(k+1)+((10**k)-1)*10+last res+=hops print(res) N = int(input()) solve(N) #print(f"iterative solution = {solve_iter(N)}")
Title: The Great Julya Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!" Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero. Input Specification: The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3). Output Specification: Print a single integer — the minimum number of subtractions that turns the magic number to a zero. Demo Input: ['24\n'] Demo Output: ['5'] Note: In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
```python import sys #rrange = lambda mi, ma: range(ma-1, mi-1, -1) dp = {} def one_step(n): val = max(int(c) for c in str(n)) return n - val def solve_iter(n): res = 0 while n > 0: n = one_step(n) res += 1 return res # compute dp[m, 1, a] (go from x9a to x'9b where x' = x-1) for m in range(1, 10): for a in range(10): num = int(f"{m}9{a}") down_to = int(f"{m-1}99") steps = 0 while num > down_to: num = one_step(num) #print(num) steps += 1 dp[m, 1, a] = steps, num % 10 def steps(m, k, a): if (m, k, a) in dp: return dp[m, k, a] if m == 0: return steps(9, k-1, a) assert k > 1, (m, k, a) assert m > 0, (m, k, a) res, last = 0, a for y in range(0, 10)[::-1]: st, last = steps(max(m, y), k-1, last) res += st dp[m, k, a] = res, last return res, last for m in range(1, 10): for k in range(1, 3): for a in range(10): steps(m, k, a) #for key in sorted(dp): # print(key, dp[key]) def solve(n): a = n % 10 res = 0 def mk(): nc = n // 10 k = 0 m = 0 while nc % 10 == 9: k += 1 nc //= 10 while nc != 0: m = max(m, nc % 10) nc //= 10 return m, k while n != 0: print(n, file=sys.stderr) m, k = mk() if k == 0: #targ = ((n//100)-1)*100+99 #while n > targ: # print(n) res += 1 n = one_step(n) elif k == 1 and m == 0: res += 1 n = one_step(n) else: hops, last = steps(m, k, n % 10) if m == 0: n = ((n//10**(k))-1)*10**(k)+((10**(k-1))-1)*10+last else: n = ((n//10**(k+1))-1)*10**(k+1)+((10**k)-1)*10+last res+=hops print(res) N = int(input()) solve(N) #print(f"iterative solution = {solve_iter(N)}") ```
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,592,511,085
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
218
0
word = input() print(word.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python word = input() print(word.lower()) ```
0
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "output": "33" }, { "input": "4", "output": "2" }, { "input": "3", "output": "1" }, { "input": "5", "output": "2" }, { "input": "19", "output": "3" }, { "input": "20", "output": "4" }, { "input": "9880", "output": "38" }, { "input": "9879", "output": "37" }, { "input": "7770", "output": "35" }, { "input": "7769", "output": "34" }, { "input": "2925", "output": "25" }, { "input": "220", "output": "10" }, { "input": "219", "output": "9" }, { "input": "3046", "output": "25" }, { "input": "7590", "output": "34" }, { "input": "1014", "output": "17" }, { "input": "7142", "output": "34" }, { "input": "9999", "output": "38" }, { "input": "10000", "output": "38" } ]
1,699,195,124
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
n = int(input()) #25 f = 1 for i in range(2,10000) : #2 3 4 5 6 7 f += i #3 #6 #10 #15 #21 #28 if f > n : print(i-1) break else : n -= f
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. Output Specification: Print the maximum possible height of the pyramid in the single line. Demo Input: ['1\n', '25\n'] Demo Output: ['1\n', '4\n'] Note: Illustration to the second sample:
```python n = int(input()) #25 f = 1 for i in range(2,10000) : #2 3 4 5 6 7 f += i #3 #6 #10 #15 #21 #28 if f > n : print(i-1) break else : n -= f ```
0
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, { "input": "2 7\n1 1", "output": "1" }, { "input": "3 3\n18 1 9", "output": "10" }, { "input": "3 3\n15 17 9", "output": "3" }, { "input": "3 3\n10 9 12", "output": "2" }, { "input": "10 3\n2 1 17 10 5 16 8 4 15 17", "output": "31" }, { "input": "10 3\n6 11 4 12 22 15 23 26 24 26", "output": "13" }, { "input": "10 3\n10 24 13 15 18 14 15 26 33 35", "output": "29" }, { "input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580", "output": "15717" }, { "input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327", "output": "16133" } ]
1,591,598,861
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
16
1,000
1,536,000
n,d=[int(x) for x in input().split(" ")] l=[int(x) for x in input().split(" ")] m=0 for i in range(1,len(l)): while l[i]<=l[i-1]: l[i]=l[i]+d m+=1 print(m)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? Input Specification: The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). Output Specification: Output the minimal number of moves needed to make the sequence increasing. Demo Input: ['4 2\n1 3 3 2\n'] Demo Output: ['3\n'] Note: none
```python n,d=[int(x) for x in input().split(" ")] l=[int(x) for x in input().split(" ")] m=0 for i in range(1,len(l)): while l[i]<=l[i-1]: l[i]=l[i]+d m+=1 print(m) ```
0
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01234567890123456789012345678901234567890123456789", "output": "25" }, { "input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "output": "10" }, { "input": "cjw2dwmr10pku4yxohe0wglktd", "output": "4" }, { "input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "output": "13" }, { "input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1", "output": "13" }, { "input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs", "output": "8" }, { "input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc", "output": "14" }, { "input": "2222", "output": "0" }, { "input": "13579", "output": "5" }, { "input": "1", "output": "1" }, { "input": "0", "output": "0" }, { "input": "a", "output": "1" }, { "input": "y", "output": "0" }, { "input": "w", "output": "0" }, { "input": "oo", "output": "2" }, { "input": "oy", "output": "1" }, { "input": "yo", "output": "1" }, { "input": "yy", "output": "0" }, { "input": "a0", "output": "1" }, { "input": "a9", "output": "2" }, { "input": "y0", "output": "0" }, { "input": "y7", "output": "1" }, { "input": "0a", "output": "1" }, { "input": "3a", "output": "2" }, { "input": "06", "output": "0" }, { "input": "07", "output": "1" }, { "input": "70", "output": "1" }, { "input": "77", "output": "2" }, { "input": "13570", "output": "4" }, { "input": "0000000000011111", "output": "5" }, { "input": "1357", "output": "4" }, { "input": "uuuuuuuuuuuuuuuuuu", "output": "18" }, { "input": "gabieurat", "output": "5" } ]
1,624,913,240
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
x=input() cont=0 for e in x: if e in "aeiou" or e in "02468": cont+=1 print(cont)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. Input Specification: The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. Output Specification: Print a single integer, the minimum number of cards you must turn over to verify your claim. Demo Input: ['ee\n', 'z\n', '0ay1\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
```python x=input() cont=0 for e in x: if e in "aeiou" or e in "02468": cont+=1 print(cont) ```
0
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "172.7875959474" }, { "input": "1\n1000", "output": "3141592.6535897931" }, { "input": "8\n8 1 7 2 6 3 5 4", "output": "113.0973355292" }, { "input": "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901", "output": "298608.3817237098" }, { "input": "6\n109 683 214 392 678 10", "output": "397266.9574170437" }, { "input": "2\n151 400", "output": "431023.3704798660" }, { "input": "6\n258 877 696 425 663 934", "output": "823521.3902487604" }, { "input": "9\n635 707 108 234 52 180 910 203 782", "output": "1100144.9065826489" }, { "input": "8\n885 879 891 428 522 176 135 983", "output": "895488.9947571954" }, { "input": "3\n269 918 721", "output": "1241695.6467754442" }, { "input": "7\n920 570 681 428 866 935 795", "output": "1469640.1849419588" }, { "input": "2\n517 331", "output": "495517.1260654109" }, { "input": "2\n457 898", "output": "1877274.3981158488" }, { "input": "8\n872 704 973 612 183 274 739 253", "output": "1780774.0965755312" }, { "input": "74\n652 446 173 457 760 847 670 25 196 775 998 279 656 809 883 148 969 884 792 502 641 800 663 938 362 339 545 608 107 184 834 666 149 458 864 72 199 658 618 987 126 723 806 643 689 958 626 904 944 415 427 498 628 331 636 261 281 276 478 220 513 595 510 384 354 561 469 462 799 449 747 109 903 456", "output": "1510006.5089479341" }, { "input": "76\n986 504 673 158 87 332 124 218 714 235 212 122 878 370 938 81 686 323 386 348 410 468 875 107 50 960 82 834 234 663 651 422 794 633 294 771 945 607 146 913 950 858 297 88 882 725 247 872 645 749 799 987 115 394 380 382 971 429 593 426 652 353 351 233 868 598 889 116 71 376 916 464 414 976 138 903", "output": "1528494.7817143100" }, { "input": "70\n12 347 748 962 514 686 192 159 990 4 10 788 602 542 946 215 523 727 799 717 955 796 529 465 897 103 181 515 495 153 710 179 747 145 16 585 943 998 923 708 156 399 770 547 775 285 9 68 713 722 570 143 913 416 663 624 925 218 64 237 797 138 942 213 188 818 780 840 480 758", "output": "1741821.4892636713" }, { "input": "26\n656 508 45 189 561 366 96 486 547 386 703 570 780 689 264 26 11 74 466 76 421 48 982 886 215 650", "output": "1818821.9252031571" }, { "input": "52\n270 658 808 249 293 707 700 78 791 167 92 772 807 502 830 991 945 102 968 376 556 578 326 980 688 368 280 853 646 256 666 638 424 737 321 996 925 405 199 680 953 541 716 481 727 143 577 919 892 355 346 298", "output": "1272941.9273080483" }, { "input": "77\n482 532 200 748 692 697 171 863 586 547 301 149 326 812 147 698 303 691 527 805 681 387 619 947 598 453 167 799 840 508 893 688 643 974 998 341 804 230 538 669 271 404 477 759 943 596 949 235 880 160 151 660 832 82 969 539 708 889 258 81 224 655 790 144 462 582 646 256 445 52 456 920 67 819 631 484 534", "output": "2045673.1891262225" }, { "input": "27\n167 464 924 575 775 97 944 390 297 315 668 296 533 829 851 406 702 366 848 512 71 197 321 900 544 529 116", "output": "1573959.9105970615" }, { "input": "38\n488 830 887 566 720 267 583 102 65 200 884 220 263 858 510 481 316 804 754 568 412 166 374 869 356 977 145 421 500 58 664 252 745 70 381 927 670 772", "output": "1479184.3434235646" }, { "input": "64\n591 387 732 260 840 397 563 136 571 876 831 953 799 493 579 13 559 872 53 678 256 232 969 993 847 14 837 365 547 997 604 199 834 529 306 443 739 49 19 276 343 835 904 588 900 870 439 576 975 955 518 117 131 347 800 83 432 882 869 709 32 950 314 450", "output": "1258248.6984672088" }, { "input": "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637", "output": "1495219.0323274869" }, { "input": "97\n768 569 306 968 437 779 227 561 412 60 44 807 234 645 169 858 580 396 343 145 842 723 416 80 456 247 81 150 297 116 760 964 312 558 101 850 549 650 299 868 121 435 579 705 118 424 302 812 970 397 659 565 916 183 933 459 6 593 518 717 326 305 744 470 75 981 824 221 294 324 194 293 251 446 481 215 338 861 528 829 921 945 540 89 450 178 24 460 990 392 148 219 934 615 932 340 937", "output": "1577239.7333274092" }, { "input": "94\n145 703 874 425 277 652 239 496 458 658 339 842 564 699 893 352 625 980 432 121 798 872 499 859 850 721 414 825 543 843 304 111 342 45 219 311 50 748 465 902 781 822 504 985 919 656 280 310 917 438 464 527 491 713 906 329 635 777 223 810 501 535 156 252 806 112 971 719 103 443 165 98 579 554 244 996 221 560 301 51 977 422 314 858 528 772 448 626 185 194 536 66 577 677", "output": "1624269.3753516484" }, { "input": "97\n976 166 649 81 611 927 480 231 998 711 874 91 969 521 531 414 993 790 317 981 9 261 437 332 173 573 904 777 882 990 658 878 965 64 870 896 271 732 431 53 761 943 418 602 708 949 930 130 512 240 363 458 673 319 131 784 224 48 919 126 208 212 911 59 677 535 450 273 479 423 79 807 336 18 72 290 724 28 123 605 287 228 350 897 250 392 885 655 746 417 643 114 813 378 355 635 905", "output": "1615601.7212203942" }, { "input": "91\n493 996 842 9 748 178 1 807 841 519 796 998 84 670 778 143 707 208 165 893 154 943 336 150 761 881 434 112 833 55 412 682 552 945 758 189 209 600 354 325 440 844 410 20 136 665 88 791 688 17 539 821 133 236 94 606 483 446 429 60 960 476 915 134 137 852 754 908 276 482 117 252 297 903 981 203 829 811 471 135 188 667 710 393 370 302 874 872 551 457 692", "output": "1806742.5014501044" }, { "input": "95\n936 736 17 967 229 607 589 291 242 244 29 698 800 566 630 667 90 416 11 94 812 838 668 520 678 111 490 823 199 973 681 676 683 721 262 896 682 713 402 691 874 44 95 704 56 322 822 887 639 433 406 35 988 61 176 496 501 947 440 384 372 959 577 370 754 802 1 945 427 116 746 408 308 391 397 730 493 183 203 871 831 862 461 565 310 344 504 378 785 137 279 123 475 138 415", "output": "1611115.5269110680" }, { "input": "90\n643 197 42 218 582 27 66 704 195 445 641 675 285 639 503 686 242 327 57 955 848 287 819 992 756 749 363 48 648 736 580 117 752 921 923 372 114 313 202 337 64 497 399 25 883 331 24 871 917 8 517 486 323 529 325 92 891 406 864 402 263 773 931 253 625 31 17 271 140 131 232 586 893 525 846 54 294 562 600 801 214 55 768 683 389 738 314 284 328 804", "output": "1569819.2914796301" }, { "input": "98\n29 211 984 75 333 96 840 21 352 168 332 433 130 944 215 210 620 442 363 877 91 491 513 955 53 82 351 19 998 706 702 738 770 453 344 117 893 590 723 662 757 16 87 546 312 669 568 931 224 374 927 225 751 962 651 587 361 250 256 240 282 600 95 64 384 589 813 783 39 918 412 648 506 283 886 926 443 173 946 241 310 33 622 565 261 360 547 339 943 367 354 25 479 743 385 485 896 741", "output": "2042921.1539616778" }, { "input": "93\n957 395 826 67 185 4 455 880 683 654 463 84 258 878 553 592 124 585 9 133 20 609 43 452 725 125 801 537 700 685 771 155 566 376 19 690 383 352 174 208 177 416 304 1000 533 481 87 509 358 233 681 22 507 659 36 859 952 259 138 271 594 779 576 782 119 69 608 758 283 616 640 523 710 751 34 106 774 92 874 568 864 660 998 992 474 679 180 409 15 297 990 689 501", "output": "1310703.8710041976" }, { "input": "97\n70 611 20 30 904 636 583 262 255 501 604 660 212 128 199 138 545 576 506 528 12 410 77 888 783 972 431 188 338 485 148 793 907 678 281 922 976 680 252 724 253 920 177 361 721 798 960 572 99 622 712 466 608 49 612 345 266 751 63 594 40 695 532 789 520 930 825 929 48 59 405 135 109 735 508 186 495 772 375 587 201 324 447 610 230 947 855 318 856 956 313 810 931 175 668 183 688", "output": "1686117.9099228707" }, { "input": "96\n292 235 391 180 840 172 218 997 166 287 329 20 886 325 400 471 182 356 448 337 417 319 58 106 366 764 393 614 90 831 924 314 667 532 64 874 3 434 350 352 733 795 78 640 967 63 47 879 635 272 145 569 468 792 153 761 770 878 281 467 209 208 298 37 700 18 334 93 5 750 412 779 523 517 360 649 447 328 311 653 57 578 767 460 647 663 50 670 151 13 511 580 625 907 227 89", "output": "1419726.5608617242" }, { "input": "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 204 169 887 388 241 983 885 267 643 943 417 237 452 562 6 839 149 742 832 896 100 831 712 754 679 743 135 222 445 680 210 955 220 63 960 487 514 824 481 584 441 997 795 290 10 45 510 678 844 503 407 945 850 84 858 934 500 320 936 663 736 592 161 670 606 465 864 969 293 863 868 393 899 744", "output": "1556458.0979239127" }, { "input": "100\n321 200 758 415 190 710 920 992 873 898 814 259 359 66 971 210 838 545 663 652 684 277 36 756 963 459 335 484 462 982 532 423 131 703 307 229 391 938 253 847 542 975 635 928 220 980 222 567 557 181 366 824 900 180 107 979 112 564 525 413 300 422 876 615 737 343 902 8 654 628 469 913 967 785 893 314 909 215 912 262 20 709 363 915 997 954 986 454 596 124 74 159 660 550 787 418 895 786 293 50", "output": "1775109.8050211088" }, { "input": "100\n859 113 290 762 701 63 188 431 810 485 671 673 99 658 194 227 511 435 941 212 551 124 89 222 42 321 657 815 898 171 216 482 707 567 724 491 414 942 820 351 48 653 685 312 586 24 20 627 602 498 533 173 463 262 621 466 119 299 580 964 510 987 40 698 521 998 847 651 746 215 808 563 785 837 631 772 404 923 682 244 232 214 390 350 968 771 517 900 70 543 934 554 681 368 642 575 891 728 478 317", "output": "1447969.4788174964" }, { "input": "100\n941 283 349 457 52 837 299 284 796 305 893 624 101 972 738 204 121 70 17 704 836 791 95 111 162 952 472 724 733 580 878 177 705 804 11 211 463 417 288 409 410 485 896 755 921 267 164 656 505 765 539 439 535 19 991 689 220 474 114 944 884 144 926 849 486 566 117 35 749 499 797 303 362 905 690 890 976 66 590 183 234 683 39 297 769 787 376 541 571 759 495 200 261 352 73 493 831 442 273 339", "output": "1597889.4218394549" }, { "input": "100\n110 868 147 888 291 282 916 542 917 337 235 595 498 621 814 249 261 713 445 666 142 275 319 49 900 543 333 606 487 670 620 769 852 258 230 867 603 491 714 839 879 37 21 74 590 190 397 506 499 967 152 862 200 107 145 23 614 167 857 475 79 598 270 906 626 116 89 59 651 846 723 201 50 699 522 408 634 132 226 414 824 764 513 586 526 238 556 162 667 173 684 415 527 743 10 442 552 274 350 822", "output": "1567230.6191330721" }, { "input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000", "output": "298608.3817237098" } ]
1,623,588,722
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
216
0
import math n = int(input()) radii = list(map(int, input().split())) radii.sort() result = 0 counter = 0 if n % 2 == 1: result += math.pi*(radii[0]**2) counter += 2 try: while True: r2 = radii[counter] r1 = radii[counter -1] result += math.pi*(r2**2 - r1**2) counter += 2 except IndexError: print(result)
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. Output Specification: Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. Demo Input: ['1\n1\n', '3\n1 4 2\n'] Demo Output: ['3.1415926536\n', '40.8407044967\n'] Note: In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
```python import math n = int(input()) radii = list(map(int, input().split())) radii.sort() result = 0 counter = 0 if n % 2 == 1: result += math.pi*(radii[0]**2) counter += 2 try: while True: r2 = radii[counter] r1 = radii[counter -1] result += math.pi*(r2**2 - r1**2) counter += 2 except IndexError: print(result) ```
0
747
C
Servers
PROGRAMMING
1,300
[ "implementation" ]
null
null
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*. It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct. To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored.
The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks. Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
[ "4 3\n1 3 2\n2 2 1\n3 4 3\n", "3 2\n3 2 3\n5 1 2\n", "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n" ]
[ "6\n-1\n10\n", "3\n3\n", "6\n9\n30\n-1\n15\n36\n" ]
In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
1,500
[ { "input": "4 3\n1 3 2\n2 2 1\n3 4 3", "output": "6\n-1\n10" }, { "input": "3 2\n3 2 3\n5 1 2", "output": "3\n3" }, { "input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8", "output": "6\n9\n30\n-1\n15\n36" }, { "input": "4 1\n6 1 1", "output": "1" }, { "input": "1 10\n4 1 1\n9 1 1\n10 1 1\n12 1 1\n13 1 1\n15 1 1\n16 1 1\n18 1 1\n19 1 1\n20 1 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "4 10\n1 1 1\n3 1 2\n4 1 2\n6 1 2\n8 1 2\n13 1 2\n16 1 1\n17 1 2\n19 3 1\n20 1 1", "output": "1\n1\n2\n1\n1\n1\n1\n1\n6\n1" }, { "input": "100 1\n1000000 100 1000", "output": "5050" }, { "input": "5 3\n1 4 10\n2 2 5\n3 1 6", "output": "10\n-1\n5" }, { "input": "4 5\n1 2 3\n2 1 3\n3 1 2\n4 3 3\n5 4 1", "output": "3\n3\n4\n-1\n10" }, { "input": "5 3\n1 4 4\n4 2 2\n5 5 2", "output": "10\n-1\n15" }, { "input": "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100", "output": "15\n40\n-1\n1" }, { "input": "8 6\n1 3 20\n4 2 1\n6 6 5\n9 1 1\n15 3 6\n21 8 8", "output": "6\n9\n-1\n4\n15\n36" }, { "input": "5 4\n1 1 4\n2 4 4\n5 2 20\n11 5 2", "output": "1\n14\n-1\n15" }, { "input": "8 4\n1 3 2\n2 3 100\n10 6 20\n11 5 20", "output": "6\n15\n-1\n21" }, { "input": "5 3\n1 3 4\n4 3 4\n6 4 1", "output": "6\n-1\n10" }, { "input": "4 3\n1 3 10\n2 2 15\n12 4 1", "output": "6\n-1\n10" } ]
1,482,210,109
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
61
4,608,000
import heapq as pq n, q = [int(i) for i in input().split(' ')] server = [i for i in range(1, n+1)] running = [] for _ in range(q): t, k, d = [int(i) for i in input().split(' ')] while running: if t >= running[0][0]: server += pq.heappop(running)[1] else: server = sorted(server) break if len(server) < k: print(-1) continue else: pq.heappush(running, (t+d, server[:k].copy())) print(sum(server[:k])) server = server[k:]
Title: Servers Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*. It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct. To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input Specification: The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks. Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Specification: Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Demo Input: ['4 3\n1 3 2\n2 2 1\n3 4 3\n', '3 2\n3 2 3\n5 1 2\n', '8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n'] Demo Output: ['6\n-1\n10\n', '3\n3\n', '6\n9\n30\n-1\n15\n36\n'] Note: In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
```python import heapq as pq n, q = [int(i) for i in input().split(' ')] server = [i for i in range(1, n+1)] running = [] for _ in range(q): t, k, d = [int(i) for i in input().split(' ')] while running: if t >= running[0][0]: server += pq.heappop(running)[1] else: server = sorted(server) break if len(server) < k: print(-1) continue else: pq.heappush(running, (t+d, server[:k].copy())) print(sum(server[:k])) server = server[k:] ```
0
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output": "I become the guy." }, { "input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5", "output": "I become the guy." }, { "input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23", "output": "Oh, my keyboard!" }, { "input": "1\n1 1\n1 1", "output": "I become the guy." }, { "input": "1\n0\n1 1", "output": "I become the guy." }, { "input": "1\n1 1\n0", "output": "I become the guy." }, { "input": "1\n0\n0", "output": "Oh, my keyboard!" }, { "input": "100\n0\n0", "output": "Oh, my keyboard!" }, { "input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11", "output": "I become the guy." }, { "input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60", "output": "I become the guy." }, { "input": "2\n2 2 1\n0", "output": "I become the guy." }, { "input": "2\n1 2\n2 1 2", "output": "I become the guy." }, { "input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54", "output": "Oh, my keyboard!" }, { "input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33", "output": "Oh, my keyboard!" }, { "input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61", "output": "I become the guy." }, { "input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58", "output": "I become the guy." }, { "input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76", "output": "Oh, my keyboard!" }, { "input": "3\n1 2\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "4\n1 2\n3 1 3 4", "output": "I become the guy." }, { "input": "6\n2 1 2\n3 4 5 6", "output": "Oh, my keyboard!" } ]
1,698,372,070
2,147,483,647
Python 3
OK
TESTS
29
46
0
# Read input n = int(input()) p_info = list(map(int, input().split())) q_info = list(map(int, input().split())) # Create sets to store the levels Little X and Little Y can pass p_levels = set(p_info[1:]) q_levels = set(q_info[1:]) # Create a set of all levels from 1 to n all_levels = set(range(1, n + 1)) # Check if the union of the levels Little X and Little Y can pass is equal to all levels if p_levels.union(q_levels) == all_levels: print("I become the guy.") else: print("Oh, my keyboard!")
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? Input Specification: The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. Output Specification: If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). Demo Input: ['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n'] Demo Output: ['I become the guy.\n', 'Oh, my keyboard!\n'] Note: In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
```python # Read input n = int(input()) p_info = list(map(int, input().split())) q_info = list(map(int, input().split())) # Create sets to store the levels Little X and Little Y can pass p_levels = set(p_info[1:]) q_levels = set(q_info[1:]) # Create a set of all levels from 1 to n all_levels = set(range(1, n + 1)) # Check if the union of the levels Little X and Little Y can pass is equal to all levels if p_levels.union(q_levels) == all_levels: print("I become the guy.") else: print("Oh, my keyboard!") ```
3
194
A
Exams
PROGRAMMING
900
[ "implementation", "math" ]
null
null
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
[ "4 8\n", "4 10\n", "1 3\n" ]
[ "4\n", "2\n", "0\n" ]
In the first sample the author has to get a 2 for all his exams. In the second sample he should get a 3 for two exams and a 2 for two more. In the third sample he should get a 3 for one exam.
500
[ { "input": "4 8", "output": "4" }, { "input": "4 10", "output": "2" }, { "input": "1 3", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "4 9", "output": "3" }, { "input": "50 234", "output": "0" }, { "input": "50 100", "output": "50" }, { "input": "50 250", "output": "0" }, { "input": "29 116", "output": "0" }, { "input": "20 69", "output": "0" }, { "input": "46 127", "output": "11" }, { "input": "3 7", "output": "2" }, { "input": "36 99", "output": "9" }, { "input": "45 104", "output": "31" }, { "input": "13 57", "output": "0" }, { "input": "25 106", "output": "0" }, { "input": "8 19", "output": "5" }, { "input": "20 69", "output": "0" }, { "input": "13 32", "output": "7" }, { "input": "47 128", "output": "13" }, { "input": "17 73", "output": "0" }, { "input": "3 7", "output": "2" }, { "input": "16 70", "output": "0" }, { "input": "1 5", "output": "0" }, { "input": "38 137", "output": "0" }, { "input": "7 20", "output": "1" }, { "input": "1 5", "output": "0" }, { "input": "36 155", "output": "0" }, { "input": "5 15", "output": "0" }, { "input": "27 75", "output": "6" }, { "input": "21 73", "output": "0" }, { "input": "2 5", "output": "1" }, { "input": "49 177", "output": "0" }, { "input": "7 20", "output": "1" }, { "input": "44 173", "output": "0" }, { "input": "49 219", "output": "0" }, { "input": "16 70", "output": "0" }, { "input": "10 28", "output": "2" } ]
1,405,029,644
2,147,483,647
Python 3
OK
TESTS
38
154
0
n , k = map(int,input().split()) x = (3 * n) - k if x <= 0 : print("0") else: print(x)
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. Input Specification: The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. Output Specification: Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. Demo Input: ['4 8\n', '4 10\n', '1 3\n'] Demo Output: ['4\n', '2\n', '0\n'] Note: In the first sample the author has to get a 2 for all his exams. In the second sample he should get a 3 for two exams and a 2 for two more. In the third sample he should get a 3 for one exam.
```python n , k = map(int,input().split()) x = (3 * n) - k if x <= 0 : print("0") else: print(x) ```
3
574
B
Bear and Three Musketeers
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs", "hashing" ]
null
null
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once.
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
[ "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n", "7 4\n2 1\n3 6\n5 1\n1 7\n" ]
[ "2\n", "-1\n" ]
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
1,000
[ { "input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "output": "2" }, { "input": "7 4\n2 1\n3 6\n5 1\n1 7", "output": "-1" }, { "input": "5 0", "output": "-1" }, { "input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "output": "5" }, { "input": "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11", "output": "4" }, { "input": "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5", "output": "27" }, { "input": "3 0", "output": "-1" }, { "input": "3 2\n2 3\n2 1", "output": "-1" }, { "input": "3 3\n3 1\n3 2\n2 1", "output": "0" }, { "input": "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2", "output": "3" }, { "input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6", "output": "2" }, { "input": "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1", "output": "3" }, { "input": "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4", "output": "7" }, { "input": "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204", "output": "6" }, { "input": "4000 0", "output": "-1" } ]
1,558,144,298
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
819,200
# Bear and Three Musketeers n, m = map(int, input().split()) g = [set() for i in range(n)] for _ in range(m): i, j = map(int, input().split()) g[i-1].add(j-1) g[j-1].add(i-1) m = float('inf') for i in range(len(g)-1): wi = len(g[i]) for j in range(1, len(g)): wj = len(g[j]) if i in g[j] and j in g[i]: rs = list(map(lambda x: len(g[x]), g[i].intersection(g[j]))) if len(rs) > 0: m = min(m, min(rs)+wi+wj) print(m - 6 if m != float('inf') else -1)
Title: Bear and Three Musketeers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. Input Specification: The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. Output Specification: If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). Demo Input: ['5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n', '7 4\n2 1\n3 6\n5 1\n1 7\n'] Demo Output: ['2\n', '-1\n'] Note: In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
```python # Bear and Three Musketeers n, m = map(int, input().split()) g = [set() for i in range(n)] for _ in range(m): i, j = map(int, input().split()) g[i-1].add(j-1) g[j-1].add(i-1) m = float('inf') for i in range(len(g)-1): wi = len(g[i]) for j in range(1, len(g)): wj = len(g[j]) if i in g[j] and j in g[i]: rs = list(map(lambda x: len(g[x]), g[i].intersection(g[j]))) if len(rs) > 0: m = min(m, min(rs)+wi+wj) print(m - 6 if m != float('inf') else -1) ```
0
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 6" }, { "input": "5\n1 1 1 1 1", "output": "0 10" }, { "input": "5\n2 2 2 2 2", "output": "0 10" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0 45" }, { "input": "3\n2 2 2", "output": "0 3" }, { "input": "3\n3 3 3", "output": "0 3" }, { "input": "2\n10000000 100000000", "output": "90000000 1" }, { "input": "5\n5 5 5 5 5", "output": "0 10" }, { "input": "5\n3 3 3 3 3", "output": "0 10" }, { "input": "6\n1 1 1 1 1 1", "output": "0 15" }, { "input": "2\n5 6", "output": "1 1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0 45" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0 45" }, { "input": "4\n4 4 4 4", "output": "0 6" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0 21" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "0 55" }, { "input": "8\n8 8 8 8 8 8 8 8", "output": "0 28" }, { "input": "2\n3 2", "output": "1 1" } ]
1,694,575,270
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
171
16,588,800
n=int(input()) str=input().split() list=[int(ele) for ele in str] p = 0 for i in range(0,n): if list[i]>p: p=list[i] r=p for i in range(0,n): if list[i]<r: r=list[i] print(p-r) c = 0 ca = 0 for i in range(0,n): if list[i]==p: c+=1 elif list[i]==r: ca+=1 print(ca*c)
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). Output Specification: The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. Demo Input: ['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n'] Demo Output: ['1 1', '4 1', '2 4'] Note: In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
```python n=int(input()) str=input().split() list=[int(ele) for ele in str] p = 0 for i in range(0,n): if list[i]>p: p=list[i] r=p for i in range(0,n): if list[i]<r: r=list[i] print(p-r) c = 0 ca = 0 for i in range(0,n): if list[i]==p: c+=1 elif list[i]==r: ca+=1 print(ca*c) ```
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,667,384,221
2,147,483,647
PyPy 3-64
OK
TESTS
45
154
13,619,200
n = int(input()) cities = list(map(int, input().split())) ans_time = 10**10 ans = 0 for i in range(n): if cities[i] < ans_time: ans_time = cities[i] ans = i+1 elif cities[i] == ans_time: ans = 'Still Rozdil' print(ans)
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()) cities = list(map(int, input().split())) ans_time = 10**10 ans = 0 for i in range(n): if cities[i] < ans_time: ans_time = cities[i] ans = i+1 elif cities[i] == ans_time: ans = 'Still Rozdil' print(ans) ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,684,960,295
2,147,483,647
Python 3
OK
TESTS
71
92
0
s=input().split("WUB") m="" for i in s : m+=i+" " print(m)
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python s=input().split("WUB") m="" for i in s : m+=i+" " print(m) ```
3
883
M
Quadcopter Competition
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1). Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside. What is the minimal length of the quadcopter path?
The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter starting point and the flag do not coincide.
Print the length of minimal path of the quadcopter to surround the flag and return back.
[ "1 5\n5 2\n", "0 1\n0 0\n" ]
[ "18\n", "8\n" ]
none
0
[ { "input": "1 5\n5 2", "output": "18" }, { "input": "0 1\n0 0", "output": "8" }, { "input": "-100 -100\n100 100", "output": "804" }, { "input": "-100 -100\n-100 100", "output": "406" }, { "input": "-100 -100\n100 -100", "output": "406" }, { "input": "100 -100\n-100 -100", "output": "406" }, { "input": "100 -100\n-100 100", "output": "804" }, { "input": "100 -100\n100 100", "output": "406" }, { "input": "-100 100\n-100 -100", "output": "406" }, { "input": "-100 100\n100 -100", "output": "804" }, { "input": "-100 100\n100 100", "output": "406" }, { "input": "100 100\n-100 -100", "output": "804" }, { "input": "100 100\n-100 100", "output": "406" }, { "input": "100 100\n100 -100", "output": "406" }, { "input": "45 -43\n45 -44", "output": "8" }, { "input": "76 76\n75 75", "output": "8" }, { "input": "-34 -56\n-35 -56", "output": "8" }, { "input": "56 -7\n55 -6", "output": "8" }, { "input": "43 -11\n43 -10", "output": "8" }, { "input": "1 -3\n2 -2", "output": "8" }, { "input": "55 71\n56 71", "output": "8" }, { "input": "54 -87\n55 -88", "output": "8" }, { "input": "22 98\n100 33", "output": "290" }, { "input": "37 84\n-83 5", "output": "402" }, { "input": "52 74\n-73 -39", "output": "480" }, { "input": "66 51\n51 -71", "output": "278" }, { "input": "-31 44\n73 86", "output": "296" }, { "input": "-20 34\n-9 55", "output": "68" }, { "input": "-5 19\n-91 -86", "output": "386" }, { "input": "-82 5\n28 -17", "output": "268" }, { "input": "-90 -100\n55 48", "output": "590" }, { "input": "-75 -14\n-32 8", "output": "134" }, { "input": "-53 -28\n-13 -28", "output": "86" }, { "input": "-42 -46\n10 -64", "output": "144" }, { "input": "55 -42\n25 2", "output": "152" }, { "input": "70 -64\n-54 70", "output": "520" }, { "input": "93 -78\n-32 -75", "output": "260" }, { "input": "8 -93\n79 -6", "output": "320" }, { "input": "50 43\n54 10", "output": "78" }, { "input": "65 32\n-37 71", "output": "286" }, { "input": "80 18\n-15 -58", "output": "346" }, { "input": "94 92\n4 -1", "output": "370" }, { "input": "-10 96\n27 64", "output": "142" }, { "input": "-96 78\n-56 32", "output": "176" }, { "input": "-81 64\n-37 -8", "output": "236" }, { "input": "-58 49\n74 -40", "output": "446" }, { "input": "-62 -55\n1 18", "output": "276" }, { "input": "-51 -69\n-78 86", "output": "368" }, { "input": "-29 -80\n-56 -47", "output": "124" }, { "input": "-14 -94\n55 -90", "output": "150" }, { "input": "83 -2\n82 83", "output": "176" }, { "input": "98 -16\n-96 40", "output": "504" }, { "input": "17 -34\n-86 -93", "output": "328" }, { "input": "32 -48\n33 -37", "output": "28" }, { "input": "74 87\n3 92", "output": "156" }, { "input": "89 73\n-80 49", "output": "390" }, { "input": "4 58\n-61 -80", "output": "410" }, { "input": "15 48\n50 -20", "output": "210" }, { "input": "-82 45\n81 46", "output": "332" }, { "input": "-68 26\n-2 6", "output": "176" }, { "input": "-53 4\n-92 -31", "output": "152" }, { "input": "-30 94\n31 -58", "output": "430" }, { "input": "-38 -11\n58 99", "output": "416" }, { "input": "-27 -25\n-28 68", "output": "192" }, { "input": "-5 -39\n-10 -77", "output": "90" }, { "input": "-90 -54\n9 -9", "output": "292" }, { "input": "7 -57\n28 61", "output": "282" }, { "input": "18 -67\n-51 21", "output": "318" }, { "input": "41 -82\n-33 -15", "output": "286" }, { "input": "56 -8\n91 -55", "output": "168" }, { "input": "-23 -13\n-24 -12", "output": "8" }, { "input": "1 32\n1 33", "output": "8" }, { "input": "25 76\n24 76", "output": "8" }, { "input": "-29 -78\n-28 -79", "output": "8" }, { "input": "-77 19\n-76 19", "output": "8" }, { "input": "-53 63\n-53 62", "output": "8" }, { "input": "86 12\n86 11", "output": "8" }, { "input": "14 56\n13 56", "output": "8" }, { "input": "63 41\n62 40", "output": "8" }, { "input": "0 -4\n1 -4", "output": "8" }, { "input": "24 41\n24 42", "output": "8" }, { "input": "48 85\n49 86", "output": "8" }, { "input": "0 0\n0 1", "output": "8" }, { "input": "0 0\n1 0", "output": "8" }, { "input": "0 0\n1 1", "output": "8" }, { "input": "0 1\n0 0", "output": "8" }, { "input": "0 1\n1 0", "output": "8" }, { "input": "0 1\n1 1", "output": "8" }, { "input": "1 0\n0 0", "output": "8" }, { "input": "1 0\n0 1", "output": "8" }, { "input": "1 0\n1 1", "output": "8" }, { "input": "1 1\n0 0", "output": "8" }, { "input": "1 1\n0 1", "output": "8" }, { "input": "1 1\n1 0", "output": "8" }, { "input": "100 100\n99 -100", "output": "406" }, { "input": "100 100\n-100 99", "output": "406" }, { "input": "-100 -100\n-99 100", "output": "406" }, { "input": "-100 -100\n100 -99", "output": "406" }, { "input": "0 0\n1 2", "output": "10" }, { "input": "0 0\n2 1", "output": "10" } ]
1,660,928,485
2,147,483,647
Python 3
OK
TESTS
100
46
0
x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) a, b = abs(x2-x1), abs(y2-y1) if a == 0: print(4 + 2 * (b + 1)) elif b == 0: print(2 * (a + 1) + 4) else: print(2*(a+1)+2*(b+1))
Title: Quadcopter Competition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1). Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside. What is the minimal length of the quadcopter path? Input Specification: The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter starting point and the flag do not coincide. Output Specification: Print the length of minimal path of the quadcopter to surround the flag and return back. Demo Input: ['1 5\n5 2\n', '0 1\n0 0\n'] Demo Output: ['18\n', '8\n'] Note: none
```python x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) a, b = abs(x2-x1), abs(y2-y1) if a == 0: print(4 + 2 * (b + 1)) elif b == 0: print(2 * (a + 1) + 4) else: print(2*(a+1)+2*(b+1)) ```
3
681
A
A Good Contest
PROGRAMMING
800
[ "implementation" ]
null
null
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
500
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155", "output": "NO" }, { "input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968", "output": "NO" }, { "input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290", "output": "NO" }, { "input": "1\na 2400 2401", "output": "YES" }, { "input": "1\nfucker 4000 4000", "output": "NO" }, { "input": "1\nJora 2400 2401", "output": "YES" }, { "input": "1\nACA 2400 2420", "output": "YES" }, { "input": "1\nAca 2400 2420", "output": "YES" }, { "input": "1\nSub_d 2401 2402", "output": "YES" }, { "input": "2\nHack 2400 2401\nDum 1243 555", "output": "YES" }, { "input": "1\nXXX 2400 2500", "output": "YES" }, { "input": "1\nfucker 2400 2401", "output": "YES" }, { "input": "1\nX 2400 2500", "output": "YES" }, { "input": "1\nvineet 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2500", "output": "YES" }, { "input": "1\naaaaa 2400 2401", "output": "YES" }, { "input": "1\nhoge 2400 2401", "output": "YES" }, { "input": "1\nInfinity 2400 2468", "output": "YES" }, { "input": "1\nBurunduk1 2400 2401", "output": "YES" }, { "input": "1\nFuck 2400 2401", "output": "YES" }, { "input": "1\nfuck 2400 2401", "output": "YES" }, { "input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "YES" }, { "input": "1\nalex 2400 2401", "output": "YES" }, { "input": "1\nA 2400 2401", "output": "YES" }, { "input": "1\na 2400 2455", "output": "YES" }, { "input": "1\nlol 2400 2401", "output": "YES" }, { "input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214", "output": "YES" }, { "input": "1\naaaaaa 2400 2401", "output": "YES" }, { "input": "1\nBurunduk1 2400 2500", "output": "YES" }, { "input": "1\nds 2400 2410", "output": "YES" }, { "input": "1\nas 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2401", "output": "YES" }, { "input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537", "output": "YES" }, { "input": "1\ncaonima 2400 2401", "output": "YES" }, { "input": "1\narr 2400 2500", "output": "YES" }, { "input": "1\nx 2400 2401", "output": "YES" }, { "input": "1\narrr 2400 2500", "output": "YES" }, { "input": "1\nabc 2400 2405", "output": "YES" }, { "input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nBurunduk1 2400 2537", "output": "YES" }, { "input": "1\nHELLO 2400 2401", "output": "YES" }, { "input": "1\neatmore 2400 2500", "output": "YES" }, { "input": "1\nb 2400 2401", "output": "YES" }, { "input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nApplejack 2400 2410", "output": "YES" }, { "input": "1\nabacaba 2400 2451", "output": "YES" }, { "input": "1\nrekt_n00b 2500 2600", "output": "YES" } ]
1,540,206,968
2,147,483,647
Python 3
OK
TESTS
60
109
0
n=int(input()) can=False for i in range(n): s,x,y=input().split() x=int(x) y=int(y) if x>=2400 and y>x: can=True break if can: print("YES") else: print("NO")
Title: A Good Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct. Output Specification: Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. Demo Input: ['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n'] Demo Output: ['YES', 'NO'] Note: In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
```python n=int(input()) can=False for i in range(n): s,x,y=input().split() x=int(x) y=int(y) if x>=2400 and y>x: can=True break if can: print("YES") else: print("NO") ```
3
414
B
Mashmokh and ACM
PROGRAMMING
1,400
[ "combinatorics", "dp", "number theory" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
1,000
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" }, { "input": "680 1091", "output": "351905328" }, { "input": "1229 1315", "output": "100240813" }, { "input": "1766 1038", "output": "435768250" }, { "input": "1000 1", "output": "1000" }, { "input": "2000 100", "output": "983281065" }, { "input": "1 1", "output": "1" }, { "input": "2000 1000", "output": "228299266" }, { "input": "1928 1504", "output": "81660104" }, { "input": "2000 2000", "output": "585712681" }, { "input": "29 99", "output": "23125873" }, { "input": "56 48", "output": "20742237" }, { "input": "209 370", "output": "804680894" }, { "input": "83 37", "output": "22793555" }, { "input": "49 110", "output": "956247348" }, { "input": "217 3", "output": "4131" }, { "input": "162 161", "output": "591739753" }, { "input": "273 871", "output": "151578252" }, { "input": "43 1640", "output": "173064407" }, { "input": "1472 854", "output": "748682383" }, { "input": "1639 1056", "output": "467464129" }, { "input": "359 896", "output": "770361185" }, { "input": "1544 648", "output": "9278889" }, { "input": "436 1302", "output": "874366220" }, { "input": "1858 743", "output": "785912917" }, { "input": "991 1094", "output": "483493131" }, { "input": "1013 1550", "output": "613533467" }, { "input": "675 741", "output": "474968598" }, { "input": "1420 1223", "output": "922677437" }, { "input": "1544 1794", "output": "933285446" }, { "input": "1903 1612", "output": "620810276" }, { "input": "500 1304", "output": "706176027" }, { "input": "525 314", "output": "245394744" }, { "input": "39 1930", "output": "992125404" }, { "input": "1895 753", "output": "180474828" }, { "input": "1722 1474", "output": "742424590" }, { "input": "1153 1823", "output": "791493066" }, { "input": "1409 734", "output": "627413973" }, { "input": "478 1301", "output": "476483030" }, { "input": "1887 1729", "output": "730033374" }, { "input": "1610 774", "output": "50897314" }, { "input": "1770 679", "output": "235295539" }, { "input": "987 1292", "output": "560110556" }, { "input": "1707 1117", "output": "237674323" }, { "input": "1424 1431", "output": "184145444" }, { "input": "86 1078", "output": "252515343" }, { "input": "1066 995", "output": "180753612" }, { "input": "1024 133", "output": "392603027" }, { "input": "659 974", "output": "397026719" }, { "input": "1349 1606", "output": "522392901" }, { "input": "473 211", "output": "809550224" }, { "input": "634 1825", "output": "438513382" }, { "input": "22 373", "output": "907321755" }, { "input": "531 147", "output": "242883376" }, { "input": "1307 1247", "output": "21512331" }, { "input": "415 735", "output": "393705804" }, { "input": "1659 1501", "output": "225266660" }, { "input": "1454 296", "output": "750032659" }, { "input": "158 772", "output": "850911301" }, { "input": "2000 1", "output": "2000" } ]
1,655,547,601
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
93
3,379,200
import math def dividors(n): d = [] for i in range(1, int(math.sqrt(n))+1): if n%i == 0: d.append(i) if i*i != n: d.append(n//i) return d nm, km = map(int, input().split()) dp = [[0]*(nm+1) for i in range(km+1)] div = [dividors(i) for i in range(nm+1)] for n in range(1, nm+1): dp[1][n] = 1 for k in range(1, km+1): dp[k][1] = 1 for k in range(2, km+1): for n in range(2, nm+1): for d in div[n]: dp[k][n] = (dp[k][n] + dp[k-1][d]) % 1000000007 print(sum(dp[k]))
Title: Mashmokh and ACM Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7). Input Specification: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). Output Specification: Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). Demo Input: ['3 2\n', '6 4\n', '2 1\n'] Demo Output: ['5\n', '39\n', '2\n'] Note: In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
```python import math def dividors(n): d = [] for i in range(1, int(math.sqrt(n))+1): if n%i == 0: d.append(i) if i*i != n: d.append(n//i) return d nm, km = map(int, input().split()) dp = [[0]*(nm+1) for i in range(km+1)] div = [dividors(i) for i in range(nm+1)] for n in range(1, nm+1): dp[1][n] = 1 for k in range(1, km+1): dp[k][1] = 1 for k in range(2, km+1): for n in range(2, nm+1): for d in div[n]: dp[k][n] = (dp[k][n] + dp[k-1][d]) % 1000000007 print(sum(dp[k])) ```
0
898
C
Phone Numbers
PROGRAMMING
1,400
[ "implementation", "strings" ]
null
null
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record. Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account. The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once. Read the examples to understand statement and format of the output better.
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books. The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books. The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend. Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.
[ "2\nivan 1 00123\nmasha 1 00123\n", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n" ]
[ "2\nmasha 1 00123 \nivan 1 00123 \n", "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n", "2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n" ]
none
1,500
[ { "input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123 \nivan 1 00123 " }, { "input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 " }, { "input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 789 23 \nivan 4 2 123 456 789 " }, { "input": "20\nnxj 6 7 6 6 7 7 7\nnxj 10 8 5 1 7 6 1 0 7 0 6\nnxj 2 6 5\nnxj 10 6 7 6 6 5 8 3 6 6 8\nnxj 10 6 1 7 6 7 1 8 7 8 6\nnxj 10 8 5 8 6 5 6 1 9 6 3\nnxj 10 8 1 6 4 8 0 4 6 0 1\nnxj 9 2 6 6 8 1 1 3 6 6\nnxj 10 8 9 0 9 1 3 2 3 2 3\nnxj 6 6 7 0 8 1 2\nnxj 7 7 7 8 1 3 6 9\nnxj 10 2 7 0 1 5 1 9 1 2 6\nnxj 6 9 6 9 6 3 7\nnxj 9 0 1 7 8 2 6 6 5 6\nnxj 4 0 2 3 7\nnxj 10 0 4 0 6 1 1 8 8 4 7\nnxj 8 4 6 2 6 6 1 2 7\nnxj 10 5 3 4 2 1 0 7 0 7 6\nnxj 10 9 6 0 6 1 6 2 1 9 6\nnxj 4 2 9 0 1", "output": "1\nnxj 10 4 1 8 7 5 3 6 9 0 2 " }, { "input": "20\nl 6 02 02 2 02 02 2\nl 8 8 8 8 2 62 13 31 3\ne 9 0 91 0 0 60 91 60 2 44\ne 9 69 2 1 44 2 91 66 1 70\nl 9 7 27 27 3 1 3 7 80 81\nl 9 2 1 13 7 2 10 02 3 92\ne 9 0 15 3 5 5 15 91 09 44\nl 7 2 50 4 5 98 31 98\nl 3 26 7 3\ne 6 7 5 0 62 65 91\nl 8 80 0 4 0 2 2 0 13\nl 9 19 13 02 2 1 4 19 26 02\nl 10 7 39 7 9 22 22 26 2 90 4\ne 7 65 2 36 0 34 57 9\ne 8 13 02 09 91 73 5 36 62\nl 9 75 0 10 8 76 7 82 8 34\nl 7 34 0 19 80 6 4 7\ne 5 4 2 5 7 2\ne 7 4 02 69 7 07 20 2\nl 4 8 2 1 63", "output": "2\ne 18 70 07 62 36 20 69 66 57 02 65 34 44 73 60 91 15 09 13 \nl 21 02 80 27 63 19 50 81 76 34 90 98 92 31 26 22 75 39 13 10 82 62 " }, { "input": "20\no 10 6 6 97 45 6 6 6 6 5 6\nl 8 5 5 5 19 59 5 8 5\nj 9 2 30 58 2 2 1 0 30 4\nc 10 1 1 7 51 7 7 51 1 1 1\no 9 7 97 87 70 2 19 2 14 6\ne 6 26 6 6 6 26 5\ng 9 3 3 3 3 3 78 69 8 9\nl 8 8 01 1 5 8 41 72 3\nz 10 1 2 2 2 9 1 9 1 6 7\ng 8 7 78 05 36 7 3 67 9\no 5 6 9 9 7 7\ne 10 30 2 1 1 2 5 04 0 6 6\ne 9 30 30 2 2 0 26 30 79 8\nt 10 2 2 9 29 7 7 7 9 2 9\nc 7 7 51 1 31 2 7 4\nc 9 83 1 6 78 94 74 54 8 32\ng 8 4 1 01 9 39 28 6 6\nt 7 9 2 01 4 4 9 58\nj 5 0 1 58 02 4\nw 10 80 0 91 91 06 91 9 9 27 7", "output": "9\nw 5 91 06 27 9 80 \nt 6 01 29 4 58 2 7 \ne 8 2 8 30 04 26 5 79 1 \nl 8 8 41 72 01 19 59 3 5 \nj 5 58 02 1 4 30 \nz 5 7 9 6 2 1 \ng 10 39 67 3 01 36 4 05 69 78 28 \no 8 19 2 45 6 87 14 97 70 \nc 10 7 94 32 6 78 74 31 83 51 54 " }, { "input": "1\negew 5 3 123 23 1234 134", "output": "1\negew 3 134 123 1234 " } ]
1,538,209,079
2,147,483,647
Python 3
OK
TESTS
59
124
0
n=int(input()) d={} for i in range(n) : a,*b=input().split() d[a]=d.get(a,[])+b[1:] print(len(d)) for x in d : L=list(set(d[x])) l=[] for i in range(len(L)) : flaf=True for j in range(len(L)) : if i!=j and L[j].endswith(L[i]) : flaf=False if flaf : l.append(L[i]) print(x+" "+str(len(l))+" "+" ".join(l))
Title: Phone Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record. Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account. The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once. Read the examples to understand statement and format of the output better. Input Specification: First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books. The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros. Output Specification: Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books. The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend. Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order. Demo Input: ['2\nivan 1 00123\nmasha 1 00123\n', '3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n', '4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n'] Demo Output: ['2\nmasha 1 00123 \nivan 1 00123 \n', '3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n', '2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n'] Note: none
```python n=int(input()) d={} for i in range(n) : a,*b=input().split() d[a]=d.get(a,[])+b[1:] print(len(d)) for x in d : L=list(set(d[x])) l=[] for i in range(len(L)) : flaf=True for j in range(len(L)) : if i!=j and L[j].endswith(L[i]) : flaf=False if flaf : l.append(L[i]) print(x+" "+str(len(l))+" "+" ".join(l)) ```
3
845
C
Two TVs
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV. Polycarp wants to check out all *n* shows. Are two TVs enough to do so?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2\n2 3\n4 5", "output": "YES" }, { "input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO" }, { "input": "4\n0 1\n1 2\n2 3\n3 4", "output": "YES" }, { "input": "3\n1 2\n2 3\n2 4", "output": "NO" }, { "input": "3\n0 100\n0 100\n0 100", "output": "NO" }, { "input": "1\n0 1000000000", "output": "YES" }, { "input": "2\n0 1\n0 1", "output": "YES" }, { "input": "3\n2 3\n4 5\n1 6", "output": "YES" }, { "input": "5\n1 3\n1 4\n4 10\n5 8\n9 11", "output": "YES" }, { "input": "3\n1 2\n1 2\n2 3", "output": "NO" }, { "input": "4\n1 100\n10 15\n20 25\n30 35", "output": "YES" }, { "input": "3\n1 8\n6 7\n8 11", "output": "YES" }, { "input": "5\n1 2\n3 5\n4 7\n8 9\n5 10", "output": "NO" }, { "input": "4\n1 7\n2 3\n4 5\n6 7", "output": "YES" }, { "input": "4\n1 100\n50 51\n60 90\n51 52", "output": "NO" }, { "input": "3\n1 10\n2 9\n3 8", "output": "NO" }, { "input": "2\n0 4\n0 4", "output": "YES" }, { "input": "2\n0 2\n0 6", "output": "YES" }, { "input": "5\n3 4\n21 26\n12 17\n9 14\n15 16", "output": "YES" }, { "input": "5\n1 4\n13 15\n11 12\n9 15\n2 5", "output": "YES" }, { "input": "4\n16 19\n9 14\n14 15\n15 19", "output": "YES" }, { "input": "5\n16 19\n23 29\n3 8\n23 26\n22 23", "output": "NO" }, { "input": "5\n19 23\n12 17\n16 21\n20 23\n8 10", "output": "NO" }, { "input": "5\n8 10\n4 10\n3 4\n14 15\n17 19", "output": "YES" }, { "input": "3\n2 8\n5 7\n6 7", "output": "NO" }, { "input": "5\n10 12\n4 6\n21 24\n9 12\n7 13", "output": "NO" }, { "input": "5\n0 3\n14 16\n6 8\n5 9\n9 15", "output": "YES" }, { "input": "5\n6 12\n23 25\n6 7\n19 25\n10 11", "output": "YES" }, { "input": "5\n15 18\n23 24\n23 28\n22 24\n15 19", "output": "NO" }, { "input": "4\n1 8\n8 9\n5 7\n1 4", "output": "YES" }, { "input": "3\n6 10\n1 9\n2 5", "output": "YES" }, { "input": "3\n1 8\n5 6\n6 9", "output": "NO" }, { "input": "4\n2 3\n5 9\n8 10\n9 10", "output": "NO" }, { "input": "4\n0 8\n6 7\n5 9\n1 4", "output": "NO" }, { "input": "3\n6 9\n0 1\n0 2", "output": "YES" }, { "input": "5\n0 6\n21 25\n18 19\n0 3\n6 12", "output": "YES" }, { "input": "4\n1 5\n6 9\n4 8\n1 3", "output": "YES" }, { "input": "2\n2 5\n0 5", "output": "YES" }, { "input": "4\n5 8\n11 15\n3 7\n10 14", "output": "YES" }, { "input": "3\n12 14\n0 4\n2 3", "output": "YES" }, { "input": "4\n4 10\n0 1\n2 10\n0 5", "output": "NO" }, { "input": "4\n0 3\n0 1\n2 4\n2 5", "output": "NO" } ]
1,503,332,785
4,885
Python 3
WRONG_ANSWER
TESTS
10
607
9,011,200
n = int(input()) a = [n] b = [n] for i in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) a.pop(0) b.pop(0) def huj(n): for i in range(n - 1): if a[i] >= a[i+1] or b[i] >= b[i+1]: return False return True if huj(n) == True: print('YES') else: print('NO')
Title: Two TVs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV. Polycarp wants to check out all *n* shows. Are two TVs enough to do so? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. Output Specification: If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). Demo Input: ['3\n1 2\n2 3\n4 5\n', '4\n1 2\n2 3\n2 3\n1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n = int(input()) a = [n] b = [n] for i in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) a.pop(0) b.pop(0) def huj(n): for i in range(n - 1): if a[i] >= a[i+1] or b[i] >= b[i+1]: return False return True if huj(n) == True: print('YES') else: print('NO') ```
0
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make.
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 999", "output": "339" }, { "input": "32 62 92", "output": "62" }, { "input": "123456789 123456789 123456789", "output": "123456789" }, { "input": "3 5 5", "output": "4" }, { "input": "666806767 385540591 357848286", "output": "470065214" }, { "input": "80010646 727118126 817880463", "output": "541669744" }, { "input": "829651016 732259171 572879931", "output": "711596705" }, { "input": "242854896 442432924 180395753", "output": "288561190" }, { "input": "139978911 5123031 935395222", "output": "360165721" }, { "input": "553182792 10264076 395427398", "output": "319624755" }, { "input": "597790453 720437830 855459575", "output": "724562619" }, { "input": "494914467 356982656 757942689", "output": "536613270" }, { "input": "908118348 67156409 217974865", "output": "397749873" }, { "input": "952726009 629846517 972974334", "output": "851848953" }, { "input": "775140200 616574841 630329230", "output": "674014756" }, { "input": "524780569 326748594 90361407", "output": "313963523" }, { "input": "937984449 184405994 992844522", "output": "705078321" }, { "input": "835108464 525983528 452876698", "output": "604656229" }, { "input": "879716125 531124573 207876166", "output": "539572288" }, { "input": "292920005 241298326 667908343", "output": "400708891" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1000000000 999999999 999999998", "output": "999999998" }, { "input": "999999998 999999998 999999999", "output": "999999998" }, { "input": "0 1 1", "output": "0" }, { "input": "0 1000000000 0", "output": "333333333" }, { "input": "0 1 0", "output": "0" }, { "input": "1 0 0", "output": "0" }, { "input": "0 2 2", "output": "0" }, { "input": "3 3 5", "output": "3" }, { "input": "2 2 0", "output": "0" }, { "input": "0 5 5", "output": "2" }, { "input": "2 0 11", "output": "3" }, { "input": "9 9 7", "output": "8" }, { "input": "65 30 74", "output": "56" } ]
1,590,387,801
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
248
0
list1=list(map(int,input().split())) list2=[] co=0 count=0 a=0 for j in range(len(list1)): while list1[j]>2: list1[j]-=3 count+=1 co=list1[j] list2.append(co) for j in range(len(list2)): a+=list2[j] b=a/3 if a%3==0: count+=b print(int(count))
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make. Input Specification: The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. Output Specification: Print the maximal number of bouquets Fox Ciel can make. Demo Input: ['3 6 9\n', '4 4 4\n', '0 0 0\n'] Demo Output: ['6\n', '4\n', '0\n'] Note: In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
```python list1=list(map(int,input().split())) list2=[] co=0 count=0 a=0 for j in range(len(list1)): while list1[j]>2: list1[j]-=3 count+=1 co=list1[j] list2.append(co) for j in range(len(list2)): a+=list2[j] b=a/3 if a%3==0: count+=b print(int(count)) ```
0
253
A
Boys and Girls
PROGRAMMING
1,100
[ "greedy" ]
null
null
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line.
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
[ "3 3\n", "4 2\n" ]
[ "GBGBGB\n", "BGBGBB\n" ]
In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
500
[ { "input": "3 3", "output": "GBGBGB" }, { "input": "4 2", "output": "BGBGBB" }, { "input": "5 5", "output": "GBGBGBGBGB" }, { "input": "6 4", "output": "BGBGBGBGBB" }, { "input": "100 1", "output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "76 48", "output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "100 90", "output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBB" }, { "input": "90 100", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGG" }, { "input": "1 98", "output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 100", "output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "56 98", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "89 89", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB" }, { "input": "18 94", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "84 27", "output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "1 1", "output": "GB" }, { "input": "1 2", "output": "GBG" }, { "input": "2 1", "output": "BGB" }, { "input": "1 34", "output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "46 2", "output": "BGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "99 3", "output": "BGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 100", "output": "GBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "100 100", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB" }, { "input": "1 4", "output": "GBGGG" } ]
1,620,687,837
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
6,963,200
def hw6problemE(): x = str(input()) xsplit = x.split() n = int(xsplit[0]) m = int(xsplit[1]) if n == m: rsnt = "" for i in range(0, n): rsnt = rsnt + "B" rsnt = rsnt + "G" print(rsnt) elif n > m: r = n - m rsnt = "" for i in range(0,m): rsnt = rsnt + "B" rsnt = rsnt + "G" rsnt = rsnt + r * "B" print(rsnt) else: r = m - n rsnt = "" for i in range(0, n): rsnt = rsnt + "G" rsnt = rsnt + "B" rsnt = rsnt + r * "G" print(rsnt)
Title: Boys and Girls Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. Input Specification: The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. Output Specification: Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. Demo Input: ['3 3\n', '4 2\n'] Demo Output: ['GBGBGB\n', 'BGBGBB\n'] Note: In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
```python def hw6problemE(): x = str(input()) xsplit = x.split() n = int(xsplit[0]) m = int(xsplit[1]) if n == m: rsnt = "" for i in range(0, n): rsnt = rsnt + "B" rsnt = rsnt + "G" print(rsnt) elif n > m: r = n - m rsnt = "" for i in range(0,m): rsnt = rsnt + "B" rsnt = rsnt + "G" rsnt = rsnt + r * "B" print(rsnt) else: r = m - n rsnt = "" for i in range(0, n): rsnt = rsnt + "G" rsnt = rsnt + "B" rsnt = rsnt + r * "G" print(rsnt) ```
0
873
A
Chores
PROGRAMMING
800
[ "implementation" ]
null
null
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.
The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1.
Print one number — minimum time Luba needs to do all *n* chores.
[ "4 2 2\n3 6 7 10\n", "5 2 1\n100 100 100 100 100\n" ]
[ "13\n", "302\n" ]
In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13. In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302.
0
[ { "input": "4 2 2\n3 6 7 10", "output": "13" }, { "input": "5 2 1\n100 100 100 100 100", "output": "302" }, { "input": "1 1 1\n100", "output": "1" }, { "input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "9999" }, { "input": "100 100 1\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "100 50 50\n51 51 52 53 55 55 55 55 56 56 56 57 57 58 58 59 59 59 60 60 61 61 62 62 63 64 64 64 64 65 65 65 65 66 66 66 67 68 68 68 69 69 70 70 70 70 71 71 71 71 71 71 72 72 76 76 76 76 77 79 79 81 81 81 81 82 82 82 82 83 84 85 86 87 87 88 88 88 89 89 89 90 90 90 91 91 91 92 92 93 95 95 96 96 96 97 97 98 99 100", "output": "5618" }, { "input": "100 100 1\n2 4 4 4 5 5 5 6 10 10 11 11 12 12 13 13 13 14 17 18 20 20 21 21 22 22 23 24 24 25 26 29 29 32 32 34 34 35 38 39 39 40 40 42 42 43 45 47 48 49 51 52 52 54 57 59 59 60 61 61 62 63 63 64 65 65 68 70 70 72 74 75 75 76 76 77 77 78 78 78 79 80 81 82 82 83 83 83 84 89 90 92 92 93 94 96 96 97 98 99", "output": "100" }, { "input": "100 1 1\n3 3 5 7 8 8 8 9 9 9 11 13 14 15 18 18 19 20 21 22 22 25 27 27 29 31 32 33 33 34 36 37 37 38 40 42 44 44 46 47 47 48 48 48 50 50 51 51 54 54 54 55 55 56 56 56 60 61 62 62 63 64 65 65 68 70 70 71 71 71 71 75 75 76 76 79 79 79 79 81 81 82 82 86 86 86 86 88 90 90 92 96 97 97 98 98 98 98 100 100", "output": "5202" }, { "input": "100 50 49\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51", "output": "4950" }, { "input": "100 50 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "151" }, { "input": "100 1 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "199" } ]
1,613,669,403
2,147,483,647
PyPy 3
OK
TESTS
11
93
0
if __name__ == "__main__": n, k, x = list(map(int, input().split())) chore_times = list(map(int, input().split())) for i in range(1, k + 1): chore_times[-i] = x print(sum(chore_times))
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously. Input Specification: The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1. Output Specification: Print one number — minimum time Luba needs to do all *n* chores. Demo Input: ['4 2 2\n3 6 7 10\n', '5 2 1\n100 100 100 100 100\n'] Demo Output: ['13\n', '302\n'] Note: In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13. In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302.
```python if __name__ == "__main__": n, k, x = list(map(int, input().split())) chore_times = list(map(int, input().split())) for i in range(1, k + 1): chore_times[-i] = x print(sum(chore_times)) ```
3
551
B
ZgukistringZ
PROGRAMMING
1,800
[ "brute force", "constructive algorithms", "implementation", "strings" ]
null
null
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Substring of string *x* is a string formed by consecutive segment of characters from *x*. Two substrings of string *x* overlap if there is position *i* in string *x* occupied by both of them. GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings *k*?
The first line contains string *a*, the second line contains string *b*, and the third line contains string *c* (1<=≤<=|*a*|,<=|*b*|,<=|*c*|<=≤<=105, where |*s*| denotes the length of string *s*). All three strings consist only of lowercase English letters. It is possible that *b* and *c* coincide.
Find one of possible strings *k*, as described in the problem statement. If there are multiple possible answers, print any of them.
[ "aaa\na\nb\n", "pozdravstaklenidodiri\nniste\ndobri\n", "abbbaaccca\nab\naca\n" ]
[ "aaa", "nisteaadddiiklooprrvz", "ababacabcc" ]
In the third sample, this optimal solutions has three non-overlaping substrings equal to either *b* or *c* on positions 1 – 2 (*ab*), 3 – 4 (*ab*), 5 – 7 (*aca*). In this sample, there exist many other optimal solutions, one of them would be *acaababbcc*.
1,250
[ { "input": "aaa\na\nb", "output": "aaa" }, { "input": "pozdravstaklenidodiri\nniste\ndobri", "output": "nisteaadddiiklooprrvz" }, { "input": "abbbaaccca\nab\naca", "output": "ababacabcc" }, { "input": "lemigazalemiolemilicomzalemljenje\nlemi\nzlo", "output": "lemilemilemilemizlozloaaaceegjjmn" }, { "input": "xxxbbbcccoca\nca\ncb", "output": "cacbcbcboxxx" }, { "input": "aleksandrehteosidatedodam\nevo\nsi", "output": "siaaaaddddeeeehklmnoorstt" }, { "input": "cumurcumur\num\ncur", "output": "umumcurcur" }, { "input": "saljivdzijasamjaneki\nneki\nja", "output": "nekijajajaadiilmssvz" }, { "input": "lebronnojameslebronprogrammers\nje\nbro", "output": "jebrobroaaeeegllmmmnnnooprrrss" }, { "input": "lukavpastaakojelukav\na\nu", "output": "aaaaauuejkkkllopstvv" }, { "input": "navijamzaradnickiastabidrugo\ndruzina\ndjavola", "output": "druzinaaaaaabcdgiiijkmnorstv" }, { "input": "zlobobermyfriendandthanksforhelp\nde\nfor", "output": "dedeforforaabbehhikllmnnnoprstyz" }, { "input": "randomusername\numno\numno", "output": "umnoaadeemnrrs" }, { "input": "aaaaaabababaaa\naa\na", "output": "aaaaaaaaaaabbb" }, { "input": "balsabratepozdravimajudevojku\noj\nzdrav", "output": "ojojzdravaaaabbdeeiklmprstuuv" }, { "input": "milenicnikolaitisideotakmicenja\nelem\nnik", "output": "elemniknikaaaccdeiiiiijlmnoostt" }, { "input": "touristyouaregreatguy\ntourist\nguy", "output": "touristguyguyaaeeorrt" }, { "input": "oduleodule\nxgrizx\nivanstosicprvi", "output": "ddeelloouu" }, { "input": "damandicnenapravicheckerzeznulibise\nman\nker", "output": "mankeraaabcccddeeeehiiiilnnnprsuvzz" }, { "input": "jankosustersicneceovoraditi\ncosovic\noce", "output": "oceoceaadeiiijknnorrsssttuv" }, { "input": "princeofpersiayouhavegreatcontestbutinwrongtime\nop\npera", "output": "peraperaabcceeeefgghiiiimnnnnoooorrsstttttuuvwy" }, { "input": "gukimikazedauradimseminarskidodatnohumorhumor\ndp\nmrzime", "output": "mrzimeaaaaaddddeghhiiiikkkmmmnnoooorrrsstuuuu" }, { "input": "duxidimkeetoivas\ndd\nodi", "output": "odiadeeiikmstuvx" }, { "input": "svetislavgajicpoznatijikaosvetaxxx\nslavi\nslavu", "output": "slaviaaaaceegiiijjknoopsstttvvxxxz" }, { "input": "djeneralmilomirstefanovic\nradi\nnesto", "output": "radinestoaceefiijllmmnorv" }, { "input": "pozdravizazenskudecunecuvasodvajatidaseneprotumacipogresno\ncao\ndeco", "output": "decodecodecoaaaaaaadeeegiiijkmnnnnooppprrrssssttuuuuvvvzzz" }, { "input": "thisiscornercase\nyouhavetwolongerstrings\nibelivethatyoudontmissit", "output": "acceehiinorrssst" }, { "input": "petryouaregoodandyouhavegoodblogs\nblog\nrega", "output": "blogregaregaadddehnoooooopstuuvyy" }, { "input": "ikatanictisinajboljiuhrvatskojakoprictasovojaviseakotijedosadno\njavise\nsine", "output": "sinesineaaaaaaaaabccddhiiiiiijjjjjkkkklnooooooooprrssstttttuvvv" }, { "input": "ikbalturkeybelieveinyou\nbal\nkan", "output": "kanbbeeeeiiikllortuuvyy" }, { "input": "egoryouaregoodbutcantsolveeverythinginonehour\neat\nyour", "output": "eateatyouryourbcdeeeeggghhiilnnnnooooorrstuvv" }, { "input": "pozdravzamojeodeljenjeiprofesoreocudabudempetnula\nbojan\ncao", "output": "bojancaoaaddddeeeeeeeefijjllmmnooooppprrrstuuuvzz" }, { "input": "pozdravizamarkamatovicaaleksandracveticainenadaslagalicustanisica\nvas\nrad", "output": "vasvasvasradradradaaaaaaaaaaccccceeegiiiiiiikklllmmnnnnoopstttuzz" }, { "input": "hellodeninobrdo\nod\nhel", "output": "ododhelbeilnnor" }, { "input": "iwanttothanktomygrandmaheisveryimportantpersoninmylife\nthanks\nstanka", "output": "stankaaaadeeeefghhiiiiilmmmmnnnnnoooopprrrrstttttvwyyy" }, { "input": "molimprofesorkuengleskogdamidapetjasamdobarcovekitrudimseiztogaiakosamoperisan\nhvala\nunapred", "output": "unapredunapredaaaaaaabcddeeeeefgggiiiiiiijkkkkllmmmmmmoooooooooprrrsssssstttvz" }, { "input": "razredninjegosgrebovicdobarcoveklosbasketas\nne\ngo", "output": "nenegogoaaaabbbccddeeeiijkklooorrrrsssstvvz" }, { "input": "goodbyeihopecontestisntsohar\noh\ngod", "output": "ohohgodabceeeiinnooprsssttty" }, { "input": "zdule\ndidins\nmeinkraft", "output": "deluz" }, { "input": "dreamoonhasonedream\nno\nno", "output": "nonoaaaddeeehmmorrs" }, { "input": "brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako", "output": "takotakotakotakotakoaaaaaaaaaaaaaaaaaaaaaabddddddddddddddddddeffffffffffffffffffghhhhhhhhhiiiiiiiiijjjjjloooooooooooooooooppppprrrssssssssssssssssssssstttttttttttuuu" }, { "input": "bumbumdzejsikerol\nbumbum\nbum", "output": "bumbumdeeijklorsz" }, { "input": "mztskopjetisisampiosrcenaterenostaviajdezanaspobedi\nmzt\noptee", "output": "mztopteeopteeopteeaaaaaabcddiiiiijjkmnnnorrssssssvz" } ]
1,434,134,038
6,538
Python 3
MEMORY_LIMIT_EXCEEDED
PRETESTS
6
1,247
268,390,400
from fileinput import * for line in input(): if lineno() == 1: a = line.strip() if lineno() == 2: b = line.strip() if lineno() == 3: c = line.strip() la = len(a) list_a = list(a) ld = [] lb = len(b) lc = len(c) def how_many_sets(substring, string): ls = len(substring) range_obj = range(ls) count = [0] * ls string_list = list(string) for i in range(ls): letter = substring[i] if letter in string_list: del string_list[string_list.index(letter)] else: return 0 return 1 + how_many_sets(substring, ''.join(string_list)) mb = how_many_sets(b, a) mc = how_many_sets(c, a) if mb < mc: b, c = c, b lb, lc = lc, lb mb, mc = mc, mb answer = b * mb for i in range(len(answer)): del list_a[list_a.index(answer[i])] aa = ''.join(list_a) mc = how_many_sets(c, aa) answer += c * mc list_a = list(a) for i in range(len(answer)): del list_a[list_a.index(answer[i])] answer = answer + ''.join(list_a) print(answer)
Title: ZgukistringZ Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Substring of string *x* is a string formed by consecutive segment of characters from *x*. Two substrings of string *x* overlap if there is position *i* in string *x* occupied by both of them. GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings *k*? Input Specification: The first line contains string *a*, the second line contains string *b*, and the third line contains string *c* (1<=≤<=|*a*|,<=|*b*|,<=|*c*|<=≤<=105, where |*s*| denotes the length of string *s*). All three strings consist only of lowercase English letters. It is possible that *b* and *c* coincide. Output Specification: Find one of possible strings *k*, as described in the problem statement. If there are multiple possible answers, print any of them. Demo Input: ['aaa\na\nb\n', 'pozdravstaklenidodiri\nniste\ndobri\n', 'abbbaaccca\nab\naca\n'] Demo Output: ['aaa', 'nisteaadddiiklooprrvz', 'ababacabcc'] Note: In the third sample, this optimal solutions has three non-overlaping substrings equal to either *b* or *c* on positions 1 – 2 (*ab*), 3 – 4 (*ab*), 5 – 7 (*aca*). In this sample, there exist many other optimal solutions, one of them would be *acaababbcc*.
```python from fileinput import * for line in input(): if lineno() == 1: a = line.strip() if lineno() == 2: b = line.strip() if lineno() == 3: c = line.strip() la = len(a) list_a = list(a) ld = [] lb = len(b) lc = len(c) def how_many_sets(substring, string): ls = len(substring) range_obj = range(ls) count = [0] * ls string_list = list(string) for i in range(ls): letter = substring[i] if letter in string_list: del string_list[string_list.index(letter)] else: return 0 return 1 + how_many_sets(substring, ''.join(string_list)) mb = how_many_sets(b, a) mc = how_many_sets(c, a) if mb < mc: b, c = c, b lb, lc = lc, lb mb, mc = mc, mb answer = b * mb for i in range(len(answer)): del list_a[list_a.index(answer[i])] aa = ''.join(list_a) mc = how_many_sets(c, aa) answer += c * mc list_a = list(a) for i in range(len(answer)): del list_a[list_a.index(answer[i])] answer = answer + ''.join(list_a) print(answer) ```
0
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,636,353,085
2,147,483,647
PyPy 3-64
OK
TESTS
44
77
28,364,800
ans = 0 ; pre = ord('a') for i in input(): x = ord(i) m = abs(x-pre) if m>13: m = 26-m ans += m ; pre = x print(ans)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python ans = 0 ; pre = ord('a') for i in input(): x = ord(i) m = abs(x-pre) if m>13: m = 26-m ans += m ; pre = x print(ans) ```
3
177
F1
Script Generation
PROGRAMMING
1,800
[]
null
null
The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series. There are *n* single men and *n* single women among the main characters. An opinion poll showed that viewers like several couples, and a marriage of any of them will make the audience happy. The Smart Beaver formalized this fact as *k* triples of numbers (*h*,<=*w*,<=*r*), where *h* is the index of the man, *w* is the index of the woman, and *r* is the measure of the audience's delight in case of the marriage of this couple. The same poll showed that the marriage of any other couple will leave the audience indifferent, so the screenwriters decided not to include any such marriages in the plot. The script allows you to arrange several marriages between the heroes or not to arrange marriages at all. A subset of some of the *k* marriages is considered acceptable if each man and each woman is involved in at most one marriage of the subset (the series won't allow any divorces). The value of the acceptable set of marriages is the total delight the spectators will get from the marriages included in this set. Obviously, there is a finite number of acceptable sets, and they all describe some variants of the script. The screenwriters do not want to choose a set with maximum value — it would make the plot too predictable. So the Smart Beaver offers the following option: sort all the acceptable sets in increasing order of value and choose the *t*-th set from the sorted list. Thus, *t*<==<=1 corresponds to a plot without marriages, *t*<==<=2 — to a single marriage resulting in minimal delight for the audience, and so on. Help the Beaver to implement the algorithm for selecting the desired set.
The first input line contains integers *n*, *k* and *t* (1<=≤<=*k*<=≤<=*min*(100,<=*n*2), 1<=≤<=*t*<=≤<=2·105), separated by single spaces. Next *k* lines contain triples of integers (*h*,<=*w*,<=*r*) (1<=≤<=*h*,<=*w*<=≤<=*n*; 1<=≤<=*r*<=≤<=1000), separated by single spaces, which describe the possible marriages. It is guaranteed that the input data is correct: *t* doesn't exceed the total number of acceptable sets, and each pair (*h*,<=*w*) is present in at most one triple. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=20
Print a single number — the value of the *t*-th acceptable variant.
[ "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n", "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n" ]
[ "2\n", "8\n" ]
The figure shows 7 acceptable sets of marriages that exist in the first sample.
30
[ { "input": "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7", "output": "2" }, { "input": "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7", "output": "8" }, { "input": "2 2 1\n1 2 8\n2 2 1", "output": "0" }, { "input": "5 25 140\n3 5 40\n3 3 42\n4 5 62\n2 4 7\n4 2 57\n1 5 69\n3 2 37\n2 5 43\n2 3 14\n1 3 67\n5 2 62\n3 1 13\n5 5 55\n1 2 71\n4 1 69\n1 4 32\n4 4 58\n5 3 2\n2 2 31\n5 1 20\n2 1 38\n1 1 69\n5 4 66\n3 4 27\n4 3 90", "output": "80" }, { "input": "3 7 8\n1 1 4\n2 2 14\n2 1 26\n3 2 12\n2 3 1\n1 3 6\n3 3 16", "output": "14" }, { "input": "3 9 21\n3 2 40\n1 3 39\n3 1 18\n1 2 34\n2 1 27\n1 1 12\n2 2 4\n3 3 7\n2 3 16", "output": "50" }, { "input": "3 9 34\n3 2 37\n3 1 16\n1 2 1\n1 3 2\n2 2 23\n2 3 34\n2 1 2\n3 3 1\n1 1 23", "output": "94" }, { "input": "4 11 61\n3 1 39\n4 1 14\n2 3 38\n2 2 24\n2 1 4\n3 4 18\n3 2 16\n4 3 40\n4 2 10\n2 4 24\n1 1 3", "output": "69" }, { "input": "4 14 110\n3 2 27\n4 1 49\n3 1 36\n1 3 39\n3 3 23\n1 2 8\n2 2 16\n4 4 7\n1 1 36\n2 3 5\n2 4 37\n2 1 29\n1 4 44\n3 4 14", "output": "85" }, { "input": "4 16 105\n2 4 15\n1 1 16\n2 2 57\n3 4 31\n1 2 47\n2 3 28\n1 3 70\n4 2 50\n3 1 10\n4 1 11\n4 4 27\n1 4 56\n3 3 28\n3 2 28\n2 1 33\n4 3 63", "output": "94" }, { "input": "5 15 90\n2 3 71\n5 1 72\n3 2 29\n2 5 35\n5 4 49\n2 1 5\n3 3 37\n5 2 3\n1 1 24\n1 3 50\n5 3 45\n2 2 31\n4 3 71\n3 1 30\n2 4 18", "output": "95" }, { "input": "5 20 110\n1 4 29\n2 3 87\n1 1 19\n5 1 56\n3 5 71\n4 5 60\n5 3 10\n1 3 35\n1 5 29\n1 2 28\n2 5 33\n5 2 21\n5 5 61\n3 1 26\n3 2 70\n2 4 10\n4 1 16\n3 3 78\n5 4 30\n3 4 83", "output": "78" } ]
1,475,450,266
2,147,483,647
Python 3
OK
TESTS1
12
124
0
I=lambda:list(map(int,input().split())) n,k,T=I() t=[I()for _ in '0'*k] def b(h,w,r,a): if h>n:a+=[r] else: b(h+1,w,r,a) for f,s,v in t: if f==h and s in w:b(h+1,w-set([s]),r+v,a) return a print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1])
Title: Script Generation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series. There are *n* single men and *n* single women among the main characters. An opinion poll showed that viewers like several couples, and a marriage of any of them will make the audience happy. The Smart Beaver formalized this fact as *k* triples of numbers (*h*,<=*w*,<=*r*), where *h* is the index of the man, *w* is the index of the woman, and *r* is the measure of the audience's delight in case of the marriage of this couple. The same poll showed that the marriage of any other couple will leave the audience indifferent, so the screenwriters decided not to include any such marriages in the plot. The script allows you to arrange several marriages between the heroes or not to arrange marriages at all. A subset of some of the *k* marriages is considered acceptable if each man and each woman is involved in at most one marriage of the subset (the series won't allow any divorces). The value of the acceptable set of marriages is the total delight the spectators will get from the marriages included in this set. Obviously, there is a finite number of acceptable sets, and they all describe some variants of the script. The screenwriters do not want to choose a set with maximum value — it would make the plot too predictable. So the Smart Beaver offers the following option: sort all the acceptable sets in increasing order of value and choose the *t*-th set from the sorted list. Thus, *t*<==<=1 corresponds to a plot without marriages, *t*<==<=2 — to a single marriage resulting in minimal delight for the audience, and so on. Help the Beaver to implement the algorithm for selecting the desired set. Input Specification: The first input line contains integers *n*, *k* and *t* (1<=≤<=*k*<=≤<=*min*(100,<=*n*2), 1<=≤<=*t*<=≤<=2·105), separated by single spaces. Next *k* lines contain triples of integers (*h*,<=*w*,<=*r*) (1<=≤<=*h*,<=*w*<=≤<=*n*; 1<=≤<=*r*<=≤<=1000), separated by single spaces, which describe the possible marriages. It is guaranteed that the input data is correct: *t* doesn't exceed the total number of acceptable sets, and each pair (*h*,<=*w*) is present in at most one triple. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=20 Output Specification: Print a single number — the value of the *t*-th acceptable variant. Demo Input: ['2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n', '2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n'] Demo Output: ['2\n', '8\n'] Note: The figure shows 7 acceptable sets of marriages that exist in the first sample.
```python I=lambda:list(map(int,input().split())) n,k,T=I() t=[I()for _ in '0'*k] def b(h,w,r,a): if h>n:a+=[r] else: b(h+1,w,r,a) for f,s,v in t: if f==h and s in w:b(h+1,w-set([s]),r+v,a) return a print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1]) ```
3
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,695,839,178
2,147,483,647
PyPy 3-64
OK
TESTS
37
62
0
import math r, x, y, nx, ny = map(int,input().split()) step = 2*r d = math.sqrt((nx-x)**2 + (ny-y)**2) l, r = 0, 10**10 ans = 10**10 while l <= r : mid = (l+r)//2 cur = step*mid if(cur + 10**(-9) > d) : ans = mid r = mid - 1 else : l = mid + 1 print(ans)
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, nx, ny = map(int,input().split()) step = 2*r d = math.sqrt((nx-x)**2 + (ny-y)**2) l, r = 0, 10**10 ans = 10**10 while l <= r : mid = (l+r)//2 cur = step*mid if(cur + 10**(-9) > d) : ans = mid r = mid - 1 else : l = mid + 1 print(ans) ```
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,694,571,740
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
k, n, w = map(int, input().split()) sum = 0 lal = w + 1 for i in range(1, lal): sum += k * i if sum > 17: print(sum-n) else: print(0)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python k, n, w = map(int, input().split()) sum = 0 lal = w + 1 for i in range(1, lal): sum += k * i if sum > 17: print(sum-n) else: print(0) ```
0
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob?
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "4" }, { "input": "1 6", "output": "5" }, { "input": "1 7", "output": "5" }, { "input": "1 8", "output": "6" }, { "input": "1 9", "output": "6" }, { "input": "1 10", "output": "6" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "2 4", "output": "2" }, { "input": "2 5", "output": "3" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "4" }, { "input": "2 8", "output": "4" }, { "input": "2 9", "output": "4" }, { "input": "2 10", "output": "4" }, { "input": "3 3", "output": "1" }, { "input": "3 4", "output": "1" }, { "input": "3 5", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "3" }, { "input": "3 8", "output": "3" }, { "input": "3 9", "output": "3" }, { "input": "3 10", "output": "3" }, { "input": "4 4", "output": "1" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "4 8", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "4 10", "output": "3" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "1" }, { "input": "5 7", "output": "1" }, { "input": "5 8", "output": "2" }, { "input": "5 9", "output": "2" }, { "input": "5 10", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "6 8", "output": "1" }, { "input": "6 9", "output": "2" }, { "input": "6 10", "output": "2" }, { "input": "7 7", "output": "1" }, { "input": "7 8", "output": "1" }, { "input": "7 9", "output": "1" }, { "input": "7 10", "output": "1" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "1" }, { "input": "8 10", "output": "1" }, { "input": "9 9", "output": "1" }, { "input": "9 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "1 2", "output": "2" } ]
1,698,489,805
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
def solve(): years = 0 a = int(input()) b = int(input()) while a <= b: a *= 3 b *= 2 years += 1 return years # Read input # Calculate and print the number of years print(solve())
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. Output Specification: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Demo Input: ['4 7\n', '4 9\n', '1 1\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
```python def solve(): years = 0 a = int(input()) b = int(input()) while a <= b: a *= 3 b *= 2 years += 1 return years # Read input # Calculate and print the number of years print(solve()) ```
-1
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it. Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on. The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest? Take a look at the notes if you think you haven't understood the problem completely.
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n1000000000", "output": "1000000000" }, { "input": "2 0\n0 0", "output": "0" }, { "input": "2 0\n1000000000 0", "output": "1000000000" }, { "input": "2 0\n0 1000000000", "output": "1000000000" }, { "input": "2 0\n1000000000 1000000000", "output": "2000000000" }, { "input": "2 1\n0 0\n1 2", "output": "0" } ]
1,606,611,859
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
3
2,012
268,390,400
import sys input = sys.stdin.readline def inInt(): return int(input()) def inStr(): return input().strip("\n") def inIList(): return(list(map(int, input().split()))) def inSList(): return(input().split()) def bsearch(nums, target): N = len(nums or []) l = 0 r = N - 1 while l <= r: mid = ((l + r) // 2) if nums[mid] < target: l = mid + 1 elif nums[mid] > target: r = mid - 1 else: return (None, mid, None) return (r if r >= 0 else None, None, l if l <= N-1 else None) def yesOrNo(val): print("YES" if val else "NO") def printSpacedArray(nums): print(*nums) def solve(): print() def DFS(n, graph, seen): if seen[n]: return 0 stack = [] stack.append(n) m = 1000000001 while stack: s = stack.pop() if not seen[s]: m = min(m, c[s]) seen[s] = True for node in range(len(graph[s])): if graph[s][node]: if not seen[node]: stack.append(node) return m n, m = inIList() graph = [[False for i in range(n)] for i in range(n)] c = inIList() for i in range(m): x, y = inIList() graph[x-1][y-1] = True graph[y-1][x-1] = True seen = [False for i in range(n)] total = 0 for i in range(n): total += DFS(i, graph, seen) print(total)
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it. Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on. The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest? Take a look at the notes if you think you haven't understood the problem completely. Input Specification: The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once. Output Specification: Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. Demo Input: ['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n'] Demo Output: ['10\n', '55\n', '15\n'] Note: In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
```python import sys input = sys.stdin.readline def inInt(): return int(input()) def inStr(): return input().strip("\n") def inIList(): return(list(map(int, input().split()))) def inSList(): return(input().split()) def bsearch(nums, target): N = len(nums or []) l = 0 r = N - 1 while l <= r: mid = ((l + r) // 2) if nums[mid] < target: l = mid + 1 elif nums[mid] > target: r = mid - 1 else: return (None, mid, None) return (r if r >= 0 else None, None, l if l <= N-1 else None) def yesOrNo(val): print("YES" if val else "NO") def printSpacedArray(nums): print(*nums) def solve(): print() def DFS(n, graph, seen): if seen[n]: return 0 stack = [] stack.append(n) m = 1000000001 while stack: s = stack.pop() if not seen[s]: m = min(m, c[s]) seen[s] = True for node in range(len(graph[s])): if graph[s][node]: if not seen[node]: stack.append(node) return m n, m = inIList() graph = [[False for i in range(n)] for i in range(n)] c = inIList() for i in range(m): x, y = inIList() graph[x-1][y-1] = True graph[y-1][x-1] = True seen = [False for i in range(n)] total = 0 for i in range(n): total += DFS(i, graph, seen) print(total) ```
0
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8", "output": "1 2 3 4 5 6 7 8 9 0" }, { "input": "1 1\n4\n4", "output": "4" }, { "input": "3 7\n6 3 4\n4 9 0 1 7 8 6", "output": "6 4" }, { "input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0", "output": "0" }, { "input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6", "output": "6 0 3 8 1" }, { "input": "8 2\n7 2 9 6 1 0 3 4\n6 3", "output": "6 3" }, { "input": "5 4\n7 0 1 4 9\n0 9 5 3", "output": "0 9" }, { "input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6", "output": "6" }, { "input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2", "output": "2 3" }, { "input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2", "output": "3 9 2 4" }, { "input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6", "output": "1 2 3 8 6 5" }, { "input": "8 2\n7 4 8 9 2 5 6 1\n6 4", "output": "4 6" }, { "input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3", "output": "0 3" }, { "input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8", "output": "2 8 1 3" }, { "input": "1 6\n3\n6 8 2 4 5 3", "output": "3" }, { "input": "1 8\n0\n9 2 4 8 1 5 0 7", "output": "0" }, { "input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4", "output": "7 9 4 1 0" }, { "input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1", "output": "0 1" }, { "input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2", "output": "2 9 6 1 4" }, { "input": "6 3\n8 3 9 2 7 6\n5 4 3", "output": "3" }, { "input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5", "output": "8 3 9 6" }, { "input": "1 2\n1\n1 0", "output": "1" }, { "input": "3 6\n1 2 3\n4 5 6 1 2 3", "output": "1 2 3" }, { "input": "1 2\n2\n1 2", "output": "2" }, { "input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9", "output": "9" } ]
1,562,564,693
2,147,483,647
Python 3
OK
TESTS
31
140
0
n, m = map(int, input().split(" ")) sequence = list(map(int, input().split(" "))) fingerprints = list(map(int, input().split(" "))) for ele in sequence: if ele in fingerprints: print(ele, end = ' ')
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. Input Specification: The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. Output Specification: In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. Demo Input: ['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n'] Demo Output: ['7 1 2\n', '1 0\n'] Note: In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.
```python n, m = map(int, input().split(" ")) sequence = list(map(int, input().split(" "))) fingerprints = list(map(int, input().split(" "))) for ele in sequence: if ele in fingerprints: print(ele, end = ' ') ```
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,677,506,476
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) a = 0 b = 0 c = 0 for i in range(n): xyz = list(map(int,input().split())) a += xyz[0] b += xyz[1] c += xyz[2] if (a,b,c) == (0,0,0): print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) a = 0 b = 0 c = 0 for i in range(n): xyz = list(map(int,input().split())) a += xyz[0] b += xyz[1] c += xyz[2] if (a,b,c) == (0,0,0): print('YES') else: print('NO') ```
3.977
755
B
PolandBall and Game
PROGRAMMING
1,100
[ "binary search", "data structures", "games", "greedy", "sortings", "strings" ]
null
null
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
[ "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "1 2\na\na\nb\n" ]
[ "YES", "YES", "NO" ]
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
1,000
[ { "input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES" }, { "input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES" }, { "input": "1 2\na\na\nb", "output": "NO" }, { "input": "2 2\na\nb\nb\nc", "output": "YES" }, { "input": "2 1\nc\na\na", "output": "YES" }, { "input": "3 3\nab\nbc\ncd\ncd\ndf\nfg", "output": "YES" }, { "input": "3 3\nc\na\nb\na\nd\ng", "output": "YES" }, { "input": "1 1\naa\naa", "output": "YES" }, { "input": "2 1\na\nb\na", "output": "YES" }, { "input": "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny", "output": "YES" }, { "input": "3 2\na\nb\nc\nd\ne", "output": "YES" } ]
1,698,481,996
2,147,483,647
Python 3
OK
TESTS
33
46
1,433,600
n, m = list(map(int, input().split())) PolandBall = set() EnemyBall = set() for i in range(n): PolandBall.add(input()) for i in range(m): EnemyBall.add(input()) intersectionSet = PolandBall.intersection(EnemyBall) PolandBall = PolandBall.difference(intersectionSet) EnemyBall = EnemyBall.difference(intersectionSet) if len(intersectionSet) % 2 == 0: if len(PolandBall) > len(EnemyBall): print("YES") else: print("NO") else: if len(PolandBall) >= len(EnemyBall): print("YES") else: print("NO")
Title: PolandBall and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally? Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters. Output Specification: In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. Demo Input: ['5 1\npolandball\nis\na\ncool\ncharacter\nnope\n', '2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n', '1 2\na\na\nb\n'] Demo Output: ['YES', 'YES', 'NO'] Note: In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
```python n, m = list(map(int, input().split())) PolandBall = set() EnemyBall = set() for i in range(n): PolandBall.add(input()) for i in range(m): EnemyBall.add(input()) intersectionSet = PolandBall.intersection(EnemyBall) PolandBall = PolandBall.difference(intersectionSet) EnemyBall = EnemyBall.difference(intersectionSet) if len(intersectionSet) % 2 == 0: if len(PolandBall) > len(EnemyBall): print("YES") else: print("NO") else: if len(PolandBall) >= len(EnemyBall): print("YES") else: print("NO") ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,452,824,750
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
716,800
import fileinput as fi def odd_one_out(nums): even_found, odd_found = False, False for index in range(len(nums)): next = nums[index] if (((next % 2 == 0) and odd_found) or ((next % 2 == 1) and even_found)): return index + 1 elif ((next % 2 == 0) and not (even_found)): even_found = True elif ((next % 2 == 1) and not (odd_found)): odd_found = True if __name__ == '__main__': argz = fi.input() argz[0] argline = argz[1] nums_as_str = argline.split(" ") nums = [int(s) for s in nums_as_str] print(odd_one_out(nums))
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python import fileinput as fi def odd_one_out(nums): even_found, odd_found = False, False for index in range(len(nums)): next = nums[index] if (((next % 2 == 0) and odd_found) or ((next % 2 == 1) and even_found)): return index + 1 elif ((next % 2 == 0) and not (even_found)): even_found = True elif ((next % 2 == 1) and not (odd_found)): odd_found = True if __name__ == '__main__': argz = fi.input() argz[0] argline = argz[1] nums_as_str = argline.split(" ") nums = [int(s) for s in nums_as_str] print(odd_one_out(nums)) ```
0
946
B
Weird Subtraction Process
PROGRAMMING
1,100
[ "math", "number theory" ]
null
null
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process. Initially the values of *a* and *b* are positive integers, and so the process will be finite. You have to determine the values of *a* and *b* after the process ends.
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Print two integers — the values of *a* and *b* after the end of the process.
[ "12 5\n", "31 12\n" ]
[ "0 1\n", "7 12\n" ]
Explanations to the samples: 1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12.
0
[ { "input": "12 5", "output": "0 1" }, { "input": "31 12", "output": "7 12" }, { "input": "1000000000000000000 7", "output": "8 7" }, { "input": "31960284556200 8515664064180", "output": "14928956427840 8515664064180" }, { "input": "1000000000000000000 1000000000000000000", "output": "1000000000000000000 1000000000000000000" }, { "input": "1 1000", "output": "1 0" }, { "input": "1 1000000", "output": "1 0" }, { "input": "1 1000000000000000", "output": "1 0" }, { "input": "1 99999999999999999", "output": "1 1" }, { "input": "1 4", "output": "1 0" }, { "input": "1000000000000001 500000000000000", "output": "1 0" }, { "input": "1 1000000000000000000", "output": "1 0" }, { "input": "2 4", "output": "2 0" }, { "input": "2 1", "output": "0 1" }, { "input": "6 19", "output": "6 7" }, { "input": "22 5", "output": "0 1" }, { "input": "10000000000000000 100000000000000001", "output": "0 1" }, { "input": "1 1000000000000", "output": "1 0" }, { "input": "2 1000000000000000", "output": "2 0" }, { "input": "2 10", "output": "2 2" }, { "input": "51 100", "output": "51 100" }, { "input": "3 1000000000000000000", "output": "3 4" }, { "input": "1000000000000000000 3", "output": "4 3" }, { "input": "1 10000000000000000", "output": "1 0" }, { "input": "8796203 7556", "output": "1019 1442" }, { "input": "5 22", "output": "1 0" }, { "input": "1000000000000000000 1", "output": "0 1" }, { "input": "1 100000000000", "output": "1 0" }, { "input": "2 1000000000000", "output": "2 0" }, { "input": "5 4567865432345678", "output": "5 8" }, { "input": "576460752303423487 288230376151711743", "output": "1 1" }, { "input": "499999999999999999 1000000000000000000", "output": "3 2" }, { "input": "1 9999999999999", "output": "1 1" }, { "input": "103 1000000000000000000", "output": "103 196" }, { "input": "7 1", "output": "1 1" }, { "input": "100000000000000001 10000000000000000", "output": "1 0" }, { "input": "5 10", "output": "5 0" }, { "input": "7 11", "output": "7 11" }, { "input": "1 123456789123456", "output": "1 0" }, { "input": "5000000000000 100000000000001", "output": "0 1" }, { "input": "1000000000000000 1", "output": "0 1" }, { "input": "1000000000000000000 499999999999999999", "output": "2 3" }, { "input": "10 5", "output": "0 5" }, { "input": "9 18917827189272", "output": "9 0" }, { "input": "179 100000000000497000", "output": "179 270" }, { "input": "5 100000000000001", "output": "1 1" }, { "input": "5 20", "output": "5 0" }, { "input": "100000001 50000000", "output": "1 0" }, { "input": "345869461223138161 835002744095575440", "output": "1 0" }, { "input": "8589934592 4294967296", "output": "0 4294967296" }, { "input": "4 8", "output": "4 0" }, { "input": "1 100000000000000000", "output": "1 0" }, { "input": "1000000000000000000 333333333333333", "output": "1000 1333" }, { "input": "25 12", "output": "1 0" }, { "input": "24 54", "output": "0 6" }, { "input": "6 12", "output": "6 0" }, { "input": "129200000000305 547300000001292", "output": "1 0" }, { "input": "1000000000000000000 49999999999999999", "output": "20 39" }, { "input": "1 2", "output": "1 0" }, { "input": "1 123456789876", "output": "1 0" }, { "input": "2 3", "output": "2 3" }, { "input": "1 3", "output": "1 1" }, { "input": "1 1", "output": "1 1" }, { "input": "19 46", "output": "3 2" }, { "input": "3 6", "output": "3 0" }, { "input": "129 1000000000000000000", "output": "1 0" }, { "input": "12 29", "output": "0 1" }, { "input": "8589934592 2147483648", "output": "0 2147483648" }, { "input": "2147483648 8589934592", "output": "2147483648 0" }, { "input": "5 6", "output": "5 6" }, { "input": "1000000000000000000 2", "output": "0 2" }, { "input": "2 7", "output": "2 3" }, { "input": "17174219820754872 61797504734333370", "output": "17174219820754872 27449065092823626" }, { "input": "49 100", "output": "1 0" }, { "input": "7 17", "output": "1 1" }, { "input": "1000000000000000000 10000001", "output": "0 1" }, { "input": "49999999999999999 2", "output": "3 2" }, { "input": "49999999999999999 1", "output": "1 1" }, { "input": "576460752303423487 2", "output": "3 2" }, { "input": "19395 19395", "output": "19395 19395" }, { "input": "19394 19394", "output": "19394 19394" } ]
1,568,953,882
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
217
716,800
a,b = map(int,input().split()) def one(a,b): if(a==0) or (b==0): print(a,b) exit() else: two(a,b) def two(a,b): if(a>=2*b): a=a-2*b one(a,b) else: three(a,b) def three(a,b): if(b>=2*a): b=b-2*a one(a,b) else: print(a,b) exit() one(a,b)
Title: Weird Subtraction Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process. Initially the values of *a* and *b* are positive integers, and so the process will be finite. You have to determine the values of *a* and *b* after the process ends. Input Specification: The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. Output Specification: Print two integers — the values of *a* and *b* after the end of the process. Demo Input: ['12 5\n', '31 12\n'] Demo Output: ['0 1\n', '7 12\n'] Note: Explanations to the samples: 1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12.
```python a,b = map(int,input().split()) def one(a,b): if(a==0) or (b==0): print(a,b) exit() else: two(a,b) def two(a,b): if(a>=2*b): a=a-2*b one(a,b) else: three(a,b) def three(a,b): if(b>=2*a): b=b-2*a one(a,b) else: print(a,b) exit() one(a,b) ```
-1
455
C
Civilization
PROGRAMMING
2,100
[ "dfs and similar", "dp", "dsu", "ternary search", "trees" ]
null
null
Andrew plays a game called "Civilization". Dima helps him. The game has *n* cities and *m* bidirectional roads. The cities are numbered from 1 to *n*. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities *v*1,<=*v*2,<=...,<=*v**k*, that there is a road between any contiguous cities *v**i* and *v**i*<=+<=1 (1<=≤<=*i*<=&lt;<=*k*). The length of the described path equals to (*k*<=-<=1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities. During the game events of two types take place: 1. Andrew asks Dima about the length of the longest path in the region where city *x* lies. 1. Andrew asks Dima to merge the region where city *x* lies with the region where city *y* lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them. Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.
The first line contains three integers *n*, *m*, *q* (1<=≤<=*n*<=≤<=3·105; 0<=≤<=*m*<=&lt;<=*n*; 1<=≤<=*q*<=≤<=3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly. Each of the following *m* lines contains two integers, *a**i* and *b**i* (*a**i*<=≠<=*b**i*; 1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). These numbers represent the road between cities *a**i* and *b**i*. There can be at most one road between two cities. Each of the following *q* lines contains one of the two events in the following format: - 1 *x**i*. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city *x**i* (1<=≤<=*x**i*<=≤<=*n*). 2 *x**i* *y**i*. It is the request Andrew gives to Dima to merge the region that contains city *x**i* and the region that contains city *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*). Note, that *x**i* can be equal to *y**i*.
For each event of the first type print the answer on a separate line.
[ "6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1\n" ]
[ "4\n" ]
none
1,500
[]
1,677,044,926
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
1
982
268,390,400
import fractions import gc import heapq import itertools from itertools import combinations, permutations import math import random from collections import Counter, deque, defaultdict from sys import stdout import time from math import factorial, log, gcd import sys from decimal import Decimal import threading from heapq import * from fractions import Fraction from bisect import bisect_left, bisect_right def S(): return sys.stdin.readline().split() def I(): return [int(i) for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n', '') def main(): n, m, q = I() tree = [[] for _ in range(n)] for _ in range(m): u, v = I() tree[u - 1].append(v - 1) tree[v - 1].append(u - 1) link = [-1] * n out_link = [[] for _ in range(n)] weights = [0] * n for i in range(n): if link[i] == -1: queue = deque([(i, 0, i)]) mx = (0, i) while queue: v, d, p = queue.pop() link[v] = i out_link[i].append(v) for u in tree[v]: if p != u: mx = max(mx, (d + 1, u)) queue.append((u, d + 1, v)) queue = deque([(mx[1], 0, mx[1])]) mx = (0, 0) while queue: v, d, p = queue.pop() for u in tree[v]: if p != u: mx = max(mx, (d + 1, u)) queue.append((u, d + 1, v)) weights[i] = mx[0] for _ in range(q): t, *z = I() if t == 1: x = z[0] print(weights[link[x - 1]]) else: x, y = z if x != y: head_x = link[x - 1] head_y = link[y - 1] if len(out_link[head_x]) > len(out_link[head_y]): head_x, head_y = head_y, head_x for i in out_link[head_x]: link[i] = head_y out_link[head_y].append(i) out_link[head_x] = [] w1, w2 = weights[head_x], weights[head_y] weights[head_y] = max([w1, w2, w1 // 2 + w1 % 2 + w2 // 2 + w2 % 2 + 1]) weights[head_x] = 0 if __name__ == '__main__': mod = 998244353 # for _ in range(II()): # main() main()
Title: Civilization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrew plays a game called "Civilization". Dima helps him. The game has *n* cities and *m* bidirectional roads. The cities are numbered from 1 to *n*. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities *v*1,<=*v*2,<=...,<=*v**k*, that there is a road between any contiguous cities *v**i* and *v**i*<=+<=1 (1<=≤<=*i*<=&lt;<=*k*). The length of the described path equals to (*k*<=-<=1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities. During the game events of two types take place: 1. Andrew asks Dima about the length of the longest path in the region where city *x* lies. 1. Andrew asks Dima to merge the region where city *x* lies with the region where city *y* lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them. Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima. Input Specification: The first line contains three integers *n*, *m*, *q* (1<=≤<=*n*<=≤<=3·105; 0<=≤<=*m*<=&lt;<=*n*; 1<=≤<=*q*<=≤<=3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly. Each of the following *m* lines contains two integers, *a**i* and *b**i* (*a**i*<=≠<=*b**i*; 1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). These numbers represent the road between cities *a**i* and *b**i*. There can be at most one road between two cities. Each of the following *q* lines contains one of the two events in the following format: - 1 *x**i*. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city *x**i* (1<=≤<=*x**i*<=≤<=*n*). 2 *x**i* *y**i*. It is the request Andrew gives to Dima to merge the region that contains city *x**i* and the region that contains city *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*). Note, that *x**i* can be equal to *y**i*. Output Specification: For each event of the first type print the answer on a separate line. Demo Input: ['6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1\n'] Demo Output: ['4\n'] Note: none
```python import fractions import gc import heapq import itertools from itertools import combinations, permutations import math import random from collections import Counter, deque, defaultdict from sys import stdout import time from math import factorial, log, gcd import sys from decimal import Decimal import threading from heapq import * from fractions import Fraction from bisect import bisect_left, bisect_right def S(): return sys.stdin.readline().split() def I(): return [int(i) for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n', '') def main(): n, m, q = I() tree = [[] for _ in range(n)] for _ in range(m): u, v = I() tree[u - 1].append(v - 1) tree[v - 1].append(u - 1) link = [-1] * n out_link = [[] for _ in range(n)] weights = [0] * n for i in range(n): if link[i] == -1: queue = deque([(i, 0, i)]) mx = (0, i) while queue: v, d, p = queue.pop() link[v] = i out_link[i].append(v) for u in tree[v]: if p != u: mx = max(mx, (d + 1, u)) queue.append((u, d + 1, v)) queue = deque([(mx[1], 0, mx[1])]) mx = (0, 0) while queue: v, d, p = queue.pop() for u in tree[v]: if p != u: mx = max(mx, (d + 1, u)) queue.append((u, d + 1, v)) weights[i] = mx[0] for _ in range(q): t, *z = I() if t == 1: x = z[0] print(weights[link[x - 1]]) else: x, y = z if x != y: head_x = link[x - 1] head_y = link[y - 1] if len(out_link[head_x]) > len(out_link[head_y]): head_x, head_y = head_y, head_x for i in out_link[head_x]: link[i] = head_y out_link[head_y].append(i) out_link[head_x] = [] w1, w2 = weights[head_x], weights[head_y] weights[head_y] = max([w1, w2, w1 // 2 + w1 % 2 + w2 // 2 + w2 % 2 + 1]) weights[head_x] = 0 if __name__ == '__main__': mod = 998244353 # for _ in range(II()): # main() main() ```
0
796
B
Find The Bone
PROGRAMMING
1,300
[ "implementation" ]
null
null
Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will confuse the audience by swapping the cups *k* times, the *i*-th time of which involves the cups at the positions *x*<==<=*u**i* and *x*<==<=*v**i*. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations. Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at *x*<==<=4 and the one at *x*<==<=6, they will not be at the position *x*<==<=5 at any moment during the operation. Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*n*) — the positions along the *x*-axis where there is a hole on the table. Each of the next *k* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the positions of the cups to be swapped.
Print one integer — the final position along the *x*-axis of the bone.
[ "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n", "5 1 2\n2\n1 2\n2 4\n" ]
[ "1", "2" ]
In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively. In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground.
750
[ { "input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "output": "1" }, { "input": "5 1 2\n2\n1 2\n2 4", "output": "2" }, { "input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11", "output": "55" }, { "input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5\n5 1\n1 4\n4 3\n3 2", "output": "4" }, { "input": "1000000 9 11\n38 59 999999 199 283 4849 1000000 2 554\n39 94\n3 9\n1 39\n39 40\n40 292\n5399 5858\n292 49949\n49949 222\n222 38\n202 9494\n38 59", "output": "38" }, { "input": "1000000 11 9\n19 28 39 82 99 929384 8298 892849 202020 777777 123123\n19 28\n28 39\n1 123124\n39 28\n28 99\n99 8298\n123124 123122\n2300 3200\n8298 1000000", "output": "123122" }, { "input": "2 1 1\n1\n1 2", "output": "1" }, { "input": "7 3 6\n1 4 5\n1 2\n2 3\n3 5\n4 5\n4 5\n4 5", "output": "1" }, { "input": "10 3 8\n1 5 10\n1 2\n2 3\n3 4\n3 4\n3 4\n4 5\n5 6\n6 5", "output": "1" }, { "input": "5 2 9\n2 4\n1 3\n3 5\n3 5\n3 4\n4 2\n2 4\n1 4\n1 2\n1 4", "output": "4" }, { "input": "10 10 13\n1 2 3 4 5 6 7 8 9 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n6 7\n6 10\n10 9\n9 1\n1 10\n1 10\n1 10", "output": "1" }, { "input": "3 3 3\n1 2 3\n1 2\n2 3\n3 2", "output": "1" }, { "input": "100 7 7\n17 27 37 47 57 67 77\n49 39\n55 1\n50 3\n89 1\n1 99\n100 55\n98 55", "output": "100" }, { "input": "9 1 9\n9\n1 2\n3 2\n4 3\n8 9\n4 5\n7 4\n8 5\n1 3\n3 2", "output": "8" }, { "input": "300000 1 1\n200000\n300000 1", "output": "300000" }, { "input": "203948 2 14\n203948 203946\n39 38\n4959 3030\n1 203947\n2929 9292\n203944 203948\n203947 203944\n203944 203922\n203922 203948\n2495 20495\n29419 5959\n12949 12\n49 29292\n1 94\n1 203", "output": "203948" }, { "input": "203948 2 14\n203948 203947\n39 38\n4959 3030\n1 203947\n2929 9292\n203944 203948\n203947 203944\n203944 203922\n203922 203948\n2495 20495\n29419 5959\n12949 12\n49 29292\n1 94\n1 203", "output": "203947" }, { "input": "100 2 5\n1 2\n2 39\n39 29\n99 100\n1 2\n2 39", "output": "1" }, { "input": "3 1 1\n1\n1 2", "output": "1" }, { "input": "5 2 2\n1 2\n1 2\n2 3", "output": "1" }, { "input": "2 2 1\n1 2\n2 1", "output": "1" }, { "input": "5 2 1\n1 2\n2 1", "output": "1" }, { "input": "5 1 1\n5\n3 4", "output": "1" }, { "input": "3 2 1\n1 2\n2 1", "output": "1" }, { "input": "5 1 2\n2\n2 1\n2 3", "output": "2" }, { "input": "3 1 2\n2\n2 1\n2 3", "output": "2" }, { "input": "3 2 2\n2 3\n2 1\n2 3", "output": "2" }, { "input": "4 2 1\n1 2\n2 1", "output": "1" }, { "input": "4 1 1\n2\n2 3", "output": "1" }, { "input": "3 2 1\n1 3\n3 1", "output": "1" }, { "input": "10 1 3\n2\n2 1\n2 4\n9 10", "output": "2" }, { "input": "5 2 4\n3 5\n1 2\n4 2\n3 4\n3 5", "output": "3" }, { "input": "4 3 1\n1 2 3\n2 1", "output": "1" } ]
1,547,826,798
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
20,377,600
n,m,k = (int(i) for i in input().split(' ')) a = [int(i) for i in input().split()] i = 0 j = 1 f = 0 s = 0 while (i < k): b = [int(i) for i in input().split(' ')] if (s == 0): if(j == b[0]): j = b[1] if (j in a): f = j s= 1 elif(j == b[1]): j = b[0] if(j in a): f = j s = 1 i+=1 if (f == 0): print(j) else: print(f)
Title: Find The Bone Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will confuse the audience by swapping the cups *k* times, the *i*-th time of which involves the cups at the positions *x*<==<=*u**i* and *x*<==<=*v**i*. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations. Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at *x*<==<=4 and the one at *x*<==<=6, they will not be at the position *x*<==<=5 at any moment during the operation. Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone. Input Specification: The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*n*) — the positions along the *x*-axis where there is a hole on the table. Each of the next *k* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the positions of the cups to be swapped. Output Specification: Print one integer — the final position along the *x*-axis of the bone. Demo Input: ['7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n', '5 1 2\n2\n1 2\n2 4\n'] Demo Output: ['1', '2'] Note: In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively. In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground.
```python n,m,k = (int(i) for i in input().split(' ')) a = [int(i) for i in input().split()] i = 0 j = 1 f = 0 s = 0 while (i < k): b = [int(i) for i in input().split(' ')] if (s == 0): if(j == b[0]): j = b[1] if (j in a): f = j s= 1 elif(j == b[1]): j = b[0] if(j in a): f = j s = 1 i+=1 if (f == 0): print(j) else: print(f) ```
0
369
A
Valera and Plates
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates. When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish.
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
[ "3 1 1\n1 2 1\n", "4 3 1\n1 1 1 1\n", "3 1 2\n2 2 2\n", "8 2 2\n1 2 1 2 1 2 1 2\n" ]
[ "1\n", "1\n", "0\n", "4\n" ]
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
500
[ { "input": "3 1 1\n1 2 1", "output": "1" }, { "input": "4 3 1\n1 1 1 1", "output": "1" }, { "input": "3 1 2\n2 2 2", "output": "0" }, { "input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4" }, { "input": "2 100 100\n2 2", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2", "output": "132" }, { "input": "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1", "output": "22" }, { "input": "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1", "output": "87" }, { "input": "3 1 2\n1 1 1", "output": "2" }, { "input": "3 2 2\n1 1 1", "output": "1" }, { "input": "3 2 1\n1 1 1", "output": "1" }, { "input": "3 1 1\n1 1 1", "output": "2" }, { "input": "5 1 2\n2 2 2 2 2", "output": "2" }, { "input": "5 2 2\n2 2 2 2 2", "output": "1" }, { "input": "5 2 1\n2 2 2 2 2", "output": "2" }, { "input": "5 1 1\n2 2 2 2 2", "output": "3" }, { "input": "1 1 2\n2", "output": "0" }, { "input": "1 2 2\n2", "output": "0" }, { "input": "1 2 1\n2", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "6 3 1\n1 1 2 2 2 2", "output": "2" }, { "input": "100 40 20\n2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "40" }, { "input": "7 5 2\n2 2 1 1 1 1 1", "output": "0" }, { "input": "10 4 4\n2 2 2 2 2 2 1 1 1 1", "output": "2" }, { "input": "3 2 1\n2 1 1", "output": "0" }, { "input": "7 6 1\n2 1 1 1 1 1 1", "output": "0" }, { "input": "7 5 1\n1 1 1 2 2 2 2", "output": "1" }, { "input": "5 3 1\n1 1 2 2 2", "output": "1" }, { "input": "3 1 1\n2 2 2", "output": "1" }, { "input": "5 2 2\n2 2 2 2 2", "output": "1" }, { "input": "3 1 3\n1 1 1", "output": "2" }, { "input": "5 2 1\n1 1 2 2 2", "output": "2" }, { "input": "4 3 2\n2 1 1 1", "output": "0" }, { "input": "4 2 1\n1 2 2 2", "output": "1" }, { "input": "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2", "output": "3" }, { "input": "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1", "output": "0" }, { "input": "5 3 2\n2 2 1 1 1", "output": "0" } ]
1,500,468,778
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
4,608,000
n,m,k=[int(i) for i in input().split()] t=0 a=[int(i) for i in input().split()] kases=a.count(1) if m==kases: result=(n-kases)-m result=max(0,result) if m<kases: result=kases-m result2=max((n-kases)-m,0) result=result2+result else: j1=m-kases k=j1+n resault=max(0,(n-kases)-k) print(result)
Title: Valera and Plates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates. When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally. Input Specification: The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish. Output Specification: Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. Demo Input: ['3 1 1\n1 2 1\n', '4 3 1\n1 1 1 1\n', '3 1 2\n2 2 2\n', '8 2 2\n1 2 1 2 1 2 1 2\n'] Demo Output: ['1\n', '1\n', '0\n', '4\n'] Note: In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
```python n,m,k=[int(i) for i in input().split()] t=0 a=[int(i) for i in input().split()] kases=a.count(1) if m==kases: result=(n-kases)-m result=max(0,result) if m<kases: result=kases-m result2=max((n-kases)-m,0) result=result2+result else: j1=m-kases k=j1+n resault=max(0,(n-kases)-k) print(result) ```
-1
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,187,704
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
def watermelon(w): if w%2!=0: return "NO" else: half=w//2 if half%2==0: return "YES" else: return "NO" weight=8 result=watermelon(weight) print(result)
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 watermelon(w): if w%2!=0: return "NO" else: half=w//2 if half%2==0: return "YES" else: return "NO" weight=8 result=watermelon(weight) print(result) ```
0
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,690,003,736
2,147,483,647
Python 3
OK
TESTS
85
124
0
s=input() l=['H','Q','9'] flag=0 for i in l: if i in s: flag=1 if flag: print("YES") else: print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python s=input() l=['H','Q','9'] flag=0 for i in l: if i in s: flag=1 if flag: print("YES") else: print("NO") ```
3
591
B
Rebranding
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Print the new name of the corporation.
[ "6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n" ]
[ "molice\n", "cdcbcdcfcdc\n" ]
In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "6 1\npolice\np m", "output": "molice" }, { "input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "output": "cdcbcdcfcdc" }, { "input": "1 1\nf\nz h", "output": "f" }, { "input": "1 1\na\na b", "output": "b" }, { "input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e", "output": "lellelleel" } ]
1,445,890,101
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
1,029
93,798,400
def main(name, n, m): for i in range(m): name = (lambda word, x, y: (y if i == x else (x if i == y else i) for i in word))(name, *input().split()) return "".join(name) n, m = map(int, input().split()) name = input() print(main(name, n, m))
Title: Rebranding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. Output Specification: Print the new name of the corporation. Demo Input: ['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n'] Demo Output: ['molice\n', 'cdcbcdcfcdc\n'] Note: In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python def main(name, n, m): for i in range(m): name = (lambda word, x, y: (y if i == x else (x if i == y else i) for i in word))(name, *input().split()) return "".join(name) n, m = map(int, input().split()) name = input() print(main(name, n, m)) ```
-1
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n510000", "output": "490000" }, { "input": "3\n2 5 27", "output": "26" }, { "input": "2\n600000 800000", "output": "400000" }, { "input": "5\n2 5 6 27 29", "output": "28" }, { "input": "1\n500001", "output": "499999" }, { "input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055", "output": "98054" }, { "input": "1\n900000", "output": "100000" }, { "input": "1\n500000", "output": "499999" }, { "input": "1\n999998", "output": "2" }, { "input": "3\n999997 999998 999999", "output": "3" }, { "input": "2\n999997 999999", "output": "3" }, { "input": "2\n2 999998", "output": "2" }, { "input": "2\n500000 500001", "output": "499999" }, { "input": "1\n500002", "output": "499998" }, { "input": "1\n700000", "output": "300000" }, { "input": "2\n2 999999", "output": "1" }, { "input": "2\n999998 999999", "output": "2" }, { "input": "1\n999995", "output": "5" }, { "input": "2\n499999 500001", "output": "499999" }, { "input": "1\n499999", "output": "499998" }, { "input": "2\n100 999900", "output": "100" }, { "input": "2\n499999 500000", "output": "499999" }, { "input": "2\n500001 999999", "output": "499999" }, { "input": "3\n500000 500001 500002", "output": "499999" }, { "input": "2\n2 500001", "output": "499999" }, { "input": "2\n499999 999999", "output": "499998" }, { "input": "2\n2 500000", "output": "499999" }, { "input": "4\n2 3 4 999999", "output": "3" }, { "input": "2\n100000 500001", "output": "499999" }, { "input": "1\n2", "output": "1" }, { "input": "1\n800000", "output": "200000" }, { "input": "1\n505050", "output": "494950" }, { "input": "1\n753572", "output": "246428" }, { "input": "2\n576696 760487", "output": "423304" }, { "input": "10\n3 4 5 6 7 8 9 10 11 12", "output": "11" }, { "input": "4\n2 3 4 5", "output": "4" }, { "input": "4\n999996 999997 999998 999999", "output": "4" } ]
1,594,661,341
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
171
30,515,200
n=int(input()) a=list(map(int,input().split())) a.sort() c=0 for i in range(n-1): c=c+min(a[i]-1,a[i+1]-a[i],(1000000-a[i])) c=c+min(a[n-1]-1,(1000000-a[n-1]),a[n-1]-a[n-2]) if((c-1)<0): print(0) else: print(c-1)
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. Output Specification: Print one integer — the minimum number of seconds it will take to collect all prizes. Demo Input: ['3\n2 3 9\n', '2\n2 999995\n'] Demo Output: ['8\n', '5\n'] Note: In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
```python n=int(input()) a=list(map(int,input().split())) a.sort() c=0 for i in range(n-1): c=c+min(a[i]-1,a[i+1]-a[i],(1000000-a[i])) c=c+min(a[n-1]-1,(1000000-a[n-1]),a[n-1]-a[n-2]) if((c-1)<0): print(0) else: print(c-1) ```
0
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,697,385,020
2,147,483,647
Python 3
OK
TESTS
25
92
0
x=input().strip() capt=x[0].upper()+x[1:] print(capt)
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 x=input().strip() capt=x[0].upper()+x[1:] print(capt) ```
3
820
B
Mister B and Angle in Polygon
PROGRAMMING
1,300
[ "constructive algorithms", "geometry", "math" ]
null
null
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them.
First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees.
Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order.
[ "3 15\n", "4 67\n", "4 68\n" ]
[ "1 2 3\n", "2 1 3\n", "4 1 2\n" ]
In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| &lt; |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| &lt; |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
1,000
[ { "input": "3 15", "output": "2 1 3" }, { "input": "4 67", "output": "2 1 3" }, { "input": "4 68", "output": "2 1 4" }, { "input": "3 1", "output": "2 1 3" }, { "input": "3 180", "output": "2 1 3" }, { "input": "100000 1", "output": "2 1 558" }, { "input": "100000 180", "output": "2 1 100000" }, { "input": "100000 42", "output": "2 1 23335" }, { "input": "100000 123", "output": "2 1 68335" }, { "input": "5 1", "output": "2 1 3" }, { "input": "5 36", "output": "2 1 3" }, { "input": "5 54", "output": "2 1 3" }, { "input": "5 55", "output": "2 1 4" }, { "input": "5 70", "output": "2 1 4" }, { "input": "5 89", "output": "2 1 4" }, { "input": "5 90", "output": "2 1 4" }, { "input": "5 91", "output": "2 1 5" }, { "input": "5 111", "output": "2 1 5" }, { "input": "5 126", "output": "2 1 5" }, { "input": "5 127", "output": "2 1 5" }, { "input": "5 141", "output": "2 1 5" }, { "input": "5 162", "output": "2 1 5" }, { "input": "5 180", "output": "2 1 5" }, { "input": "6 46", "output": "2 1 4" }, { "input": "6 33", "output": "2 1 3" }, { "input": "13 4", "output": "2 1 3" }, { "input": "23 11", "output": "2 1 3" }, { "input": "11 119", "output": "2 1 9" }, { "input": "13 117", "output": "2 1 10" }, { "input": "18 174", "output": "2 1 18" }, { "input": "8509 139", "output": "2 1 6573" }, { "input": "29770 76", "output": "2 1 12572" }, { "input": "59115 40", "output": "2 1 13139" }, { "input": "68459 88", "output": "2 1 33471" }, { "input": "85100 129", "output": "2 1 60990" }, { "input": "100000 13", "output": "2 1 7224" }, { "input": "100000 35", "output": "2 1 19446" }, { "input": "100000 49", "output": "2 1 27224" }, { "input": "100000 71", "output": "2 1 39446" }, { "input": "100000 79", "output": "2 1 43891" }, { "input": "100000 101", "output": "2 1 56113" }, { "input": "100000 109", "output": "2 1 60558" }, { "input": "100000 143", "output": "2 1 79446" }, { "input": "100000 148", "output": "2 1 82224" }, { "input": "100000 176", "output": "2 1 97780" }, { "input": "4 16", "output": "2 1 3" } ]
1,498,576,982
2,882
PyPy 3
WRONG_ANSWER
PRETESTS
6
93
23,142,400
""" Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout def main(): n, a = [int(_) for _ in stdin.readline().strip().split()] if n == 3: stdout.write('1 2 3\n') return smallest = 180 / n required = a // smallest if required == 0: ans = 3 else: x = smallest * required y = smallest * (required + 1) if abs(a - x) < abs(a - y): ans = 2 + required else: ans = 3 + required stdout.write('2 1 ' + str(int(ans)) + '\n') if __name__ == '__main__': main()
Title: Mister B and Angle in Polygon Time Limit: None seconds Memory Limit: None megabytes Problem Description: On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. Input Specification: First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. Output Specification: Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. Demo Input: ['3 15\n', '4 67\n', '4 68\n'] Demo Output: ['1 2 3\n', '2 1 3\n', '4 1 2\n'] Note: In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| &lt; |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1". In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| &lt; |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
```python """ Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout def main(): n, a = [int(_) for _ in stdin.readline().strip().split()] if n == 3: stdout.write('1 2 3\n') return smallest = 180 / n required = a // smallest if required == 0: ans = 3 else: x = smallest * required y = smallest * (required + 1) if abs(a - x) < abs(a - y): ans = 2 + required else: ans = 3 + required stdout.write('2 1 ' + str(int(ans)) + '\n') if __name__ == '__main__': main() ```
0
44
H
Phone Number
PROGRAMMING
1,700
[ "dp" ]
H. Phone Number
2
256
Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppose that Masha's phone number is 12345. After that one should write her favorite digit from 0 to 9 under the first digit of her number. That will be the first digit of the needed number. For example, Masha's favorite digit is 9. The second digit is determined as a half sum of the second digit of Masha's number and the already written down first digit from her beloved one's number. In this case the arithmetic average equals to (2<=+<=9)<=/<=2<==<=5.5. Masha can round the number up or down, depending on her wishes. For example, she chooses the digit 5. Having written down the resulting digit under the second digit of her number, Masha moves to finding the third digit in the same way, i.e. finding the half sum the the third digit of her number and the second digit of the new number. The result is (5<=+<=3)<=/<=2<==<=4. In this case the answer is unique. Thus, every *i*-th digit is determined as an arithmetic average of the *i*-th digit of Masha's number and the *i*<=-<=1-th digit of her true love's number. If needed, the digit can be rounded up or down. For example, Masha can get:
The first line contains nonempty sequence consisting of digits from 0 to 9 — Masha's phone number. The sequence length does not exceed 50.
Output the single number — the number of phone numbers Masha will dial.
[ "12345\n", "09\n" ]
[ "48\n", "15\n" ]
none
0
[ { "input": "12345", "output": "48" }, { "input": "09", "output": "15" }, { "input": "3", "output": "9" }, { "input": "55", "output": "14" }, { "input": "737", "output": "23" }, { "input": "21583", "output": "55" }, { "input": "33408349", "output": "133" }, { "input": "0180990956", "output": "473" }, { "input": "433488906230138", "output": "1399" }, { "input": "00046142930690780976", "output": "35257" }, { "input": "317579445234107659439645596", "output": "145866" }, { "input": "95066916647678224147260013920", "output": "446529" }, { "input": "36460576924876475371008334246121610", "output": "31319157" }, { "input": "429622625617508557672595893160462042433748844995", "output": "284175107" }, { "input": "17601120900014764776764048700928872725171605903217", "output": "10428170619" }, { "input": "39884857105160870767160905699169880375621726152715", "output": "244663375" }, { "input": "52056884218028089650567882557609167736461846591193", "output": "1358962463" }, { "input": "74239501210975375541963549337949373386030687741681", "output": "3422420940" }, { "input": "96591550315931484452350406227169651758570705180260", "output": "6869183484" }, { "input": "10764487327809690332754482187409867297140746339768", "output": "3435387051" }, { "input": "44444444444444444444444444444444444444444444444444", "output": "631" }, { "input": "9876543210", "output": "157" }, { "input": "23321232101010000101232344554334", "output": "5316368" }, { "input": "3232345665654567888878887898999998788766654567878", "output": "2520209072" }, { "input": "78776656654555655544443212222101121000000000100000", "output": "164642009" }, { "input": "78767765544454334445445555455676565433343455432332", "output": "11031574582" }, { "input": "67676566654565654332111011212211111223433222110012", "output": "5882859948" } ]
1,658,301,723
2,147,483,647
PyPy 3-64
OK
TESTS
27
122
0
import os import sys from math import floor, ceil if os.getenv('LOCALCFTEST'): sys.stdin = open('cfinput.txt') MOD = 998244353 def solve(s): s = list(map(int, s)) n = len(s) dp = [[0] * 10 for _ in range(n)] dp[0] = [1] * 10 flag = True for i in range(n - 1): t = (s[i] + s[i + 1]) / 2 if s[i + 1] != ceil(t) and s[i + 1] != floor(t): flag = False for j in range(10): a, b = divmod(j + s[i + 1], 2) dp[i + 1][a] += dp[i][j] if b == 1: dp[i + 1][a + 1] += dp[i][j] # print(dp) print(sum(dp[-1]) - flag) if __name__ == '__main__': s = input() solve(s)
Title: Phone Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppose that Masha's phone number is 12345. After that one should write her favorite digit from 0 to 9 under the first digit of her number. That will be the first digit of the needed number. For example, Masha's favorite digit is 9. The second digit is determined as a half sum of the second digit of Masha's number and the already written down first digit from her beloved one's number. In this case the arithmetic average equals to (2<=+<=9)<=/<=2<==<=5.5. Masha can round the number up or down, depending on her wishes. For example, she chooses the digit 5. Having written down the resulting digit under the second digit of her number, Masha moves to finding the third digit in the same way, i.e. finding the half sum the the third digit of her number and the second digit of the new number. The result is (5<=+<=3)<=/<=2<==<=4. In this case the answer is unique. Thus, every *i*-th digit is determined as an arithmetic average of the *i*-th digit of Masha's number and the *i*<=-<=1-th digit of her true love's number. If needed, the digit can be rounded up or down. For example, Masha can get: Input Specification: The first line contains nonempty sequence consisting of digits from 0 to 9 — Masha's phone number. The sequence length does not exceed 50. Output Specification: Output the single number — the number of phone numbers Masha will dial. Demo Input: ['12345\n', '09\n'] Demo Output: ['48\n', '15\n'] Note: none
```python import os import sys from math import floor, ceil if os.getenv('LOCALCFTEST'): sys.stdin = open('cfinput.txt') MOD = 998244353 def solve(s): s = list(map(int, s)) n = len(s) dp = [[0] * 10 for _ in range(n)] dp[0] = [1] * 10 flag = True for i in range(n - 1): t = (s[i] + s[i + 1]) / 2 if s[i + 1] != ceil(t) and s[i + 1] != floor(t): flag = False for j in range(10): a, b = divmod(j + s[i + 1], 2) dp[i + 1][a] += dp[i][j] if b == 1: dp[i + 1][a + 1] += dp[i][j] # print(dp) print(sum(dp[-1]) - flag) if __name__ == '__main__': s = input() solve(s) ```
3.9695
6
D
Lizards and Basements 2
PROGRAMMING
2,600
[ "brute force", "dp" ]
D. Lizards and Basements 2
2
64
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced. Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the *i*-th archer with his fire ball (they are numbered from left to right), the archer loses *a* health points. At the same time the spell damages the archers adjacent to the *i*-th (if any) — they lose *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=10) health points each. As the extreme archers (i.e. archers numbered 1 and *n*) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball. The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies? Polycarp can throw his fire ball into an archer if the latter is already killed.
The first line of the input contains three integers *n*,<=*a*,<=*b* (3<=≤<=*n*<=≤<=10; 1<=≤<=*b*<=&lt;<=*a*<=≤<=10). The second line contains a sequence of *n* integers — *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=15), where *h**i* is the amount of health points the *i*-th archer has.
In the first line print *t* — the required minimum amount of fire balls. In the second line print *t* numbers — indexes of the archers that Polycarp should hit to kill all the archers in *t* shots. All these numbers should be between 2 and *n*<=-<=1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
[ "3 2 1\n2 2 2\n", "4 3 1\n1 4 1 1\n" ]
[ "3\n2 2 2 ", "4\n2 2 3 3 " ]
none
0
[ { "input": "3 2 1\n2 2 2", "output": "3\n2 2 2 " }, { "input": "4 3 1\n1 4 1 1", "output": "4\n2 2 3 3 " }, { "input": "3 5 3\n1 2 1", "output": "1\n2 " }, { "input": "3 5 3\n3 2 2", "output": "2\n2 2 " }, { "input": "3 5 3\n3 2 2", "output": "2\n2 2 " }, { "input": "3 5 1\n10 10 10", "output": "11\n2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "3 5 3\n10 9 7", "output": "4\n2 2 2 2 " }, { "input": "3 5 1\n1 9 10", "output": "11\n2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "3 5 3\n10 9 7", "output": "4\n2 2 2 2 " }, { "input": "3 5 2\n9 3 6", "output": "5\n2 2 2 2 2 " }, { "input": "4 5 3\n2 2 2 1", "output": "2\n2 3 " }, { "input": "4 5 3\n2 3 2 2", "output": "2\n2 3 " }, { "input": "4 5 3\n4 2 4 2", "output": "3\n2 2 3 " }, { "input": "4 5 1\n4 9 1 8", "output": "14\n2 2 2 2 2 3 3 3 3 3 3 3 3 3 " }, { "input": "4 5 3\n9 9 3 4", "output": "6\n2 2 2 2 3 3 " }, { "input": "4 5 1\n8 8 9 8", "output": "18\n2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 " }, { "input": "4 5 3\n10 10 10 10", "output": "8\n2 2 2 2 3 3 3 3 " }, { "input": "4 5 2\n7 3 8 5", "output": "7\n2 2 2 2 3 3 3 " }, { "input": "4 5 3\n5 10 7 7", "output": "5\n2 2 3 3 3 " }, { "input": "4 3 1\n8 10 9 7", "output": "17\n2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 " }, { "input": "10 9 5\n12 14 11 11 14 14 12 15 14 12", "output": "10\n2 2 2 4 5 6 7 9 9 9 " }, { "input": "10 5 2\n12 10 6 7 11 4 3 5 9 3", "output": "13\n2 2 2 2 2 2 2 4 5 5 7 9 9 " }, { "input": "10 4 1\n5 12 10 5 13 6 5 5 2 10", "output": "25\n2 2 2 2 2 2 3 4 5 5 5 6 7 8 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 10 1\n10 12 11 4 12 1 15 15 11 12", "output": "30\n2 2 2 2 2 2 2 2 2 2 2 4 5 5 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 9 1\n6 12 9 3 7 3 3 11 13 10", "output": "23\n2 2 2 2 2 2 2 3 5 5 5 7 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 9 1\n8 7 9 8 14 1 9 11 8 13", "output": "28\n2 2 2 2 2 2 2 2 2 4 5 5 7 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 3\n9 11 9 11 4 5 7 13 12 9", "output": "13\n2 2 2 2 4 4 4 7 7 9 9 9 9 " }, { "input": "10 8 2\n11 10 13 12 9 10 9 9 10 12", "output": "18\n2 2 2 2 2 2 4 4 5 6 7 9 9 9 9 9 9 9 " }, { "input": "10 3 1\n9 6 8 7 10 10 9 6 6 7", "output": "28\n2 2 2 2 2 2 2 2 2 2 4 5 5 5 5 5 6 7 7 7 9 9 9 9 9 9 9 9 " }, { "input": "10 4 1\n6 5 4 5 5 4 5 4 5 4", "output": "18\n2 2 2 2 2 2 2 4 5 5 7 7 7 9 9 9 9 9 " }, { "input": "10 4 3\n2 1 2 4 2 4 3 2 2 4", "output": "6\n2 5 5 7 9 9 " }, { "input": "10 3 1\n4 4 3 3 3 3 2 1 3 1", "output": "11\n2 2 2 2 2 4 5 6 7 9 9 " }, { "input": "10 7 1\n3 3 2 1 3 1 2 2 3 1", "output": "9\n2 2 2 2 5 5 7 9 9 " }, { "input": "10 10 1\n8 8 8 8 8 8 8 8 8 8", "output": "22\n2 2 2 2 2 2 2 2 2 4 5 6 7 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 1\n11 9 11 10 10 11 9 10 9 11", "output": "33\n2 2 2 2 2 2 2 2 2 2 2 2 4 4 5 5 5 6 6 7 7 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 2\n10 9 14 9 13 11 14 10 14 10", "output": "21\n2 2 2 2 2 2 4 4 5 6 6 6 7 7 8 9 9 9 9 9 9 " }, { "input": "10 8 6\n14 12 14 12 10 8 10 13 9 12", "output": "10\n2 2 2 4 5 7 8 9 9 9 " }, { "input": "10 4 1\n7 8 9 8 8 7 8 9 7 7", "output": "23\n2 2 2 2 2 2 2 2 4 4 5 5 6 7 7 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n9 10 9 9 10 9 9 10 9 10", "output": "34\n2 2 2 2 2 2 2 2 2 2 4 4 5 5 5 5 5 5 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 9 4\n11 10 10 10 10 12 10 10 10 12", "output": "11\n2 2 2 4 5 6 7 9 9 9 9 " }, { "input": "10 10 4\n1 1 1 1 1 1 1 1 1 1", "output": "4\n2 5 8 9 " }, { "input": "10 2 1\n9 12 12 8 8 5 14 10 7 3", "output": "28\n2 2 2 2 2 2 2 2 2 2 4 4 4 5 5 5 7 7 7 7 7 7 7 8 9 9 9 9 " }, { "input": "10 2 1\n14 15 15 14 15 15 15 14 14 14", "output": "49\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 5 5 5 5 5 6 6 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 6 3\n9 8 8 8 11 11 9 10 9 11", "output": "13\n2 2 2 2 5 5 5 7 7 9 9 9 9 " }, { "input": "10 6 2\n11 8 10 11 10 8 8 13 9 13", "output": "19\n2 2 2 2 2 2 4 5 5 5 7 7 9 9 9 9 9 9 9 " }, { "input": "10 3 1\n3 7 9 12 11 3 4 3 14 8", "output": "22\n2 2 2 2 3 4 4 4 5 5 5 7 7 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 1\n6 7 10 7 6 8 9 8 6 9", "output": "25\n2 2 2 2 2 2 2 3 4 4 5 6 6 7 7 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 7 2\n2 9 2 6 8 7 6 5 6 2", "output": "8\n2 2 4 5 6 7 9 9 " }, { "input": "10 7 3\n2 7 2 7 3 4 3 2 4 3", "output": "7\n2 3 5 5 7 9 9 " }, { "input": "10 6 3\n8 9 8 9 8 9 10 9 8 9", "output": "12\n2 2 2 4 5 5 7 7 9 9 9 9 " }, { "input": "10 2 1\n10 9 10 9 9 9 10 8 8 10", "output": "35\n2 2 2 2 2 2 2 2 2 2 2 4 4 4 5 5 5 5 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 3\n4 4 5 6 4 6 4 5 5 4", "output": "8\n2 2 4 5 7 7 9 9 " }, { "input": "10 9 2\n5 7 8 8 7 5 7 4 4 5", "output": "11\n2 2 2 4 4 6 6 7 9 9 9 " }, { "input": "10 9 5\n8 7 5 9 8 7 8 11 11 8", "output": "7\n2 2 5 5 7 9 9 " }, { "input": "10 7 4\n5 6 6 6 7 7 6 5 5 5", "output": "7\n2 2 5 5 7 9 9 " }, { "input": "10 9 1\n10 11 11 11 11 11 11 11 11 11", "output": "29\n2 2 2 2 2 2 2 2 2 2 2 4 4 5 6 7 7 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 5 1\n6 5 6 5 6 6 6 5 6 6", "output": "19\n2 2 2 2 2 2 2 4 5 6 7 8 9 9 9 9 9 9 9 " }, { "input": "10 3 1\n8 7 9 7 9 12 12 6 8 8", "output": "29\n2 2 2 2 2 2 2 2 2 4 4 5 5 6 6 7 7 7 7 7 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 2\n7 3 5 3 5 5 3 4 2 4", "output": "10\n2 2 2 2 5 5 7 9 9 9 " }, { "input": "10 7 2\n5 2 5 3 2 3 4 3 5 3", "output": "8\n2 2 2 5 5 7 9 9 " }, { "input": "10 2 1\n5 3 6 6 7 4 4 4 3 3", "output": "18\n2 2 2 2 2 2 4 4 5 5 5 7 7 8 9 9 9 9 " }, { "input": "10 6 1\n13 13 13 13 13 13 13 13 13 13", "output": "36\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 5 5 6 6 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n14 11 11 11 15 15 12 15 12 14", "output": "47\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 5 5 5 5 5 5 5 5 6 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 7 1\n9 15 15 11 8 10 13 9 15 9", "output": "28\n2 2 2 2 2 2 2 2 2 2 3 4 4 5 6 7 7 7 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 10 4\n12 12 14 13 14 12 14 14 11 14", "output": "13\n2 2 2 2 4 5 6 7 8 9 9 9 9 " }, { "input": "10 6 4\n5 5 5 5 5 5 5 6 4 4", "output": "7\n2 2 5 5 7 9 9 " }, { "input": "10 8 7\n15 15 15 15 15 15 15 15 15 15", "output": "11\n2 2 2 5 5 5 7 7 9 9 9 " }, { "input": "10 9 5\n11 10 4 4 6 9 11 4 10 8", "output": "8\n2 2 2 5 7 8 9 9 " }, { "input": "10 6 3\n9 12 8 11 7 14 8 5 15 10", "output": "13\n2 2 2 2 4 5 5 6 7 9 9 9 9 " }, { "input": "10 3 1\n4 4 4 4 3 4 3 3 3 3", "output": "14\n2 2 2 2 2 4 5 5 6 7 9 9 9 9 " }, { "input": "10 6 4\n11 10 10 10 12 12 12 10 10 10", "output": "11\n2 2 2 4 4 6 6 7 9 9 9 " }, { "input": "10 6 1\n3 2 4 4 8 12 5 10 12 6", "output": "17\n2 2 2 2 4 5 6 6 7 8 9 9 9 9 9 9 9 " }, { "input": "10 9 5\n13 13 13 13 13 12 12 12 12 12", "output": "10\n2 2 2 4 5 7 7 9 9 9 " }, { "input": "10 4 1\n7 7 6 6 6 8 6 7 6 7", "output": "23\n2 2 2 2 2 2 2 2 4 5 5 5 6 7 7 9 9 9 9 9 9 9 9 " }, { "input": "10 6 3\n13 10 12 10 9 12 11 8 12 12", "output": "15\n2 2 2 2 2 4 4 6 6 7 9 9 9 9 9 " }, { "input": "10 6 2\n1 4 5 4 4 2 3 6 6 4", "output": "8\n2 4 4 6 8 9 9 9 " }, { "input": "10 8 1\n12 6 7 9 3 12 5 9 5 11", "output": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 6 6 7 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 4 2\n13 14 10 6 8 7 8 8 11 5", "output": "16\n2 2 2 2 2 2 2 4 5 5 7 7 8 9 9 9 " }, { "input": "10 8 1\n3 4 5 6 4 6 5 6 5 4", "output": "15\n2 2 2 2 4 4 5 6 7 9 9 9 9 9 9 " }, { "input": "10 7 2\n12 10 9 9 15 15 10 14 15 15", "output": "21\n2 2 2 2 2 2 2 4 5 5 6 6 7 9 9 9 9 9 9 9 9 " }, { "input": "10 3 1\n9 9 8 8 8 9 9 8 8 8", "output": "29\n2 2 2 2 2 2 2 2 2 2 4 4 5 5 5 6 7 7 7 7 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n5 4 5 4 4 4 4 4 4 5", "output": "18\n2 2 2 2 2 2 4 4 5 6 7 7 9 9 9 9 9 9 " }, { "input": "10 6 5\n11 8 5 13 8 9 11 15 11 12", "output": "11\n2 2 2 5 5 5 7 7 9 9 9 " }, { "input": "10 5 1\n7 10 15 5 15 5 5 5 11 7", "output": "24\n2 2 2 2 2 2 2 2 3 3 5 5 5 5 7 7 9 9 9 9 9 9 9 9 " }, { "input": "10 3 2\n5 5 4 4 4 4 4 4 5 4", "output": "10\n2 2 2 4 5 7 7 9 9 9 " }, { "input": "10 6 2\n5 8 4 5 1 3 6 7 5 3", "output": "8\n2 2 2 4 7 7 9 9 " }, { "input": "10 5 2\n10 12 10 10 11 9 11 11 9 9", "output": "18\n2 2 2 2 2 2 4 5 5 5 7 7 8 9 9 9 9 9 " }, { "input": "10 6 5\n9 8 10 10 11 11 8 9 10 11", "output": "9\n2 2 4 5 6 7 9 9 9 " }, { "input": "10 3 2\n3 5 1 4 5 3 3 1 3 4", "output": "9\n2 2 4 5 6 8 9 9 9 " }, { "input": "10 3 2\n4 9 6 9 6 8 4 5 6 9", "output": "15\n2 2 2 3 5 5 5 5 7 8 9 9 9 9 9 " }, { "input": "10 3 2\n8 9 8 9 8 8 8 8 8 8", "output": "17\n2 2 2 2 2 4 4 5 5 7 7 7 9 9 9 9 9 " }, { "input": "10 2 1\n11 6 9 9 11 10 7 13 11 9", "output": "35\n2 2 2 2 2 2 2 2 2 2 2 2 4 5 5 5 5 5 5 5 5 7 7 7 7 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 6 1\n4 5 5 3 7 5 6 5 6 8", "output": "18\n2 2 2 2 2 4 5 6 7 9 9 9 9 9 9 9 9 9 " }, { "input": "10 9 6\n15 14 14 12 15 10 9 14 13 8", "output": "9\n2 2 2 4 5 6 8 9 9 " }, { "input": "10 7 1\n9 9 9 9 9 9 9 9 9 9", "output": "26\n2 2 2 2 2 2 2 2 2 2 4 4 5 6 7 7 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 6 5\n4 5 4 1 3 6 3 2 2 2", "output": "4\n2 5 7 9 " }, { "input": "10 10 3\n10 8 11 11 10 11 11 9 7 10", "output": "12\n2 2 2 2 4 5 6 7 9 9 9 9 " }, { "input": "10 3 2\n7 8 11 6 8 7 2 3 8 7", "output": "13\n2 2 2 2 4 4 5 6 6 9 9 9 9 " }, { "input": "10 8 6\n9 9 8 10 7 13 7 11 13 12", "output": "8\n2 2 5 5 7 9 9 9 " }, { "input": "10 3 2\n9 13 9 10 12 10 14 13 11 11", "output": "21\n2 2 2 2 2 4 5 5 5 5 7 7 7 7 7 9 9 9 9 9 9 " }, { "input": "10 3 2\n12 12 14 15 15 12 12 14 12 14", "output": "26\n2 2 2 2 2 2 2 4 4 4 4 5 5 6 7 7 7 8 9 9 9 9 9 9 9 9 " }, { "input": "10 7 4\n6 4 8 4 8 7 10 6 8 6", "output": "8\n2 2 4 6 6 8 9 9 " }, { "input": "10 5 4\n14 14 14 10 13 15 13 13 10 14", "output": "14\n2 2 2 2 5 5 5 7 7 8 9 9 9 9 " }, { "input": "10 10 2\n10 10 13 10 10 12 6 8 11 12", "output": "17\n2 2 2 2 2 2 4 5 6 7 9 9 9 9 9 9 9 " }, { "input": "10 6 4\n5 6 5 6 6 7 5 7 9 9", "output": "8\n2 2 5 5 7 9 9 9 " }, { "input": "10 7 5\n10 10 10 10 10 10 10 10 10 10", "output": "10\n2 2 2 4 5 7 7 9 9 9 " }, { "input": "10 5 1\n11 10 10 10 11 11 11 10 11 11", "output": "32\n2 2 2 2 2 2 2 2 2 2 2 2 4 4 5 5 6 6 7 7 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 10 4\n13 13 13 13 13 13 13 13 13 13", "output": "12\n2 2 2 2 4 5 6 7 9 9 9 9 " }, { "input": "10 5 2\n4 5 3 6 7 8 4 4 9 6", "output": "11\n2 2 2 4 5 6 7 9 9 9 9 " }, { "input": "10 7 3\n5 9 8 8 8 7 6 7 6 5", "output": "8\n2 2 4 5 7 7 9 9 " }, { "input": "10 2 1\n12 13 15 14 14 11 12 14 11 15", "output": "46\n2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 5 5 5 5 5 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n13 12 15 12 14 14 14 15 13 15", "output": "48\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n14 15 15 14 14 15 14 15 14 15", "output": "50\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n9 7 14 8 14 15 15 9 12 13", "output": "42\n2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n14 15 15 14 15 14 15 14 15 15", "output": "50\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n9 7 14 8 14 15 15 9 12 13", "output": "42\n2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "10 2 1\n4 14 13 15 14 5 8 11 12 14", "output": "38\n2 2 2 2 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " } ]
1,430,980,417
2,147,483,647
Python 3
OK
TESTS
117
124
0
__author__ = 'Darren' def solve(): n, a, b = map(int, input().split()) h = [0] h.extend(map(int, input().split())) fires = [] count = h[1] // b + 1 if h[1] >= 0 else 0 fires.extend([2 for i in range(count)]) h[1] -= b * count h[2] -= a * count h[3] -= b * count count = h[n] // b + 1 if h[n] >= 0 else 0 fires.extend([n-1 for i in range(count)]) h[n] -= b * count h[n-1] -= a * count h[n-2] -= b * count temp = fires.copy() for i in range(2, n): count = h[i] // a + 1 fires.extend([i for j in range(count)]) def search(pos): nonlocal n, a, b, h, fires, temp if pos == n and h[pos-1] < 0: if len(fires) > len(temp): fires = temp.copy() return balls = 0 count = h[pos-1] // b + 1 if h[pos-1] >= 0 else 0 temp.extend([pos for i in range(count)]) h[pos-1] -= b * count h[pos] -= a * count h[pos+1] -= b * count balls += count while h[pos] >= 0: search(pos+1) temp.append(pos) h[pos-1] -= b h[pos] -= a h[pos+1] -= b balls += 1 search(pos+1) h[pos-1] += b * balls h[pos] += a * balls h[pos+1] += b * balls for i in range(balls): temp.pop() search(2) print(len(fires)) print(' '.join(map(str, fires))) if __name__ == '__main__': solve()
Title: Lizards and Basements 2 Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced. Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the *i*-th archer with his fire ball (they are numbered from left to right), the archer loses *a* health points. At the same time the spell damages the archers adjacent to the *i*-th (if any) — they lose *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=10) health points each. As the extreme archers (i.e. archers numbered 1 and *n*) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball. The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies? Polycarp can throw his fire ball into an archer if the latter is already killed. Input Specification: The first line of the input contains three integers *n*,<=*a*,<=*b* (3<=≤<=*n*<=≤<=10; 1<=≤<=*b*<=&lt;<=*a*<=≤<=10). The second line contains a sequence of *n* integers — *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=15), where *h**i* is the amount of health points the *i*-th archer has. Output Specification: In the first line print *t* — the required minimum amount of fire balls. In the second line print *t* numbers — indexes of the archers that Polycarp should hit to kill all the archers in *t* shots. All these numbers should be between 2 and *n*<=-<=1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order. Demo Input: ['3 2 1\n2 2 2\n', '4 3 1\n1 4 1 1\n'] Demo Output: ['3\n2 2 2 ', '4\n2 2 3 3 '] Note: none
```python __author__ = 'Darren' def solve(): n, a, b = map(int, input().split()) h = [0] h.extend(map(int, input().split())) fires = [] count = h[1] // b + 1 if h[1] >= 0 else 0 fires.extend([2 for i in range(count)]) h[1] -= b * count h[2] -= a * count h[3] -= b * count count = h[n] // b + 1 if h[n] >= 0 else 0 fires.extend([n-1 for i in range(count)]) h[n] -= b * count h[n-1] -= a * count h[n-2] -= b * count temp = fires.copy() for i in range(2, n): count = h[i] // a + 1 fires.extend([i for j in range(count)]) def search(pos): nonlocal n, a, b, h, fires, temp if pos == n and h[pos-1] < 0: if len(fires) > len(temp): fires = temp.copy() return balls = 0 count = h[pos-1] // b + 1 if h[pos-1] >= 0 else 0 temp.extend([pos for i in range(count)]) h[pos-1] -= b * count h[pos] -= a * count h[pos+1] -= b * count balls += count while h[pos] >= 0: search(pos+1) temp.append(pos) h[pos-1] -= b h[pos] -= a h[pos+1] -= b balls += 1 search(pos+1) h[pos-1] += b * balls h[pos] += a * balls h[pos+1] += b * balls for i in range(balls): temp.pop() search(2) print(len(fires)) print(' '.join(map(str, fires))) if __name__ == '__main__': solve() ```
3.969