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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "499999999"
},
{
"input": "1924704072",
"output": "481176017"
},
{
"input": "73740586",
"output": "18435146"
},
{
"input": "1925088820",
"output": "481272204"
},
{
"input": "593070992",
"output": "148267747"
},
{
"input": "1925473570",
"output": "481368392"
},
{
"input": "629490186",
"output": "157372546"
},
{
"input": "1980649112",
"output": "495162277"
},
{
"input": "36661322",
"output": "9165330"
},
{
"input": "1943590793",
"output": "0"
},
{
"input": "71207034",
"output": "17801758"
},
{
"input": "1757577394",
"output": "439394348"
},
{
"input": "168305294",
"output": "42076323"
},
{
"input": "1934896224",
"output": "483724055"
},
{
"input": "297149088",
"output": "74287271"
},
{
"input": "1898001634",
"output": "474500408"
},
{
"input": "176409698",
"output": "44102424"
},
{
"input": "1873025522",
"output": "468256380"
},
{
"input": "5714762",
"output": "1428690"
},
{
"input": "1829551192",
"output": "457387797"
},
{
"input": "16269438",
"output": "4067359"
},
{
"input": "1663283390",
"output": "415820847"
},
{
"input": "42549941",
"output": "0"
},
{
"input": "1967345604",
"output": "491836400"
},
{
"input": "854000",
"output": "213499"
},
{
"input": "1995886626",
"output": "498971656"
},
{
"input": "10330019",
"output": "0"
},
{
"input": "1996193634",
"output": "499048408"
},
{
"input": "9605180",
"output": "2401294"
},
{
"input": "1996459740",
"output": "499114934"
},
{
"input": "32691948",
"output": "8172986"
},
{
"input": "1975903308",
"output": "493975826"
},
{
"input": "1976637136",
"output": "494159283"
},
{
"input": "29803038",
"output": "7450759"
},
{
"input": "1977979692",
"output": "494494922"
},
{
"input": "1978595336",
"output": "494648833"
},
{
"input": "27379344",
"output": "6844835"
},
{
"input": "1979729912",
"output": "494932477"
},
{
"input": "1980253780",
"output": "495063444"
},
{
"input": "1980751584",
"output": "495187895"
},
{
"input": "53224878",
"output": "13306219"
},
{
"input": "5",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "2"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "0"
},
{
"input": "14",
"output": "3"
},
{
"input": "15",
"output": "0"
},
{
"input": "16",
"output": "3"
},
{
"input": "17",
"output": "0"
},
{
"input": "18",
"output": "4"
},
{
"input": "19",
"output": "0"
},
{
"input": "21",
"output": "0"
},
{
"input": "22",
"output": "5"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "26",
"output": "6"
},
{
"input": "27",
"output": "0"
},
{
"input": "28",
"output": "6"
},
{
"input": "29",
"output": "0"
},
{
"input": "30",
"output": "7"
},
{
"input": "111",
"output": "0"
},
{
"input": "55",
"output": "0"
},
{
"input": "105",
"output": "0"
},
{
"input": "199",
"output": "0"
},
{
"input": "151",
"output": "0"
}
] | 1,570,001,014 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | n=int(input())
y=n
l=[]
i=1
c=0
while True:
y=y-(2*i)
x=y//2
if x<=i:
break
y=y-(2*x)
if y==0:
c+=1
y=n
i+=1
print(c)
| Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
Output Specification:
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Demo Input:
['6\n', '20\n']
Demo Output:
['1\n', '4\n']
Note:
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | ```python
n=int(input())
y=n
l=[]
i=1
c=0
while True:
y=y-(2*i)
x=y//2
if x<=i:
break
y=y-(2*x)
if y==0:
c+=1
y=n
i+=1
print(c)
``` | 0 |
|
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,609,937,341 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 0 | n = input ()
def fib(n):
if n <= 1:
return 1
else:
return(fib(n-1) + fib(n-2))
f = [fib(d) for d in range(1,n)]
for i in range(1,n+1):
print (['o','O'][i in f],end='') | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
n = input ()
def fib(n):
if n <= 1:
return 1
else:
return(fib(n-1) + fib(n-2))
f = [fib(d) for d in range(1,n)]
for i in range(1,n+1):
print (['o','O'][i in f],end='')
``` | -1 |
|
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,694,371,262 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 |
def main():
n = int(input())
b = []
a = []
for _ in range(n):
ai, bi = map(int,input().split())
a.append(ai)
b.append(bi)
open = set()
res = 0
for i in range(len(b)):
if b[i] == a[i]:
res += 1
g = b[i]
open.add(g)
print(len(a) - len(open) + res)
main()
| Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none | ```python
def main():
n = int(input())
b = []
a = []
for _ in range(n):
ai, bi = map(int,input().split())
a.append(ai)
b.append(bi)
open = set()
res = 0
for i in range(len(b)):
if b[i] == a[i]:
res += 1
g = b[i]
open.add(g)
print(len(a) - len(open) + res)
main()
``` | 0 |
|
538 | C | Tourist's Notes | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"greedy",
"implementation",
"math"
] | null | null | A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all *i*'s from 1 to *n*<=-<=1 the inequality |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1 holds.
At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1. | The first line contains two space-separated numbers, *n* and *m* (1<=≤<=*n*<=≤<=108, 1<=≤<=*m*<=≤<=105) — the number of days of the hike and the number of notes left in the journal.
Next *m* lines contain two space-separated integers *d**i* and *h**d**i* (1<=≤<=*d**i*<=≤<=*n*, 0<=≤<=*h**d**i*<=≤<=108) — the number of the day when the *i*-th note was made and height on the *d**i*-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all *i* from 1 to *m*<=-<=1 the following condition holds: *d**i*<=<<=*d**i*<=+<=1. | If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes). | [
"8 2\n2 0\n7 0\n",
"8 3\n2 0\n7 0\n8 3\n"
] | [
"2\n",
"IMPOSSIBLE\n"
] | For the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).
In the second sample the inequality between *h*<sub class="lower-index">7</sub> and *h*<sub class="lower-index">8</sub> does not hold, thus the information is inconsistent. | 1,500 | [
{
"input": "8 2\n2 0\n7 0",
"output": "2"
},
{
"input": "8 3\n2 0\n7 0\n8 3",
"output": "IMPOSSIBLE"
},
{
"input": "10 10\n1 0\n2 0\n3 0\n4 0\n5 1\n6 2\n7 3\n8 2\n9 3\n10 4",
"output": "4"
},
{
"input": "50 10\n1 42\n7 36\n16 40\n21 40\n26 39\n30 41\n32 41\n36 40\n44 37\n50 41",
"output": "42"
},
{
"input": "50 10\n5 17\n7 15\n10 4\n15 11\n18 13\n21 15\n31 5\n34 13\n40 15\n49 16",
"output": "IMPOSSIBLE"
},
{
"input": "100 50\n1 53\n3 51\n4 50\n6 48\n9 45\n12 48\n14 46\n16 48\n17 47\n19 49\n20 48\n22 46\n23 45\n24 44\n26 46\n27 47\n29 49\n32 52\n33 53\n35 55\n37 53\n40 50\n41 51\n43 53\n47 57\n50 60\n51 59\n52 60\n57 65\n59 63\n60 62\n61 61\n62 60\n64 62\n68 66\n70 64\n71 63\n73 65\n77 69\n79 67\n81 65\n83 63\n86 66\n88 68\n89 69\n91 67\n94 64\n95 63\n98 60\n100 58",
"output": "69"
},
{
"input": "10 1\n4 16160172",
"output": "16160178"
},
{
"input": "10000 2\n3270 897970\n8270 899508",
"output": "901239"
},
{
"input": "100000000 1\n9783835 100000000",
"output": "190216165"
},
{
"input": "100000000 1\n1 100000000",
"output": "199999999"
},
{
"input": "100000000 1\n100000000 100000000",
"output": "199999999"
},
{
"input": "100000000 2\n1 100000000\n100000000 100000000",
"output": "149999999"
},
{
"input": "100000000 2\n50000000 100000000\n50000001 100000000",
"output": "149999999"
},
{
"input": "99999999 20\n3 100000000\n14 100000000\n22 100000000\n24 100000000\n31 100000000\n41 100000000\n46 100000000\n84 100000000\n94 100000000\n98 100000000\n99999912 100000000\n99999915 100000000\n99999916 100000000\n99999923 100000000\n99999935 100000000\n99999937 100000000\n99999954 100000000\n99999955 100000000\n99999979 100000000\n99999982 100000000",
"output": "149999907"
},
{
"input": "8 3\n2 0\n7 3\n8 0",
"output": "IMPOSSIBLE"
},
{
"input": "10 1\n5 5",
"output": "10"
},
{
"input": "100 2\n1 100\n2 1",
"output": "IMPOSSIBLE"
},
{
"input": "1 1\n1 100",
"output": "100"
},
{
"input": "1 1\n1 10",
"output": "10"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "9 2\n1 8\n9 11",
"output": "13"
},
{
"input": "9 2\n1 1\n9 3",
"output": "6"
},
{
"input": "10000000 1\n10000000 0",
"output": "9999999"
},
{
"input": "3 2\n1 0\n3 0",
"output": "1"
},
{
"input": "100000000 2\n1 2\n2 1",
"output": "99999999"
},
{
"input": "1 1\n1 5",
"output": "5"
}
] | 1,645,780,972 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 483 | 18,329,600 | from re import L
from sys import stdin
input=stdin.readline
j=[]
res=-1e9
n,m=map(int,input().split())
for _ in range(m):
d,h=map(int,input().split())
res=max(res,h)
j.append([d,h])
def solve(c,n):
l,r=0,1e8
ad=abs(c[0]-n[0])-abs(c[1]-n[1])
while l<r:
mid=(l+r)//2
if ad//2>mid:
l=mid+1
else:
r=mid
return int(l)
pass
for i in range(m-1):
next=j[i+1];curr=j[i]
if abs(curr[1]-next[1])>abs(curr[0]-next[0]):print('IMPOSSIBLE');exit()
else:
res=max(res,solve(curr,next))
print(res)
| Title: Tourist's Notes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all *i*'s from 1 to *n*<=-<=1 the inequality |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1 holds.
At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1.
Input Specification:
The first line contains two space-separated numbers, *n* and *m* (1<=≤<=*n*<=≤<=108, 1<=≤<=*m*<=≤<=105) — the number of days of the hike and the number of notes left in the journal.
Next *m* lines contain two space-separated integers *d**i* and *h**d**i* (1<=≤<=*d**i*<=≤<=*n*, 0<=≤<=*h**d**i*<=≤<=108) — the number of the day when the *i*-th note was made and height on the *d**i*-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all *i* from 1 to *m*<=-<=1 the following condition holds: *d**i*<=<<=*d**i*<=+<=1.
Output Specification:
If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes).
Demo Input:
['8 2\n2 0\n7 0\n', '8 3\n2 0\n7 0\n8 3\n']
Demo Output:
['2\n', 'IMPOSSIBLE\n']
Note:
For the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).
In the second sample the inequality between *h*<sub class="lower-index">7</sub> and *h*<sub class="lower-index">8</sub> does not hold, thus the information is inconsistent. | ```python
from re import L
from sys import stdin
input=stdin.readline
j=[]
res=-1e9
n,m=map(int,input().split())
for _ in range(m):
d,h=map(int,input().split())
res=max(res,h)
j.append([d,h])
def solve(c,n):
l,r=0,1e8
ad=abs(c[0]-n[0])-abs(c[1]-n[1])
while l<r:
mid=(l+r)//2
if ad//2>mid:
l=mid+1
else:
r=mid
return int(l)
pass
for i in range(m-1):
next=j[i+1];curr=j[i]
if abs(curr[1]-next[1])>abs(curr[0]-next[0]):print('IMPOSSIBLE');exit()
else:
res=max(res,solve(curr,next))
print(res)
``` | 0 |
|
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club. | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
{
"input": "5 4\n1 4\n4 3\n4 5\n5 2",
"output": "2"
},
{
"input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11",
"output": "4"
},
{
"input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7",
"output": "2"
},
{
"input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6",
"output": "0"
},
{
"input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3",
"output": "0"
},
{
"input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5",
"output": "0"
},
{
"input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6",
"output": "1"
},
{
"input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4",
"output": "0"
},
{
"input": "95 0",
"output": "0"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39",
"output": "2"
},
{
"input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51",
"output": "3"
},
{
"input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41",
"output": "3"
},
{
"input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65",
"output": "5"
},
{
"input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7",
"output": "4"
},
{
"input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35",
"output": "4"
},
{
"input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65",
"output": "8"
},
{
"input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36",
"output": "4"
},
{
"input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70",
"output": "4"
},
{
"input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66",
"output": "3"
},
{
"input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27",
"output": "8"
},
{
"input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51",
"output": "4"
},
{
"input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75",
"output": "5"
},
{
"input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31",
"output": "3"
},
{
"input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35",
"output": "8"
},
{
"input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37",
"output": "3"
},
{
"input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41",
"output": "4"
},
{
"input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53",
"output": "5"
}
] | 1,624,025,281 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 186 | 204,800 | from collections import defaultdict
n,m=map(int,input().split())
dic=defaultdict(list)
li=[0]*n
for i in range(m):
u,v=list(map(int,input().split()))
u=u-1
v=v-1
li[u]+=1
li[v]+=1
dic[u].append(v)
dic[v].append(u)
r=0
for i in range(n):
res=[]
for i in range(n):
if li[i]==1:
res.append(i)
li[i]=0
#print(res)
if len(res)==0:
break
r+=1
for j in res:
for k in dic[j]:
li[k]-=1
print(r)
| Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club.
Input Specification:
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Output Specification:
Print the single number — the number of groups of students that will be kicked out from the club.
Demo Input:
['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | ```python
from collections import defaultdict
n,m=map(int,input().split())
dic=defaultdict(list)
li=[0]*n
for i in range(m):
u,v=list(map(int,input().split()))
u=u-1
v=v-1
li[u]+=1
li[v]+=1
dic[u].append(v)
dic[v].append(u)
r=0
for i in range(n):
res=[]
for i in range(n):
if li[i]==1:
res.append(i)
li[i]=0
#print(res)
if len(res)==0:
break
r+=1
for j in res:
for k in dic[j]:
li[k]-=1
print(r)
``` | 3 |
|
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order. | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 1,636,144,629 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 467 | 12,288,000 | from collections import defaultdict
import cmath
n = int(input())
vala = []
valb = []
suma = sumb = 0
seqa = ""
seqb = ""
for i in range(n):
val = int(input())
if val > 0:
vala.append(val)
suma += val
seqa += str(val)
else:
valb.append(val)
sumb += abs(val)
seqb += str(abs(val))
if suma > sumb :
print("first")
elif sumb > suma :
print("second")
else:
if seqa > seqb:
print("first")
elif seqb > seqa:
print("second")
else:
print("second")
| Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input Specification:
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
Output Specification:
If the first wrestler wins, print string "first", otherwise print "second"
Demo Input:
['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n']
Demo Output:
['second\n', 'first\n', 'second\n']
Note:
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | ```python
from collections import defaultdict
import cmath
n = int(input())
vala = []
valb = []
suma = sumb = 0
seqa = ""
seqb = ""
for i in range(n):
val = int(input())
if val > 0:
vala.append(val)
suma += val
seqa += str(val)
else:
valb.append(val)
sumb += abs(val)
seqb += str(abs(val))
if suma > sumb :
print("first")
elif sumb > suma :
print("second")
else:
if seqa > seqb:
print("first")
elif seqb > seqa:
print("second")
else:
print("second")
``` | 0 |
|
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 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\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 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",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314",
"output": "1762894"
},
{
"input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585",
"output": "2960349"
},
{
"input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933",
"output": "99140444"
},
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686",
"output": "301124161"
},
{
"input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495",
"output": "30125295"
},
{
"input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165",
"output": "136422"
},
{
"input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348",
"output": "2578628"
},
{
"input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338",
"output": "9168707"
},
{
"input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657",
"output": "144901921"
},
{
"input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860",
"output": "809931"
},
{
"input": "a\n0\n5 1 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": "5"
},
{
"input": "lol\n3\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "21"
}
] | 1,469,951,698 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | t = input
r = range
p = print
s = t()
k = int(t())
w = list(map(int, t().split()))
ans = 0
ma = max(w)
for i in r(len(s)):
ans += w[ord(s[i]) - 97] * (i + 1)
p(ans + 0 if k == 0 else ((k + len(s)) * (k + len(s) - 1) // 2) * ma)
| Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input Specification:
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Output Specification:
Print a single integer — the largest possible value of the resulting string DZY could get.
Demo Input:
['abc\n3\n1 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\n']
Demo Output:
['41\n']
Note:
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | ```python
t = input
r = range
p = print
s = t()
k = int(t())
w = list(map(int, t().split()))
ans = 0
ma = max(w)
for i in r(len(s)):
ans += w[ord(s[i]) - 97] * (i + 1)
p(ans + 0 if k == 0 else ((k + len(s)) * (k + len(s) - 1) // 2) * ma)
``` | 0 |
|
463 | C | Gargari and Bishops | PROGRAMMING | 1,900 | [
"greedy",
"hashing",
"implementation"
] | null | null | Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard. | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right.
If there are several optimal solutions, you can print any of them. | [
"4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n"
] | [
"12\n2 2 3 2\n"
] | none | 1,500 | [
{
"input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1",
"output": "12\n2 2 3 2"
},
{
"input": "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 79 51\n93 66 53 39 89 30 16 27 63 93",
"output": "2242\n6 6 7 6"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0",
"output": "0\n1 1 1 2"
},
{
"input": "15\n2 6 9 4 8 9 10 10 3 8 8 4 4 8 7\n10 9 2 6 8 10 5 2 8 4 9 6 9 10 10\n3 1 5 1 6 5 1 6 4 4 3 3 9 8 10\n5 7 10 6 4 9 6 8 1 5 4 9 10 4 8\n9 6 10 5 8 6 9 9 3 4 4 7 6 2 4\n8 6 10 7 3 3 8 10 3 8 4 8 8 3 1\n7 3 6 8 8 5 5 8 3 7 2 6 3 9 7\n6 8 4 7 7 7 10 4 6 4 3 10 1 10 2\n1 6 7 8 3 4 2 8 1 7 4 4 4 9 5\n3 4 4 6 1 10 2 2 5 8 7 7 7 7 6\n10 9 3 6 8 6 1 9 5 4 7 10 7 1 8\n3 3 4 9 8 6 10 2 9 5 9 5 3 7 3\n1 8 1 3 4 8 10 4 8 4 7 5 4 6 7\n3 10 9 6 8 8 1 8 9 9 4 9 5 6 5\n7 6 3 9 9 8 6 10 3 6 4 2 10 9 7",
"output": "361\n7 9 9 8"
},
{
"input": "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5",
"output": "159\n4 4 5 4"
},
{
"input": "13\n9 9 3 3 5 6 8 2 6 1 10 3 8\n10 4 9 2 10 3 5 10 10 7 10 7 3\n5 8 4 1 10 2 1 2 4 7 9 1 10\n6 3 10 10 10 1 3 10 4 4 2 10 4\n1 7 5 7 9 9 7 4 1 8 5 4 1\n10 10 9 2 2 6 4 1 5 5 1 9 4\n4 2 5 5 7 8 1 2 6 1 2 4 6\n5 1 10 8 1 1 9 1 2 10 6 7 2\n2 1 2 10 4 7 4 1 4 10 10 4 3\n7 7 5 1 2 1 1 4 8 2 4 8 2\n8 8 8 4 1 1 7 3 1 10 1 4 2\n4 5 1 10 8 8 8 4 10 9 4 10 4\n3 1 10 10 5 7 9 4 2 10 4 8 4",
"output": "280\n6 6 7 6"
},
{
"input": "9\n3 9 6 1 7 6 2 8 4\n5 4 1 1 7 2 7 4 10\n7 9 9 4 6 2 7 2 8\n5 7 7 4 9 5 9 1 3\n7 3 10 2 9 4 2 1 2\n5 8 7 4 6 6 2 2 3\n4 8 4 3 4 2 1 8 10\n5 8 2 8 4 4 7 5 4\n2 8 7 4 3 6 10 8 1",
"output": "181\n5 4 6 4"
}
] | 1,606,101,427 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 3,000 | 33,792,000 | import sys
input = sys.stdin.readline
for _ in range(1):
n=int(input())
arr=[]
d1,d2={},{}
for _ in range(n):
temp=[int(x) for x in input().split()]
arr.append(temp)
for i in range(n):
if _-i in d1:
d1[_-i]+=temp[i]
else:
d1[_-i]=temp[i]
if _+i in d2:
d2[i+_]+=temp[i]
else:
d2[i+_]=temp[i]
ans1,ans2=[0,0,0],[0,0,0]
for i in range(n):
for j in range(n):
if (i+j)%2:
if d2[i+j]+d1[i-j]-arr[i][j]>=ans2[0]:
ans2[0]=d2[i+j]+d1[i-j]-arr[i][j]
ans2[1]=i
ans2[2]=j
else:
if d2[i+j]+d1[i-j]-arr[i][j]>=ans1[0]:
ans1[0]=d2[i+j]+d1[i-j]-arr[i][j]
ans1[1]=i
ans1[2]=j
#print(d1,d2)
print(ans1[0]+ans2[0])
print(ans1[1]+1,ans1[2]+1,ans2[1]+1,ans2[2]+1) | Title: Gargari and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard.
Output Specification:
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right.
If there are several optimal solutions, you can print any of them.
Demo Input:
['4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n']
Demo Output:
['12\n2 2 3 2\n']
Note:
none | ```python
import sys
input = sys.stdin.readline
for _ in range(1):
n=int(input())
arr=[]
d1,d2={},{}
for _ in range(n):
temp=[int(x) for x in input().split()]
arr.append(temp)
for i in range(n):
if _-i in d1:
d1[_-i]+=temp[i]
else:
d1[_-i]=temp[i]
if _+i in d2:
d2[i+_]+=temp[i]
else:
d2[i+_]=temp[i]
ans1,ans2=[0,0,0],[0,0,0]
for i in range(n):
for j in range(n):
if (i+j)%2:
if d2[i+j]+d1[i-j]-arr[i][j]>=ans2[0]:
ans2[0]=d2[i+j]+d1[i-j]-arr[i][j]
ans2[1]=i
ans2[2]=j
else:
if d2[i+j]+d1[i-j]-arr[i][j]>=ans1[0]:
ans1[0]=d2[i+j]+d1[i-j]-arr[i][j]
ans1[1]=i
ans1[2]=j
#print(d1,d2)
print(ans1[0]+ans2[0])
print(ans1[1]+1,ans1[2]+1,ans2[1]+1,ans2[2]+1)
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,688,901,367 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a = input("")
m = input("")
n = input("")
if m % a == 0:
k = m/a
else:
k = 1 + m/a
if n % a == 0:
j = n/a
else:
j = 1 + n/a
print(j*k) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
a = input("")
m = input("")
n = input("")
if m % a == 0:
k = m/a
else:
k = 1 + m/a
if n % a == 0:
j = n/a
else:
j = 1 + n/a
print(j*k)
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j*<==<=*y**j*. Here |*a*| denotes the length of the string *a*. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
The teacher gave Anna and Maria homework. She gave them a string of length *n*. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the *k*-th string from the list. Help Anna and Maria do the homework. | The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105). | Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes). | [
"aa\n2\n",
"abc\n5\n",
"abab\n7\n"
] | [
"a\n",
"bc\n",
"b\n"
] | In the second sample before string "bc" follow strings "a", "ab", "abc", "b". | 0 | [
{
"input": "aa\n2",
"output": "a"
},
{
"input": "abc\n5",
"output": "bc"
},
{
"input": "abab\n7",
"output": "b"
},
{
"input": "codeforces\n1",
"output": "c"
},
{
"input": "cccc\n8",
"output": "ccc"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n27",
"output": "b"
},
{
"input": "cba\n6",
"output": "cba"
},
{
"input": "z\n100000",
"output": "No such line."
},
{
"input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n17416",
"output": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
},
{
"input": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n32912",
"output": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
},
{
"input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n84480",
"output": "No such line."
},
{
"input": "llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\n83252",
"output": "No such line."
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n18883",
"output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
},
{
"input": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n14594",
"output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n87315",
"output": "No such line."
},
{
"input": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n27016",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n9184",
"output": "ssssssssssssssssssssssssssss"
},
{
"input": "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n99590",
"output": "No such line."
},
{
"input": "aaaaaaaaaa\n90",
"output": "No such line."
}
] | 1,671,503,815 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 15,052,800 | from queue import PriorityQueue
string = input()
kth_smallest = int(input())
length = len(string)
if kth_smallest > length * (length + 1) / 2:
print("No such line.")
quit()
char_indices = [(string[i], i) for i in range(length)]
pq = PriorityQueue()
for char_index in char_indices:
pq.put(char_index)
while kth_smallest:
kth_smallest -= 1
smallest, index = pq.get()
if kth_smallest == 0:
print(smallest)
else:
if index < length - 1:
pq.put((smallest + string[index + 1], index + 1))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j*<==<=*y**j*. Here |*a*| denotes the length of the string *a*. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
The teacher gave Anna and Maria homework. She gave them a string of length *n*. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the *k*-th string from the list. Help Anna and Maria do the homework.
Input Specification:
The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105).
Output Specification:
Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes).
Demo Input:
['aa\n2\n', 'abc\n5\n', 'abab\n7\n']
Demo Output:
['a\n', 'bc\n', 'b\n']
Note:
In the second sample before string "bc" follow strings "a", "ab", "abc", "b". | ```python
from queue import PriorityQueue
string = input()
kth_smallest = int(input())
length = len(string)
if kth_smallest > length * (length + 1) / 2:
print("No such line.")
quit()
char_indices = [(string[i], i) for i in range(length)]
pq = PriorityQueue()
for char_index in char_indices:
pq.put(char_index)
while kth_smallest:
kth_smallest -= 1
smallest, index = pq.get()
if kth_smallest == 0:
print(smallest)
else:
if index < length - 1:
pq.put((smallest + string[index + 1], index + 1))
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,570,809,609 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n=int(input())
l=[int(x) for x in input().split()]
e=0
o=0
for i in range(0,3):
if(l[i]%2==0):
e+=1
else:
o+=1
if(e>o):
for i in range(0,n):
if(l[i]%2!=0):
print(i+1)
break
else:
for i in range(0,n):
if(l[i]%2==0):
print(i+1)
break | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n=int(input())
l=[int(x) for x in input().split()]
e=0
o=0
for i in range(0,3):
if(l[i]%2==0):
e+=1
else:
o+=1
if(e>o):
for i in range(0,n):
if(l[i]%2!=0):
print(i+1)
break
else:
for i in range(0,n):
if(l[i]%2==0):
print(i+1)
break
``` | 3.9455 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,697,787,614 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | n = int(input())
pi = list(map(int, input().split()))
total_fraction = sum(pi)
average_fraction = total_fraction / n
print("{:.12f}".format(average_fraction))
| Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | ```python
n = int(input())
pi = list(map(int, input().split()))
total_fraction = sum(pi)
average_fraction = total_fraction / n
print("{:.12f}".format(average_fraction))
``` | 3 |
|
834 | A | The Useless Toy | PROGRAMMING | 900 | [
"implementation"
] | null | null | Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this. | There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position. | Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. | [
"^ >\n1\n",
"< ^\n3\n",
"^ v\n6\n"
] | [
"cw\n",
"ccw\n",
"undefined\n"
] | none | 500 | [
{
"input": "^ >\n1",
"output": "cw"
},
{
"input": "< ^\n3",
"output": "ccw"
},
{
"input": "^ v\n6",
"output": "undefined"
},
{
"input": "^ >\n999999999",
"output": "ccw"
},
{
"input": "> v\n1",
"output": "cw"
},
{
"input": "v <\n1",
"output": "cw"
},
{
"input": "< ^\n1",
"output": "cw"
},
{
"input": "v <\n422435957",
"output": "cw"
},
{
"input": "v >\n139018901",
"output": "ccw"
},
{
"input": "v ^\n571728018",
"output": "undefined"
},
{
"input": "^ ^\n0",
"output": "undefined"
},
{
"input": "< >\n2",
"output": "undefined"
},
{
"input": "> >\n1000000000",
"output": "undefined"
},
{
"input": "v v\n8",
"output": "undefined"
},
{
"input": "< <\n1568",
"output": "undefined"
},
{
"input": "^ v\n2",
"output": "undefined"
},
{
"input": "^ <\n1",
"output": "ccw"
},
{
"input": "< v\n1",
"output": "ccw"
},
{
"input": "v >\n1",
"output": "ccw"
},
{
"input": "> ^\n1",
"output": "ccw"
},
{
"input": "v <\n422435957",
"output": "cw"
},
{
"input": "v v\n927162384",
"output": "undefined"
},
{
"input": "v ^\n571728018",
"output": "undefined"
},
{
"input": "^ <\n467441155",
"output": "cw"
},
{
"input": "^ >\n822875521",
"output": "cw"
},
{
"input": "^ <\n821690113",
"output": "ccw"
},
{
"input": "^ <\n171288453",
"output": "ccw"
},
{
"input": "^ <\n110821381",
"output": "ccw"
},
{
"input": "^ ^\n539580280",
"output": "undefined"
},
{
"input": "^ >\n861895563",
"output": "ccw"
},
{
"input": "v v\n4",
"output": "undefined"
},
{
"input": "^ ^\n4",
"output": "undefined"
},
{
"input": "> >\n4",
"output": "undefined"
},
{
"input": "< <\n8",
"output": "undefined"
},
{
"input": "v v\n0",
"output": "undefined"
},
{
"input": "^ <\n11",
"output": "cw"
},
{
"input": "< <\n4",
"output": "undefined"
},
{
"input": "< <\n0",
"output": "undefined"
},
{
"input": "< v\n3",
"output": "cw"
},
{
"input": "^ <\n3",
"output": "cw"
},
{
"input": "^ <\n7",
"output": "cw"
},
{
"input": "< >\n6",
"output": "undefined"
},
{
"input": "v >\n3",
"output": "cw"
},
{
"input": "> >\n300",
"output": "undefined"
},
{
"input": "> >\n0",
"output": "undefined"
},
{
"input": "v <\n3",
"output": "ccw"
},
{
"input": "> >\n12",
"output": "undefined"
}
] | 1,598,663,806 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | alph = "v<^>"
pos = input()
n = int(input())
if n % 2 == 0:
print("undefined")
else:
if (alph.find(pos[0]) - alph.find(pos[2])) % 4 == n:
print("ccw")
else:
print("cw")
| Title: The Useless Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input Specification:
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
Output Specification:
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
Demo Input:
['^ >\n1\n', '< ^\n3\n', '^ v\n6\n']
Demo Output:
['cw\n', 'ccw\n', 'undefined\n']
Note:
none | ```python
alph = "v<^>"
pos = input()
n = int(input())
if n % 2 == 0:
print("undefined")
else:
if (alph.find(pos[0]) - alph.find(pos[2])) % 4 == n:
print("ccw")
else:
print("cw")
``` | 0 |
|
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500",
"output": "6"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39",
"output": "6"
},
{
"input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064",
"output": "5"
},
{
"input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697",
"output": "21"
}
] | 1,698,738,447 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | # -*- coding: utf-8 -*-
#2300090102 石芯洁
n=int(input())
ti=list(map(int,input().split()))
ti.sort()
not_disappointed=[]
for t in range(len(ti)):
if ti[t] >= sum(ti[:t]):
not_disappointed.append(ti[t])
print(len(not_disappointed))
| Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Output Specification:
Print a single number — the maximum number of not disappointed people in the queue.
Demo Input:
['5\n15 2 1 5 3\n']
Demo Output:
['4\n']
Note:
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | ```python
# -*- coding: utf-8 -*-
#2300090102 石芯洁
n=int(input())
ti=list(map(int,input().split()))
ti.sort()
not_disappointed=[]
for t in range(len(ti)):
if ti[t] >= sum(ti[:t]):
not_disappointed.append(ti[t])
print(len(not_disappointed))
``` | 0 |
|
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
"output": "3"
},
{
"input": "10 10\n1 10 1 10 1 1 7 8 6 7",
"output": "8"
},
{
"input": "100 100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "63"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "10 2\n2 2 1 1 1 1 1 2 1 2",
"output": "8"
},
{
"input": "10 3\n1 3 1 1 3 2 2 2 3 3",
"output": "9"
},
{
"input": "10 4\n2 1 1 1 3 4 4 4 1 2",
"output": "6"
},
{
"input": "10 5\n2 2 3 4 4 1 5 3 1 2",
"output": "7"
},
{
"input": "100 3\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2",
"output": "83"
},
{
"input": "100 7\n4 7 4 7 7 4 7 3 5 6 3 5 4 3 7 2 7 2 4 1 6 3 3 7 4 4 5 4 3 6 4 3 2 2 1 4 4 1 7 3 7 7 1 3 1 5 4 1 5 3 5 2 2 1 5 5 1 5 2 7 5 5 1 5 5 4 6 5 1 3 5 6 7 4 1 3 3 4 3 2 7 6 5 7 2 7 1 1 2 2 3 1 3 7 1 3 2 1 1 7",
"output": "71"
},
{
"input": "100 10\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "64"
},
{
"input": "100 15\n3 12 8 3 11 14 12 14 1 11 13 3 5 13 4 14 2 11 7 8 12 9 15 7 15 1 4 11 6 12 1 3 8 13 1 8 14 4 3 14 1 3 1 6 10 15 13 11 12 1 14 13 11 14 11 3 12 7 3 15 14 4 5 6 5 14 7 14 6 2 6 12 6 13 13 1 9 13 15 11 6 3 15 11 9 4 15 8 15 12 1 15 10 10 4 1 15 1 4 1",
"output": "71"
},
{
"input": "100 30\n7 14 22 16 11 13 7 29 20 19 22 6 12 16 1 8 27 21 22 3 15 27 20 12 4 19 1 26 26 22 25 17 29 25 16 29 29 28 16 26 25 14 16 20 5 21 5 15 19 13 17 21 17 19 23 13 1 25 6 30 16 19 12 10 28 8 15 13 14 24 19 30 12 19 22 1 3 14 16 3 20 26 15 19 9 10 19 27 2 16 10 22 15 13 19 3 24 9 8 13",
"output": "71"
},
{
"input": "100 40\n39 19 13 36 11 21 32 12 1 2 39 26 32 39 24 1 4 19 10 4 16 39 32 34 13 24 30 35 3 10 8 18 13 12 39 27 31 40 37 20 17 17 37 5 10 12 22 17 7 1 31 13 11 10 2 6 22 16 2 4 9 27 6 35 22 16 22 30 33 2 26 20 35 19 40 37 19 17 21 28 37 28 40 4 5 4 35 19 26 36 19 12 21 20 21 30 9 16 9 32",
"output": "65"
},
{
"input": "100 50\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1",
"output": "60"
},
{
"input": "100 60\n34 21 39 17 48 46 23 56 46 52 50 39 55 48 54 38 32 38 24 26 44 12 28 9 25 26 10 52 42 60 41 3 16 60 44 29 27 55 19 19 19 57 45 59 29 35 5 14 50 47 57 48 16 7 12 36 58 31 37 58 30 50 19 11 10 41 59 57 49 41 33 9 12 11 53 50 60 51 21 9 44 23 1 16 4 15 17 57 15 17 46 50 18 52 43 24 47 50 19 18",
"output": "74"
},
{
"input": "100 90\n74 65 49 41 3 79 61 83 50 40 13 57 90 14 62 77 36 10 3 5 5 40 50 75 32 26 3 71 79 54 88 50 46 20 42 59 30 36 83 86 60 62 82 68 62 80 18 65 28 28 81 74 62 33 61 35 33 83 90 72 6 6 51 4 22 20 29 10 8 3 84 69 12 17 24 16 12 64 80 74 68 59 1 59 15 59 37 58 79 83 51 56 81 14 37 45 19 31 61 90",
"output": "67"
},
{
"input": "100 99\n69 46 76 47 71 9 66 46 78 17 96 83 56 96 29 3 43 48 79 23 93 61 19 9 29 72 15 84 93 46 71 87 11 43 96 44 54 75 3 66 2 95 46 32 69 52 79 38 57 53 37 60 71 82 28 31 84 58 89 40 62 74 22 50 45 38 99 67 24 28 28 12 69 88 33 10 31 71 46 7 42 81 54 81 96 44 8 1 20 24 28 19 54 35 69 32 71 13 66 15",
"output": "68"
},
{
"input": "90 100\n25 52 88 89 36 17 57 64 66 11 89 61 54 92 48 51 18 42 44 92 6 14 67 100 16 21 17 88 85 73 33 11 94 84 56 72 4 80 90 78 96 5 62 70 54 70 94 80 10 91 100 89 98 87 69 74 88 63 53 79 38 94 89 52 21 82 67 79 100 81 2 40 30 69 34 15 12 33 87 52 95 18 51 30 15 39 30 99 46 84",
"output": "67"
},
{
"input": "5 100\n14 67 15 28 21",
"output": "2"
},
{
"input": "10 100\n2 17 53 94 95 57 36 47 68 48",
"output": "7"
},
{
"input": "1 100\n18",
"output": "1"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "30 100\n56 7 99 83 2 65 35 53 99 36 42 57 13 37 68 52 87 11 50 23 86 24 32 39 97 6 64 1 18 86",
"output": "18"
},
{
"input": "60 100\n18 75 43 88 45 43 20 59 59 79 62 39 53 21 28 46 54 53 97 81 18 15 2 95 84 9 36 70 30 76 17 19 83 40 45 32 31 70 23 14 44 35 79 84 97 96 99 60 3 73 64 83 6 12 67 86 70 89 18 61",
"output": "40"
},
{
"input": "1 73\n24",
"output": "1"
},
{
"input": "4 4\n1 4 4 4",
"output": "4"
},
{
"input": "2 6\n1 4",
"output": "1"
},
{
"input": "2 5\n5 5",
"output": "2"
}
] | 1,417,424,769 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 0 | from sys import stdin
def main():
n, m = map(int, stdin.readline().strip().split())
it = iter(map(int, stdin.readline().strip().split()))
try:
cnt = vol = 0
while True:
x = next(it)
if vol < x:
cnt += 1
vol = m
vol -= x
except StopIteration:
return cnt
print(main())
| Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*).
Output Specification:
Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside.
Demo Input:
['4 3\n2 3 2 1\n', '3 4\n1 2 1\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
from sys import stdin
def main():
n, m = map(int, stdin.readline().strip().split())
it = iter(map(int, stdin.readline().strip().split()))
try:
cnt = vol = 0
while True:
x = next(it)
if vol < x:
cnt += 1
vol = m
vol -= x
except StopIteration:
return cnt
print(main())
``` | 3 |
|
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,591,549,672 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 1,331,200 | a,b,n=map(int,input().split())
while n>0:
n=n-1
t=1
s=0
while t<=9:
if (10*a+t)%b==0:
s=1
a=10*a+t
break
t=t+1
if s==1:
print(a)
else:
print('-1')
| 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())
while n>0:
n=n-1
t=1
s=0
while t<=9:
if (10*a+t)%b==0:
s=1
a=10*a+t
break
t=t+1
if s==1:
print(a)
else:
print('-1')
``` | 0 |
|
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,679,064,842 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 154 | 1,843,200 | import sys
a= input()
c=0
while 1:
if len(a)==1:
break
a= str(sum(int(i) for i in a))
c+=1
print(c)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | ```python
import sys
a= input()
c=0
while 1:
if len(a)==1:
break
a= str(sum(int(i) for i in a))
c+=1
print(c)
``` | 3.958183 |
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{
"input": "16 112 50 114 68\n1 4 8 4 9\n19 11",
"output": "5178"
},
{
"input": "55 66 75 44 47\n6 0 6 6 10\n19 0",
"output": "6414"
},
{
"input": "47 11 88 5 110\n6 10 4 2 3\n10 6",
"output": "5188"
},
{
"input": "5 44 61 103 92\n9 0 10 4 8\n15 7",
"output": "4914"
},
{
"input": "115 53 96 62 110\n7 8 1 7 9\n7 16",
"output": "3416"
},
{
"input": "102 83 26 6 11\n3 4 1 8 3\n17 14",
"output": "6704"
},
{
"input": "36 102 73 101 19\n5 9 2 2 6\n4 13",
"output": "4292"
},
{
"input": "40 115 93 107 113\n5 7 2 6 8\n6 17",
"output": "2876"
},
{
"input": "53 34 53 107 81\n4 3 1 10 8\n7 7",
"output": "4324"
},
{
"input": "113 37 4 84 66\n2 0 10 3 0\n20 19",
"output": "6070"
},
{
"input": "10 53 101 62 1\n8 0 9 7 9\n0 11",
"output": "4032"
},
{
"input": "45 45 75 36 76\n6 2 2 0 0\n8 17",
"output": "5222"
},
{
"input": "47 16 44 78 111\n7 9 8 0 2\n1 19",
"output": "3288"
},
{
"input": "7 54 39 102 31\n6 0 2 10 1\n18 3",
"output": "6610"
},
{
"input": "0 46 86 72 40\n1 5 5 5 9\n6 5",
"output": "4924"
},
{
"input": "114 4 45 78 113\n0 4 8 10 2\n10 12",
"output": "4432"
},
{
"input": "56 56 96 105 107\n4 9 10 4 8\n2 1",
"output": "3104"
},
{
"input": "113 107 59 50 56\n3 7 10 6 3\n10 12",
"output": "4586"
},
{
"input": "96 104 9 94 84\n6 10 7 8 3\n14 11",
"output": "4754"
},
{
"input": "98 15 116 43 55\n4 3 0 9 3\n10 7",
"output": "5400"
},
{
"input": "0 26 99 108 35\n0 4 3 0 10\n9 5",
"output": "5388"
},
{
"input": "89 24 51 49 84\n5 6 2 2 9\n2 14",
"output": "4066"
},
{
"input": "57 51 76 45 96\n1 0 4 3 6\n12 15",
"output": "5156"
},
{
"input": "79 112 37 36 116\n2 8 4 7 5\n4 12",
"output": "3872"
},
{
"input": "71 42 60 20 7\n7 1 1 10 6\n1 7",
"output": "5242"
},
{
"input": "86 10 66 80 55\n0 2 5 10 5\n15 6",
"output": "5802"
},
{
"input": "66 109 22 22 62\n3 1 5 4 5\n10 5",
"output": "5854"
},
{
"input": "97 17 43 84 58\n2 8 3 8 6\n10 7",
"output": "5028"
},
{
"input": "109 83 5 114 104\n6 0 3 9 5\n5 2",
"output": "4386"
},
{
"input": "94 18 24 91 105\n2 0 7 10 3\n1 4",
"output": "4118"
},
{
"input": "64 17 86 59 45\n8 0 10 2 2\n4 4",
"output": "5144"
},
{
"input": "70 84 31 57 2\n7 0 0 2 7\n12 5",
"output": "6652"
},
{
"input": "98 118 117 86 4\n2 10 9 7 5\n11 15",
"output": "4476"
},
{
"input": "103 110 101 97 70\n4 2 1 0 5\n7 5",
"output": "4678"
},
{
"input": "78 96 6 97 62\n7 7 9 2 9\n10 3",
"output": "4868"
},
{
"input": "95 28 3 31 115\n1 9 0 7 3\n10 13",
"output": "5132"
},
{
"input": "45 17 116 58 3\n8 8 7 6 4\n3 19",
"output": "3992"
},
{
"input": "19 12 0 113 77\n3 0 10 9 2\n8 6",
"output": "5040"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0",
"output": "7500"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n20 0",
"output": "9500"
},
{
"input": "119 119 119 119 119\n10 10 10 10 10\n0 20",
"output": "1310"
},
{
"input": "0 0 0 0 0\n10 10 10 10 10\n0 20",
"output": "4150"
},
{
"input": "119 0 0 0 0\n10 0 0 0 0\n5 5",
"output": "7400"
},
{
"input": "0 119 0 0 0\n0 10 0 0 0\n5 5",
"output": "7050"
},
{
"input": "0 0 119 0 0\n0 0 10 0 0\n0 0",
"output": "6450"
},
{
"input": "0 0 0 119 0\n0 0 0 10 0\n5 5",
"output": "6350"
},
{
"input": "0 0 0 0 119\n0 0 0 0 10\n5 5",
"output": "6060"
},
{
"input": "119 0 0 0 0\n2 0 0 0 0\n5 5",
"output": "7412"
},
{
"input": "0 119 0 0 0\n0 2 0 0 0\n5 5",
"output": "7174"
},
{
"input": "0 0 119 0 0\n0 0 2 0 0\n5 5",
"output": "6936"
},
{
"input": "0 0 0 119 0\n0 0 0 2 0\n5 5",
"output": "6698"
},
{
"input": "0 0 0 0 119\n0 0 0 0 2\n5 5",
"output": "6460"
},
{
"input": "119 0 0 0 0\n0 0 0 0 0\n4 9",
"output": "7212"
}
] | 1,448,986,086 | 1,986 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 31 | 0 | def calc(x, m, w):
score = max(0.3*x, ((1 - m/250 )*x - 50*w));
return score;
m1, m2, m3, m4, m5 = map(int, input().split(" "))
w1, w2, w3, w4, w5 = map(int, input().split(" "))
h1, h2 = map(int, input().split(" "))
score = calc(500, m1, w1) + calc(1000, m2, w2) + calc(1500, m3, w3) + calc(2000, m4, w4) + calc(2500, m5, w5)
score += h1*100
score-=h2*50
print(score)
| Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
Input Specification:
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Output Specification:
Print a single integer, the value of Kevin's final score.
Demo Input:
['20 40 60 80 100\n0 1 2 3 4\n1 0\n', '119 119 119 119 119\n0 0 0 0 0\n10 0\n']
Demo Output:
['4900\n', '4930\n']
Note:
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | ```python
def calc(x, m, w):
score = max(0.3*x, ((1 - m/250 )*x - 50*w));
return score;
m1, m2, m3, m4, m5 = map(int, input().split(" "))
w1, w2, w3, w4, w5 = map(int, input().split(" "))
h1, h2 = map(int, input().split(" "))
score = calc(500, m1, w1) + calc(1000, m2, w2) + calc(1500, m3, w3) + calc(2000, m4, w4) + calc(2500, m5, w5)
score += h1*100
score-=h2*50
print(score)
``` | 0 |
|
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ghbdtn",
"output": "Just a legend"
},
{
"input": "a",
"output": "Just a legend"
},
{
"input": "aa",
"output": "Just a legend"
},
{
"input": "ab",
"output": "Just a legend"
},
{
"input": "aaa",
"output": "a"
},
{
"input": "aba",
"output": "Just a legend"
},
{
"input": "aab",
"output": "Just a legend"
},
{
"input": "abb",
"output": "Just a legend"
},
{
"input": "abc",
"output": "Just a legend"
},
{
"input": "aaabaabaaaaab",
"output": "Just a legend"
},
{
"input": "aabaaabaaaaab",
"output": "aab"
},
{
"input": "aaabaaaabab",
"output": "Just a legend"
},
{
"input": "abcabcabcabcabc",
"output": "abcabcabc"
},
{
"input": "aaaaabaaaa",
"output": "aaaa"
},
{
"input": "aaaabaaaaaaa",
"output": "aaaa"
},
{
"input": "ghghghgxghghghg",
"output": "ghghg"
},
{
"input": "kincenvizh",
"output": "Just a legend"
},
{
"input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw",
"output": "Just a legend"
},
{
"input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx",
"output": "Just a legend"
},
{
"input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb",
"output": "nfbdzgdlbjhrlvfryyjb"
},
{
"input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp",
"output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp"
},
{
"input": "abcazabca",
"output": "a"
}
] | 1,587,188,307 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | def lps(s):
n=len(s)
for i in range(n//2,0,-1):
pre=s[0:i]
suff=s[n-i:n]
if pre==suff:
return pre,i
return 0
s=str(input())
prefix,index=lps(s)
temp=s[index+1:len(s)-index]
if prefix in temp:
print(prefix)
else:
print("Just a legend")
| Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
Input Specification:
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output Specification:
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
Demo Input:
['fixprefixsuffix\n', 'abcdabc\n']
Demo Output:
['fix', 'Just a legend']
Note:
none | ```python
def lps(s):
n=len(s)
for i in range(n//2,0,-1):
pre=s[0:i]
suff=s[n-i:n]
if pre==suff:
return pre,i
return 0
s=str(input())
prefix,index=lps(s)
temp=s[index+1:len(s)-index]
if prefix in temp:
print(prefix)
else:
print("Just a legend")
``` | 0 |
|
290 | F | Greedy Petya | PROGRAMMING | 2,800 | [
"*special",
"dfs and similar",
"graphs",
"greedy"
] | null | null | Petya is an unexperienced programming contestant. Recently he has come across the following problem:
You are given a non-directed graph which consists of *n* nodes and *m* edges. Your task is to determine whether the graph contains a Hamiltonian path.
Petya wrote a quick bug-free code which he believes solves this problem. After that Petya decided to give this problem for April Fools Day contest. Unfortunately, Petya might have made a mistake, and it's quite possible that his algorithm is wrong. But this isn't a good excuse to leave the contest without submitting this problem, is it? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=20; 0<=≤<=*m*<=≤<=400). Next *m* lines contain pairs of integers *v**i*,<=*u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*). | Follow the format of Petya's code output. | [
"2 3\n1 2\n2 1\n1 1\n",
"3 0\n",
"10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | none | 0 | [] | 1,664,157,082 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | import random as r
a=r.randint(2,3)
if(a==2):
print("Yes")
else:
print("No") | Title: Greedy Petya
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is an unexperienced programming contestant. Recently he has come across the following problem:
You are given a non-directed graph which consists of *n* nodes and *m* edges. Your task is to determine whether the graph contains a Hamiltonian path.
Petya wrote a quick bug-free code which he believes solves this problem. After that Petya decided to give this problem for April Fools Day contest. Unfortunately, Petya might have made a mistake, and it's quite possible that his algorithm is wrong. But this isn't a good excuse to leave the contest without submitting this problem, is it?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=20; 0<=≤<=*m*<=≤<=400). Next *m* lines contain pairs of integers *v**i*,<=*u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*).
Output Specification:
Follow the format of Petya's code output.
Demo Input:
['2 3\n1 2\n2 1\n1 1\n', '3 0\n', '10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
none | ```python
import random as r
a=r.randint(2,3)
if(a==2):
print("Yes")
else:
print("No")
``` | 0 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,696,088,242 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 159,539,200 | def even_odd():
n, k = map(int, input().split())
arrEven=[]
arrOdd=[]
for x in range(n+1):
if not x:
continue
if x%2==0:
arrEven.append(x)
else:
arrOdd.append(x)
totAll = [*arrOdd, *arrEven]
print(totAll[k-1])
even_odd() | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
def even_odd():
n, k = map(int, input().split())
arrEven=[]
arrOdd=[]
for x in range(n+1):
if not x:
continue
if x%2==0:
arrEven.append(x)
else:
arrOdd.append(x)
totAll = [*arrOdd, *arrEven]
print(totAll[k-1])
even_odd()
``` | 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,589,285,226 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 6,656,000 | n = int(input())
m, o = [], []
for i in range(n):
l = list(map(int, input().split()))
m.append(l)
for i in range(3):
tot = 0
for j in range(n):
tot += m[j][i]
o.append(tot)
if '0' not in o == 0: print("NO")
else: print("YES") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
m, o = [], []
for i in range(n):
l = list(map(int, input().split()))
m.append(l)
for i in range(3):
tot = 0
for j in range(n):
tot += m[j][i]
o.append(tot)
if '0' not in o == 0: print("NO")
else: print("YES")
``` | 0 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,427,062,242 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | word = input()
bword = input()
n = len(word) if len(word) < len(bword) else len(bword)
good = True if len(word) == len(bword) else False
for i in range(n):
if word[i] != bword[n - 1 - i]:
good = False
print("YES") if good else print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
word = input()
bword = input()
n = len(word) if len(word) < len(bword) else len(bword)
good = True if len(word) == len(bword) else False
for i in range(n):
if word[i] != bword[n - 1 - i]:
good = False
print("YES") if good else print("NO")
``` | 3.969 |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,647,023,412 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 77 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
l,r = [int(item) for item in input().split(" ")]
if(r-l<2):
print(-1)
elif(r-l>2):
print(l+1,l+2,l+3)
elif(l%2==0):
print(l,l+1,l+2)
else:
print(-1)
if __name__ == '__main__':
main() | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
l,r = [int(item) for item in input().split(" ")]
if(r-l<2):
print(-1)
elif(r-l>2):
print(l+1,l+2,l+3)
elif(l%2==0):
print(l,l+1,l+2)
else:
print(-1)
if __name__ == '__main__':
main()
``` | 0 |
|
437 | C | The Child and Toy | PROGRAMMING | 1,400 | [
"graphs",
"greedy",
"sortings"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1<=+<=*v**f*2<=+<=...<=+<=*v**f**k* energy for removing part *i* where *f*1,<=*f*2,<=...,<=*f**k* are the parts that are directly connected to the *i*-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*).
Consider all the parts are numbered from 1 to *n*. | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | 1,500 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
"output": "0"
},
{
"input": "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5",
"output": "4"
},
{
"input": "10 30\n3 6 17 15 13 15 6 12 9 1\n3 8\n1 10\n4 7\n1 7\n3 7\n2 9\n8 10\n3 1\n3 4\n8 6\n10 3\n3 9\n2 3\n10 4\n2 10\n5 8\n9 5\n6 1\n2 1\n7 2\n7 6\n7 10\n4 8\n5 6\n3 6\n4 1\n8 9\n7 9\n4 2\n5 10",
"output": "188"
},
{
"input": "3 3\n1 1 1\n1 2\n2 3\n3 1",
"output": "3"
}
] | 1,560,566,082 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 0 | n, m = map(int, input().split())
x = list(map(int, input().split()))
num = 0
for i in range(m):
a, b = map(int, input().split())
a, b = a - 1, b - 1
num += min(x[a], x[b])
print(num)
| Title: The Child and Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1<=+<=*v**f*2<=+<=...<=+<=*v**f**k* energy for removing part *i* where *f*1,<=*f*2,<=...,<=*f**k* are the parts that are directly connected to the *i*-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*).
Consider all the parts are numbered from 1 to *n*.
Output Specification:
Output the minimum total energy the child should spend to remove all *n* parts of the toy.
Demo Input:
['4 3\n10 20 30 40\n1 4\n1 2\n2 3\n', '4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n', '7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n']
Demo Output:
['40\n', '400\n', '160\n']
Note:
One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | ```python
n, m = map(int, input().split())
x = list(map(int, input().split()))
num = 0
for i in range(m):
a, b = map(int, input().split())
a, b = a - 1, b - 1
num += min(x[a], x[b])
print(num)
``` | 3 |
|
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,695,756,862 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 5,632,000 | a = input()
print(a) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
a = input()
print(a)
``` | 0 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,412,521,042 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | A = []
def plz_del(x):
for i in range(len(A)):
if A[i] == x:
A[i] = -1
for i in input().split(' '):
A.append(int(i))
ok = False
for i in range(len(A)):
if A.count(i) >= 4:
plz_del(i)
ok = True
if ok:
e1 = -1
e2 = -1
for i in A:
if i != -1:
if e1 == -1:
e1 = i
else:
e2 = i
if e1 == e2:
print("Elephant")
else:
print("Bear")
else:
print("Alien") | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
A = []
def plz_del(x):
for i in range(len(A)):
if A[i] == x:
A[i] = -1
for i in input().split(' '):
A.append(int(i))
ok = False
for i in range(len(A)):
if A.count(i) >= 4:
plz_del(i)
ok = True
if ok:
e1 = -1
e2 = -1
for i in A:
if i != -1:
if e1 == -1:
e1 = i
else:
e2 = i
if e1 == e2:
print("Elephant")
else:
print("Bear")
else:
print("Alien")
``` | 0 |
|
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length. | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output": "YES"
},
{
"input": "princeofpersia\n1",
"output": "NO"
},
{
"input": "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqththlrdwnyklbrxallihyvasunlvrxdemnfyjzfkivqsqrdizpcbjecmxmcyvapirlgxaifyrodbwhx\n1",
"output": "YES"
},
{
"input": "yfhqnbzaqeqmcvtsbcdn\n456",
"output": "NO"
},
{
"input": "lgsdfiforlqrohhjyzrigewkigiiffvbyrapzmjvtkklndeyuqpuukajgtguhlarjdqlxksyekbjgrmhuyiqdlzjqqzlxufffpelyptodwhvkfbalxbufrlcsjgxmfxeqsszqghcustqrqjljattgvzynyvfbjgbuynbcguqtyfowgtcbbaywvcrgzrulqpghwoflutswu\n584",
"output": "NO"
},
{
"input": "awlrhmxxivqbntvtapwkdkunamcqoerfncfmookhdnuxtttlxmejojpwbdyxirdsjippzjhdrpjepremruczbedxrjpodlyyldopjrxdebzcurmerpejprdhjzppijsdrixydbwpjojemxltttxundhkoomfcnfreoqcmanukdkwpatvtnbqvixxmhrlwa\n1",
"output": "YES"
},
{
"input": "kafzpsglcpzludxojtdhzynpbekzssvhzizfrboxbhqvojiqtjitrackqccxgenwwnegxccqkcartijtqijovqhbxobrfzizhvsszkebpnyzhdtjoxdulzpclgspzfakvcbbjejeubvrrzlvjjgrcprntbyuakoxowoybbxgdugjffgbtfwrfiobifrshyaqqayhsrfiboifrwftbgffjgudgxbbyowoxokauybtnrpcrgjjvlzrrvbuejejbbcv\n2",
"output": "YES"
},
{
"input": "zieqwmmbrtoxysvavwdemmdeatfrolsqvvlgphhhmojjfxfurtuiqdiilhlcwwqedlhblrzmvuoaczcwrqzyymiggpvbpkycibsvkhytrzhguksxyykkkvfljbbnjblylftmqxkojithwsegzsaexlpuicexbdzpwesrkzbqltxhifwqcehzsjgsqbwkujvjbjpqxdpmlimsusumizizpyigmkxwuberthdghnepyrxzvvidxeafwylegschhtywvqsxuqmsddhkzgkdiekodqpnftdyhnpicsnbhfxemxllvaurkmjvtrmqkulerxtaolmokiqqvqgechkqxmendpmgxwiaffcajmqjmvrwryzxujmiasuqtosuisiclnv\n8",
"output": "NO"
},
{
"input": "syghzncbi\n829",
"output": "NO"
},
{
"input": "ljpdpstntznciejqqtpysskztdfawuncqzwwfefrfsihyrdopwawowshquqnjhesxszuywezpebpzhtopgngrnqgwnoqhyrykojguybvdbjpfpmvkxscocywzsxcivysfrrzsonayztzzuybrkiombhqcfkszyscykzistiobrpavezedgobowjszfadcccmxyqehmkgywiwxffibzetb\n137",
"output": "NO"
},
{
"input": "eytuqriplfczwsqlsnjetfpzehzvzayickkbnfqddaisfpasvigwtnvbybwultsgrtjbaebktvubwofysgidpufzteuhuaaqkhmhguockoczlrmlrrzouvqtwbcchxxiydbohnvrmtqjzhkfmvdulojhdvgwudvidpausvfujkjprxsobliuauxleqvsmz\n253",
"output": "NO"
},
{
"input": "xkaqgwabuilhuqwhnrdtyattmqcjfbiqodjlwzgcyvghqncklbhnlmagvjvwysrfryrlmclninogumjfmyenkmydlmifxpkvlaapgnfarejaowftxxztshsesjtsgommaeslrhronruqdurvjesydrzmxirmxumrcqezznqltngsgdcthivdnjnshjfujtiqsltpttgbljfcbqsfwbzokciqlavrthgaqbzikpwwsebzwddlvdwrmztwmhcxdinwlbklwmteeybbdbzevfbsrtldapulwgusuvnreiflkytonzmervyrlbqhzapgxepwauaiwygpxarfeyqhimzlxntjuaaigeisgrvwgbhqemqetzyallzaoqprhzpjibkutgwrodruqu\n857",
"output": "NO"
},
{
"input": "rbehjxpblnzfgeebpkvzznwtzszghjuuxovreapmwehqyjymrkmksffbdpbdyegulabsmjiykeeqtuvqqyxlitpxjdpwmqtlmudqsksgwqekvwfjdsggzajcpsyserkctpbajgzdbiqaekfaepnecezdzamqszpwfvhlannszgaiewvcdnnvzhblmuzjtqeyjcqjqoxatavavokyxokuxwuqueskktxnxraihnqovrfykpzsyjmrhqsvbobzsnfqwvdwatvjxaubtiwhgvrqwjhgfnauqegqmcwnaruinplmtmxhvohhqgvcatsdqiwkvslhqzqevdgdhpijjevuyuitnixdjhwlmjsstmugownjdhvxueg\n677",
"output": "NO"
},
{
"input": "a\n3",
"output": "NO"
},
{
"input": "aa\n2",
"output": "YES"
},
{
"input": "abcaabca\n2",
"output": "NO"
},
{
"input": "aaaaaaaaab\n5",
"output": "NO"
},
{
"input": "aabbb\n3",
"output": "NO"
},
{
"input": "abcde\n5",
"output": "YES"
},
{
"input": "aabc\n2",
"output": "NO"
},
{
"input": "aabcaa\n3",
"output": "NO"
}
] | 1,432,666,846 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def polindrom(word):
if word[0:int(len(word)/2)] == word[-1:int((len(word) - 1)/2 ):-1]:
return True
return False
string = input()
k = int(input())
len_palindrom = int(len(string)/k)
words = []
notfound = False
for i in range(k):
words.append(string[len_palindrom * i:(i+1)*len_palindrom])
for i in range(k):
if not polindrom(words[i]):
print ('NO')
notfound = True
break
if not notfound:
print ('YES')
| Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length.
Input Specification:
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Output Specification:
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
Demo Input:
['saba\n2\n', 'saddastavvat\n2\n']
Demo Output:
['NO\n', 'YES\n']
Note:
Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | ```python
def polindrom(word):
if word[0:int(len(word)/2)] == word[-1:int((len(word) - 1)/2 ):-1]:
return True
return False
string = input()
k = int(input())
len_palindrom = int(len(string)/k)
words = []
notfound = False
for i in range(k):
words.append(string[len_palindrom * i:(i+1)*len_palindrom])
for i in range(k):
if not polindrom(words[i]):
print ('NO')
notfound = True
break
if not notfound:
print ('YES')
``` | 0 |
|
1,003 | B | Binary String Constructing | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists.
For example, for the string "01010" there are four indices $i$ such that $1 \le i < n$ and $s_i \ne s_{i + 1}$ ($i = 1, 2, 3, 4$). For the string "111001" there are two such indices $i$ ($i = 3, 5$).
Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1. | The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x < a + b)$. | Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists. | [
"2 2 1\n",
"3 3 3\n",
"5 3 6\n"
] | [
"1100\n",
"101100\n",
"01010100\n"
] | All possible answers for the first example:
- 1100; - 0011.
All possible answers for the second example:
- 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011. | 0 | [
{
"input": "2 2 1",
"output": "1100"
},
{
"input": "3 3 3",
"output": "101100"
},
{
"input": "5 3 6",
"output": "01010100"
},
{
"input": "100 1 2",
"output": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 1 1",
"output": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
},
{
"input": "1 100 1",
"output": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 100 2",
"output": "10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "7 8 7",
"output": "101010111110000"
},
{
"input": "100 100 199",
"output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010"
},
{
"input": "50 47 18",
"output": "0101010101010101011111111111111111111111111111111111111100000000000000000000000000000000000000000"
},
{
"input": "2 3 3",
"output": "10110"
},
{
"input": "100 100 100",
"output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111"
},
{
"input": "2 2 2",
"output": "1001"
},
{
"input": "3 4 6",
"output": "1010101"
},
{
"input": "1 1 1",
"output": "10"
},
{
"input": "5 6 2",
"output": "10000011111"
},
{
"input": "5 4 2",
"output": "011110000"
},
{
"input": "2 3 4",
"output": "10101"
},
{
"input": "3 3 2",
"output": "100011"
},
{
"input": "100 99 100",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000"
},
{
"input": "3 2 1",
"output": "00011"
},
{
"input": "12 74 22",
"output": "10101010101010101010100111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "6 84 12",
"output": "101010101010111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "3 2 4",
"output": "01010"
},
{
"input": "66 11 22",
"output": "01010101010101010101010000000000000000000000000000000000000000000000000000000"
},
{
"input": "83 83 83",
"output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010111111111111111111111111111111111111111111000000000000000000000000000000000000000000"
},
{
"input": "9 89 18",
"output": "10101010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "2 1 2",
"output": "010"
},
{
"input": "52 12 17",
"output": "0101010101010101000000000000000000000000000000000000000000001111"
},
{
"input": "55 56 110",
"output": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"input": "67 81 40",
"output": "1010101010101010101010101010101010101010000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "15 26 24",
"output": "10101010101010101010101000011111111111111"
},
{
"input": "7 99 14",
"output": "1010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "99 41 17",
"output": "01010101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111"
},
{
"input": "91 87 11",
"output": "0101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "73 61 122",
"output": "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101000000000000"
},
{
"input": "10 40 1",
"output": "11111111111111111111111111111111111111110000000000"
},
{
"input": "10 6 10",
"output": "0101010101100000"
},
{
"input": "78 67 117",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000111111111"
},
{
"input": "3 5 6",
"output": "10101011"
},
{
"input": "30 34 44",
"output": "1010101010101010101010101010101010101010101000000000111111111111"
},
{
"input": "2 15 4",
"output": "10101111111111111"
},
{
"input": "4 9 6",
"output": "1010100111111"
}
] | 1,595,526,104 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 327 | 30,208,000 | import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque
def r():
return int(input())
def rm():
return map(int,input().split())
def rl():
return list(map(int,input().split()))
'''b Binary string construction'''
a,b,x=rm()
c=(x+1)//2
s='01'*c
a-=c;b-=c
print('0'*a+s+'1'*b+'0'*(1 if x%2==0 else 0)) | Title: Binary String Constructing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists.
For example, for the string "01010" there are four indices $i$ such that $1 \le i < n$ and $s_i \ne s_{i + 1}$ ($i = 1, 2, 3, 4$). For the string "111001" there are two such indices $i$ ($i = 3, 5$).
Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.
Input Specification:
The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x < a + b)$.
Output Specification:
Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.
Demo Input:
['2 2 1\n', '3 3 3\n', '5 3 6\n']
Demo Output:
['1100\n', '101100\n', '01010100\n']
Note:
All possible answers for the first example:
- 1100; - 0011.
All possible answers for the second example:
- 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011. | ```python
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque
def r():
return int(input())
def rm():
return map(int,input().split())
def rl():
return list(map(int,input().split()))
'''b Binary string construction'''
a,b,x=rm()
c=(x+1)//2
s='01'*c
a-=c;b-=c
print('0'*a+s+'1'*b+'0'*(1 if x%2==0 else 0))
``` | 0 |
|
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron",
"output": "256"
},
{
"input": "1\nTetrahedron",
"output": "4"
},
{
"input": "1\nCube",
"output": "6"
},
{
"input": "1\nOctahedron",
"output": "8"
},
{
"input": "1\nDodecahedron",
"output": "12"
},
{
"input": "1\nIcosahedron",
"output": "20"
},
{
"input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron",
"output": "340"
}
] | 1,676,892,655 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 265 | 0 | n = int(input())
result = 0
a = {
"Tetrahedron": 4,
"Cube": 6,
"Octahedron": 8,
"Dodecahedron": 12,
"Icosahedron": 20,
}
for _ in range(n):
s = input()
result += a[s]
print(result)
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output Specification:
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
Demo Input:
['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n']
Demo Output:
['42\n', '28\n']
Note:
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | ```python
n = int(input())
result = 0
a = {
"Tetrahedron": 4,
"Cube": 6,
"Octahedron": 8,
"Dodecahedron": 12,
"Icosahedron": 20,
}
for _ in range(n):
s = input()
result += a[s]
print(result)
``` | 3 |
|
300 | B | Coach | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive.
Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team.
Help the coach and divide the teams the way he wants. | The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team.
It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*,<=*b**i* occurs in the input at most once. | If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team.
If there are multiple answers, you are allowed to print any of them. | [
"3 0\n",
"6 4\n1 2\n2 3\n3 4\n5 6\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"3 2 1 \n",
"-1\n",
"3 2 1 \n"
] | none | 1,000 | [
{
"input": "3 0",
"output": "3 2 1 "
},
{
"input": "6 4\n1 2\n2 3\n3 4\n5 6",
"output": "-1"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "3 2 1 "
},
{
"input": "6 3\n1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "15 9\n1 4\n1 6\n2 7\n2 11\n4 6\n5 12\n7 11\n9 14\n13 15",
"output": "6 4 1 \n11 7 2 \n12 5 3 \n14 9 8 \n15 13 10 "
},
{
"input": "3 1\n1 3",
"output": "3 2 1 "
},
{
"input": "15 13\n1 9\n1 11\n2 7\n2 12\n3 8\n3 15\n4 10\n5 6\n5 14\n6 14\n7 12\n8 15\n9 11",
"output": "11 9 1 \n12 7 2 \n14 6 5 \n15 8 3 \n13 10 4 "
},
{
"input": "36 27\n1 34\n2 18\n2 20\n3 9\n3 21\n4 5\n4 25\n5 25\n6 13\n6 22\n8 23\n8 31\n9 21\n10 14\n11 17\n11 19\n13 22\n15 24\n15 26\n17 19\n18 20\n23 31\n24 26\n28 29\n28 33\n29 33\n32 36",
"output": "19 17 11 \n20 18 2 \n21 9 3 \n22 13 6 \n25 5 4 \n26 24 15 \n31 23 8 \n33 29 28 \n14 10 7 \n34 12 1 \n36 32 16 \n35 30 27 "
},
{
"input": "18 12\n1 10\n2 4\n2 8\n3 15\n3 18\n4 8\n5 6\n9 13\n12 14\n12 16\n14 16\n15 18",
"output": "8 4 2 \n16 14 12 \n18 15 3 \n7 6 5 \n11 10 1 \n17 13 9 "
},
{
"input": "39 27\n1 2\n1 25\n2 25\n4 16\n5 22\n5 28\n6 7\n6 26\n7 26\n8 24\n10 31\n10 38\n11 17\n11 21\n12 35\n12 37\n13 34\n17 21\n18 23\n19 39\n22 28\n27 29\n27 36\n29 36\n31 38\n32 33\n35 37",
"output": "21 17 11 \n25 2 1 \n26 7 6 \n28 22 5 \n36 29 27 \n37 35 12 \n38 31 10 \n16 4 3 \n23 18 9 \n24 14 8 \n33 32 15 \n34 20 13 \n39 30 19 "
},
{
"input": "12 7\n1 2\n4 5\n6 12\n7 8\n9 10\n9 11\n10 11",
"output": "-1"
},
{
"input": "33 22\n3 9\n3 28\n4 12\n5 11\n5 31\n6 18\n8 15\n8 29\n9 28\n10 22\n11 31\n13 14\n15 29\n16 23\n16 27\n17 25\n17 32\n19 21\n20 30\n23 27\n24 33\n25 32",
"output": "-1"
},
{
"input": "18 8\n1 14\n2 16\n4 7\n5 11\n8 9\n8 12\n9 12\n10 18",
"output": "12 9 8 \n7 4 3 \n11 6 5 \n14 13 1 \n16 15 2 \n18 17 10 "
},
{
"input": "27 21\n1 3\n2 9\n2 11\n5 16\n5 25\n7 26\n8 14\n8 22\n9 11\n10 17\n10 27\n12 21\n13 20\n13 23\n14 22\n15 18\n15 19\n16 25\n17 27\n18 19\n20 23",
"output": "11 9 2 \n19 18 15 \n22 14 8 \n23 20 13 \n25 16 5 \n27 17 10 \n4 3 1 \n21 12 6 \n26 24 7 "
},
{
"input": "24 21\n1 14\n2 6\n3 4\n3 19\n4 19\n5 7\n5 21\n7 21\n8 18\n8 23\n9 15\n9 16\n10 12\n10 17\n11 22\n12 17\n13 20\n13 24\n15 16\n18 23\n20 24",
"output": "-1"
},
{
"input": "45 31\n1 5\n2 45\n3 29\n3 30\n4 16\n4 32\n6 40\n7 13\n7 25\n8 42\n10 31\n11 20\n11 26\n12 27\n12 34\n13 25\n14 24\n14 43\n15 36\n15 37\n16 32\n18 19\n18 33\n19 33\n20 26\n23 41\n24 43\n27 34\n28 39\n29 30\n36 37",
"output": "25 13 7 \n26 20 11 \n30 29 3 \n32 16 4 \n33 19 18 \n34 27 12 \n37 36 15 \n43 24 14 \n9 5 1 \n31 17 10 \n39 28 21 \n40 22 6 \n41 35 23 \n42 38 8 \n45 44 2 "
},
{
"input": "18 9\n1 16\n2 17\n4 6\n5 18\n7 8\n7 15\n8 15\n9 11\n10 13",
"output": "-1"
},
{
"input": "6 6\n1 6\n1 3\n3 6\n2 4\n4 5\n2 5",
"output": "5 4 2 \n6 3 1 "
},
{
"input": "48 48\n7 39\n39 45\n7 45\n25 26\n26 31\n25 31\n4 11\n11 19\n4 19\n8 16\n16 37\n8 37\n14 22\n22 33\n14 33\n6 12\n12 46\n6 46\n29 44\n44 48\n29 48\n15 27\n27 41\n15 41\n3 24\n24 34\n3 34\n13 20\n20 47\n13 47\n5 9\n9 36\n5 36\n21 40\n40 43\n21 43\n2 35\n35 38\n2 38\n23 28\n28 42\n23 42\n1 10\n10 32\n1 32\n17 18\n18 30\n17 30",
"output": "19 11 4 \n30 18 17 \n31 26 25 \n32 10 1 \n33 22 14 \n34 24 3 \n36 9 5 \n37 16 8 \n38 35 2 \n41 27 15 \n42 28 23 \n43 40 21 \n45 39 7 \n46 12 6 \n47 20 13 \n48 44 29 "
},
{
"input": "12 9\n1 2\n2 4\n1 3\n5 6\n6 8\n5 7\n9 10\n10 12\n9 11",
"output": "-1"
},
{
"input": "9 7\n1 2\n3 4\n5 6\n7 8\n2 3\n2 5\n2 7",
"output": "-1"
},
{
"input": "9 3\n4 5\n6 7\n8 9",
"output": "5 4 1 \n7 6 2 \n9 8 3 "
},
{
"input": "6 2\n3 4\n5 6",
"output": "4 3 1 \n6 5 2 "
},
{
"input": "9 7\n1 2\n2 3\n1 3\n4 5\n4 6\n4 7\n4 8",
"output": "-1"
},
{
"input": "6 1\n1 2",
"output": "3 2 1 \n6 5 4 "
},
{
"input": "48 1\n1 2",
"output": "3 2 1 \n6 5 4 \n9 8 7 \n12 11 10 \n15 14 13 \n18 17 16 \n21 20 19 \n24 23 22 \n27 26 25 \n30 29 28 \n33 32 31 \n36 35 34 \n39 38 37 \n42 41 40 \n45 44 43 \n48 47 46 "
}
] | 1,685,266,922 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 62 | 0 | # /**
# * author: brownfox2k6
# * created: 28/05/2023 15:44:44 Hanoi, Vietnam
# **/
n, m = map(int, input().split())
g = {}
for i in range(1, n+1):
g[i] = []
for _ in range(m):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
teams = [[] for _ in range(n//3)]
vis = [False for _ in range(n+1)]
p = 0
for i in range(1, n+1):
if g[i] and not vis[i]:
st = [i]
vis[i] = True
while st:
u = st.pop()
teams[p].append(u)
for v in g[u]:
if not vis[v]:
st.append(v)
vis[v] = True
p += 1
remain = [i for i in range(1, n+1) if not vis[i]]
for i in range(n//3):
if len(teams[i]) > 3:
exit(print(-1))
while len(teams[i]) < 3:
teams[i].append(remain.pop())
for team in teams:
print(*team) | Title: Coach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive.
Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team.
Help the coach and divide the teams the way he wants.
Input Specification:
The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team.
It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*,<=*b**i* occurs in the input at most once.
Output Specification:
If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team.
If there are multiple answers, you are allowed to print any of them.
Demo Input:
['3 0\n', '6 4\n1 2\n2 3\n3 4\n5 6\n', '3 3\n1 2\n2 3\n1 3\n']
Demo Output:
['3 2 1 \n', '-1\n', '3 2 1 \n']
Note:
none | ```python
# /**
# * author: brownfox2k6
# * created: 28/05/2023 15:44:44 Hanoi, Vietnam
# **/
n, m = map(int, input().split())
g = {}
for i in range(1, n+1):
g[i] = []
for _ in range(m):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
teams = [[] for _ in range(n//3)]
vis = [False for _ in range(n+1)]
p = 0
for i in range(1, n+1):
if g[i] and not vis[i]:
st = [i]
vis[i] = True
while st:
u = st.pop()
teams[p].append(u)
for v in g[u]:
if not vis[v]:
st.append(v)
vis[v] = True
p += 1
remain = [i for i in range(1, n+1) if not vis[i]]
for i in range(n//3):
if len(teams[i]) > 3:
exit(print(-1))
while len(teams[i]) < 3:
teams[i].append(remain.pop())
for team in teams:
print(*team)
``` | -1 |
|
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "6 0\n10\n102\n120\n1032\n1212103\n1999999",
"output": "5"
},
{
"input": "1 3\n1000000000",
"output": "0"
},
{
"input": "1 9\n1000000000",
"output": "0"
},
{
"input": "1 0\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 3\n1",
"output": "0"
},
{
"input": "1 9\n1",
"output": "0"
},
{
"input": "2 8\n123456780\n123",
"output": "1"
},
{
"input": "2 8\n12345678\n1230",
"output": "0"
},
{
"input": "6 1\n10\n102\n120\n1032\n1212103\n1999999",
"output": "5"
},
{
"input": "6 2\n10\n102\n120\n1032\n1212103\n1999999",
"output": "4"
},
{
"input": "6 3\n10\n102\n120\n1032\n1212103\n1999999",
"output": "2"
},
{
"input": "6 9\n10\n102\n120\n1032\n1212103\n1999999",
"output": "0"
},
{
"input": "1 2\n2220",
"output": "0"
}
] | 1,687,537,037 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | lengh,number=map(int,input().split())
c=0
for i in range(lengh):
s=int(input())
if len(str(s))>number:
s=s//10
if s%10==number:
c+=1
print(c) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
Input Specification:
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the number of *k*-good numbers in *a*.
Demo Input:
['10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n', '2 1\n1\n10\n']
Demo Output:
['10\n', '1\n']
Note:
none | ```python
lengh,number=map(int,input().split())
c=0
for i in range(lengh):
s=int(input())
if len(str(s))>number:
s=s//10
if s%10==number:
c+=1
print(c)
``` | 0 |
|
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,648,194,995 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | k = int(input())
a = [int(i) for i in input().split()]
if sum(a)<k:
print(-1)
else:
a.sort()
a = a[::-1]
cnt = 0
for i in range(len(a)):
cnt += a[i]
if cnt >= k:
print(i+1)
break | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
k = int(input())
a = [int(i) for i in input().split()]
if sum(a)<k:
print(-1)
else:
a.sort()
a = a[::-1]
cnt = 0
for i in range(len(a)):
cnt += a[i]
if cnt >= k:
print(i+1)
break
``` | 0 |
|
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted.
Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads.
According to the schedule of road works tell in which days at least one road will be asphalted. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct. | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road. | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 1",
"output": "1 4 5 "
},
{
"input": "3\n1 3\n3 1\n2 1\n1 1\n1 2\n2 2\n3 2\n3 3\n2 3",
"output": "1 2 6 "
},
{
"input": "4\n1 3\n2 3\n2 4\n4 4\n3 1\n1 1\n3 4\n2 1\n1 4\n4 3\n4 1\n3 2\n1 2\n4 2\n2 2\n3 3",
"output": "1 3 5 14 "
},
{
"input": "4\n3 3\n4 2\n2 3\n3 4\n4 4\n1 2\n3 2\n2 2\n1 4\n3 1\n4 1\n2 1\n1 3\n1 1\n4 3\n2 4",
"output": "1 2 9 12 "
},
{
"input": "9\n4 5\n2 3\n8 3\n5 6\n9 3\n4 4\n5 4\n4 7\n1 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n9 9\n8 7\n7 5\n3 7\n6 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n1 1\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 2\n3 9\n2 9\n7 7\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n3 3\n3 8\n5 5\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n8 8\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8",
"output": "1 2 4 9 10 14 16 32 56 "
},
{
"input": "8\n1 1\n1 2\n1 3\n1 4\n1 5\n8 6\n1 7\n1 8\n2 1\n8 5\n2 3\n2 4\n2 5\n2 6\n4 3\n2 2\n3 1\n3 2\n3 3\n3 4\n3 5\n3 6\n5 6\n3 8\n4 1\n4 2\n2 7\n4 4\n8 8\n4 6\n4 7\n4 8\n5 1\n5 2\n5 3\n6 5\n5 5\n3 7\n5 7\n5 8\n6 1\n6 2\n6 3\n6 4\n5 4\n6 6\n6 7\n6 8\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n7 8\n8 1\n8 2\n8 3\n8 4\n2 8\n1 6\n8 7\n4 5",
"output": "1 6 11 18 28 36 39 56 "
},
{
"input": "9\n9 9\n5 5\n8 8\n3 3\n2 2\n6 6\n4 4\n1 1\n7 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n1 7\n8 7\n7 5\n3 7\n5 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n4 5\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 3\n3 9\n2 9\n5 4\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n8 3\n3 8\n9 3\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n4 7\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8",
"output": "1 2 3 4 5 6 7 8 9 "
}
] | 1,587,288,018 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 |
t=[]
a=[]
for i in range(int(input())**2):
n,m=list(map(int,input().split()))
if n not in t:
if m not in t:
a.append(i+1)
t.append(m)
t.append(n)
else:
pass
else:
pass
print(*a)
| Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted.
Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads.
According to the schedule of road works tell in which days at least one road will be asphalted.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.
Output Specification:
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
Demo Input:
['2\n1 1\n1 2\n2 1\n2 2\n', '1\n1 1\n']
Demo Output:
['1 4 \n', '1 \n']
Note:
In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road. | ```python
t=[]
a=[]
for i in range(int(input())**2):
n,m=list(map(int,input().split()))
if n not in t:
if m not in t:
a.append(i+1)
t.append(m)
t.append(n)
else:
pass
else:
pass
print(*a)
``` | 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,587,576,198 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 5,836,800 | a,b,n=[int(x) for x in input().split(' ')]
b2=True
for i in range(n):
bhul=True
for j in range(10):
if((a*10+j)%b==0):
a=a*10+j
bhul=False
break
if(bhul):
print(-1)
b2=False
break
if(b2):
print(a)
| 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=[int(x) for x in input().split(' ')]
b2=True
for i in range(n):
bhul=True
for j in range(10):
if((a*10+j)%b==0):
a=a*10+j
bhul=False
break
if(bhul):
print(-1)
b2=False
break
if(b2):
print(a)
``` | 0 |
|
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain\nB man\nD woman\nC child\nE rat",
"output": "E\nD\nC\nB\nA"
},
{
"input": "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat",
"output": "Rat\nRatt\nD\nC\nA\nE\nB\nF\nMan\nCap"
},
{
"input": "5\nJoyxnkypf captain\nDxssgr woman\nKeojmnpd rat\nGdv man\nHnw man",
"output": "Keojmnpd\nDxssgr\nGdv\nHnw\nJoyxnkypf"
},
{
"input": "11\nJue rat\nWyglbyphk rat\nGjlgu child\nGi man\nAttx rat\nTheorpkgx man\nYm rat\nX child\nB captain\nEnualf rat\nKktsgyuyv woman",
"output": "Jue\nWyglbyphk\nAttx\nYm\nEnualf\nGjlgu\nX\nKktsgyuyv\nGi\nTheorpkgx\nB"
},
{
"input": "22\nWswwcvvm woman\nBtmfats rat\nI rat\nOcmtsnwx man\nUrcqv rat\nYghnogt woman\nWtyfc man\nWqle child\nUjfrelpu rat\nDstixj man\nAhksnio woman\nKhkvaap woman\nSjppvwm rat\nEgdmsv rat\nDank rat\nNquicjnw rat\nLh captain\nTdyaqaqln rat\nQtj rat\nTfgwijvq rat\nNbiso child\nNqthvbf woman",
"output": "Btmfats\nI\nUrcqv\nUjfrelpu\nSjppvwm\nEgdmsv\nDank\nNquicjnw\nTdyaqaqln\nQtj\nTfgwijvq\nWswwcvvm\nYghnogt\nWqle\nAhksnio\nKhkvaap\nNbiso\nNqthvbf\nOcmtsnwx\nWtyfc\nDstixj\nLh"
},
{
"input": "36\nKqxmtwmsf child\nIze woman\nDlpr child\nK woman\nF captain\nRjwfeuhba rat\nBbv rat\nS rat\nMnmg woman\nSmzyx woman\nSr man\nQmhroracn rat\nSoqpuqock rat\nPibdq man\nIlrkrptx rat\nZaecfyqka man\nMmersfs child\nVvvocqi man\nHjeqxvq rat\nMpmb woman\nWmgu woman\nCerelmhoxi child\nA man\nDylv man\nXrdgmmtcpq woman\nXj woman\nCeh child\nOfccguo man\nNevr man\nAknkwdkq child\nBmo man\nLqo woman\nVej child\nT child\nRlijc man\nNsdtpdg woman",
"output": "Rjwfeuhba\nBbv\nS\nQmhroracn\nSoqpuqock\nIlrkrptx\nHjeqxvq\nKqxmtwmsf\nIze\nDlpr\nK\nMnmg\nSmzyx\nMmersfs\nMpmb\nWmgu\nCerelmhoxi\nXrdgmmtcpq\nXj\nCeh\nAknkwdkq\nLqo\nVej\nT\nNsdtpdg\nSr\nPibdq\nZaecfyqka\nVvvocqi\nA\nDylv\nOfccguo\nNevr\nBmo\nRlijc\nF"
},
{
"input": "2\nA captain\nB man",
"output": "B\nA"
},
{
"input": "2\nB woman\nA captain",
"output": "B\nA"
},
{
"input": "2\nX child\nY captain",
"output": "X\nY"
},
{
"input": "2\nX captain\nY rat",
"output": "Y\nX"
},
{
"input": "6\nAbdelrhman captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nAbdelrhman"
},
{
"input": "4\nAratos captain\nMind child\nAman woman\nCarrot man",
"output": "Mind\nAman\nCarrot\nAratos"
}
] | 1,621,937,872 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 0 | t=int(input())
l1,l2,l3=[],[],[]
for i in range(t):
n,s=map(str,input().split())
if s=='rat':
l1.append(n)
if s=='child' or s=='woman':
l2.append(n)
if s=='man':
l3.append(n)
if s=='captain':
cap=n
for i in range(len(l1)):
print(l1[i])
for j in range(len(l2)):
print(l2[j])
for k in range(len(l3)):
print(l3[k])
print(cap)
| Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
Input Specification:
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Output Specification:
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
Demo Input:
['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n']
Demo Output:
['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n']
Note:
none | ```python
t=int(input())
l1,l2,l3=[],[],[]
for i in range(t):
n,s=map(str,input().split())
if s=='rat':
l1.append(n)
if s=='child' or s=='woman':
l2.append(n)
if s=='man':
l3.append(n)
if s=='captain':
cap=n
for i in range(len(l1)):
print(l1[i])
for j in range(len(l2)):
print(l2[j])
for k in range(len(l3)):
print(l3[k])
print(cap)
``` | 3.969 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,698,555,828 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input()) # Number of drinks
fractions = list(map(int, input().split())) # List of volume fractions
# Calculate the weighted average
total_volume = sum(fractions)
average_fraction = total_volume / n
# Print the result with 10 decimal places
print(format(average_fraction, '.10f'))
| Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | ```python
n = int(input()) # Number of drinks
fractions = list(map(int, input().split())) # List of volume fractions
# Calculate the weighted average
total_volume = sum(fractions)
average_fraction = total_volume / n
# Print the result with 10 decimal places
print(format(average_fraction, '.10f'))
``` | 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,695,182,051 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | i = input()
l = len(i)
s = l/2
uppernum = 0
for x in i:
if ord(x) < 97:
uppernum += 1
if uppernum > s:
print(i.upper())
else:
print(i.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
i = input()
l = len(i)
s = l/2
uppernum = 0
for x in i:
if ord(x) < 97:
uppernum += 1
if uppernum > s:
print(i.upper())
else:
print(i.lower())
``` | 3.977 |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string. | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss",
"output": "1"
},
{
"input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs",
"output": "2"
},
{
"input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi",
"output": "2"
},
{
"input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn",
"output": "1"
},
{
"input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti",
"output": "2"
},
{
"input": "rmeetriiitijmrenmeiijt",
"output": "0"
},
{
"input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne",
"output": "1"
},
{
"input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer",
"output": "2"
},
{
"input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim",
"output": "2"
},
{
"input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm",
"output": "3"
},
{
"input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn",
"output": "3"
},
{
"input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni",
"output": "1"
},
{
"input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm",
"output": "2"
},
{
"input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet",
"output": "3"
},
{
"input": "jrjshtjstteh",
"output": "0"
},
{
"input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn",
"output": "2"
},
{
"input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn",
"output": "2"
},
{
"input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei",
"output": "1"
},
{
"input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin",
"output": "2"
},
{
"input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin",
"output": "1"
},
{
"input": "rnsrsmretjiitrjthhritniijhjmm",
"output": "0"
},
{
"input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj",
"output": "3"
},
{
"input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni",
"output": "0"
},
{
"input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis",
"output": "2"
},
{
"input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh",
"output": "3"
},
{
"input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei",
"output": "3"
},
{
"input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs",
"output": "1"
},
{
"input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj",
"output": "1"
},
{
"input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj",
"output": "2"
},
{
"input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii",
"output": "1"
},
{
"input": "iihienhirmnihh",
"output": "0"
},
{
"input": "ismtthhshjmhisssnmnhe",
"output": "0"
},
{
"input": "rhsmnrmhejshinnjrtmtsssijimimethnm",
"output": "0"
},
{
"input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj",
"output": "3"
},
{
"input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes",
"output": "2"
},
{
"input": "ssrmjmjeeetrnimemrhimes",
"output": "0"
},
{
"input": "n",
"output": "0"
},
{
"input": "ni",
"output": "0"
},
{
"input": "nine",
"output": "0"
},
{
"input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen",
"output": "13"
},
{
"input": "ninetee",
"output": "0"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd",
"output": "0"
},
{
"input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch",
"output": "0"
},
{
"input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq",
"output": "0"
},
{
"input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz",
"output": "13"
},
{
"input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee",
"output": "3"
},
{
"input": "ttttiiiieeeeeeeeeeeennnnnnnnn",
"output": "4"
},
{
"input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn",
"output": "3"
},
{
"input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt",
"output": "4"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn",
"output": "3"
},
{
"input": "nineeen",
"output": "0"
},
{
"input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii",
"output": "0"
},
{
"input": "nineteenieteenieteenieteenieteenieteenieteen",
"output": "4"
},
{
"input": "nineteenineteenineteenineteenineteen",
"output": "5"
}
] | 1,592,394,205 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | s=input()
n=s.count('n')
i=s.count('i')
e=s.count('e')
t=s.count('t')
ne=min(n,e)
it=min(i,t)
c=0
while n-3>=0 and it-1>=0:
ne-=3
it-=1
c+=1
print(c) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string.
Input Specification:
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Output Specification:
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
Demo Input:
['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n']
Demo Output:
['2', '2', '2']
Note:
none | ```python
s=input()
n=s.count('n')
i=s.count('i')
e=s.count('e')
t=s.count('t')
ne=min(n,e)
it=min(i,t)
c=0
while n-3>=0 and it-1>=0:
ne-=3
it-=1
c+=1
print(c)
``` | 0 |
|
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "999 2",
"output": "1997"
},
{
"input": "1000 3",
"output": "1499"
},
{
"input": "1000 4",
"output": "1333"
},
{
"input": "1 1000",
"output": "1"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "10 4",
"output": "13"
},
{
"input": "4 3",
"output": "5"
},
{
"input": "91 5",
"output": "113"
},
{
"input": "777 17",
"output": "825"
},
{
"input": "100 4",
"output": "133"
},
{
"input": "5 3",
"output": "7"
},
{
"input": "6 4",
"output": "7"
},
{
"input": "26 8",
"output": "29"
},
{
"input": "9 4",
"output": "11"
},
{
"input": "20 3",
"output": "29"
},
{
"input": "17 3",
"output": "25"
}
] | 1,641,889,013 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 77 | 0 | a,b = map(int,input().split())
c=a
x=a
while(x>=b ):
c+= x//b
x = x//b + (x - (x//b)*b)
# print(x,c)
print(c) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input Specification:
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Output Specification:
Print a single integer — the number of hours Vasily can light up the room for.
Demo Input:
['4 2\n', '6 3\n']
Demo Output:
['7\n', '8\n']
Note:
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | ```python
a,b = map(int,input().split())
c=a
x=a
while(x>=b ):
c+= x//b
x = x//b + (x - (x//b)*b)
# print(x,c)
print(c)
``` | 3 |
|
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem? | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "10\n0 -1 2 2 -1 1 0 0 0 2",
"output": "0"
},
{
"input": "10\n-1 -1 1 -1 0 1 0 1 1 1",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "9"
},
{
"input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3",
"output": "3"
},
{
"input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3",
"output": "0"
},
{
"input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2",
"output": "0"
},
{
"input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2",
"output": "1"
},
{
"input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2",
"output": "6"
},
{
"input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n10000",
"output": "0"
},
{
"input": "1\n-10000",
"output": "0"
}
] | 1,691,572,659 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int n,ans,cum[100010],a[100010];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
cum[i]=cum[i-1]+a[i];
}
for(int i=1;i<n;i++){
if(cum[i]==cum[n]-cum[i])
ans++;
}
cout<<ans<<endl;
return 0;
} | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output Specification:
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
Demo Input:
['9\n1 5 -6 7 9 -16 0 -2 2\n', '3\n1 1 1\n', '2\n0 0\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
none | ```python
#include <iostream>
using namespace std;
int n,ans,cum[100010],a[100010];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
cum[i]=cum[i-1]+a[i];
}
for(int i=1;i<n;i++){
if(cum[i]==cum[n]-cum[i])
ans++;
}
cout<<ans<<endl;
return 0;
}
``` | -1 |
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements.
The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid. | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80",
"output": "No"
},
{
"input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58",
"output": "Yes"
},
{
"input": "4 1\n2 1 0 4\n3",
"output": "Yes"
},
{
"input": "2 1\n199 0\n200",
"output": "No"
},
{
"input": "3 2\n115 0 0\n145 191",
"output": "Yes"
},
{
"input": "5 1\n196 197 198 0 200\n199",
"output": "No"
},
{
"input": "5 1\n92 0 97 99 100\n93",
"output": "No"
},
{
"input": "3 1\n3 87 0\n81",
"output": "Yes"
},
{
"input": "3 1\n0 92 192\n118",
"output": "Yes"
},
{
"input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22",
"output": "Yes"
},
{
"input": "100 1\n14 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 0 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\n67",
"output": "No"
},
{
"input": "100 5\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 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 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 0 99 100\n98 64 55 52 29",
"output": "Yes"
},
{
"input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27",
"output": "Yes"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 0 10 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\n11",
"output": "Yes"
},
{
"input": "100 1\n0 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\n1",
"output": "No"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\n100",
"output": "No"
},
{
"input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65",
"output": "Yes"
},
{
"input": "100 2\n0 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 0 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\n48 1",
"output": "Yes"
},
{
"input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69",
"output": "Yes"
},
{
"input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129",
"output": "No"
},
{
"input": "5 2\n0 2 7 0 10\n1 8",
"output": "Yes"
},
{
"input": "3 1\n5 4 0\n1",
"output": "Yes"
},
{
"input": "3 1\n1 0 3\n4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n1",
"output": "No"
},
{
"input": "2 1\n0 5\n7",
"output": "Yes"
},
{
"input": "5 1\n10 11 0 12 13\n1",
"output": "Yes"
},
{
"input": "5 1\n0 2 3 4 5\n6",
"output": "Yes"
},
{
"input": "6 2\n1 0 3 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "7 2\n1 2 3 0 0 6 7\n4 5",
"output": "Yes"
},
{
"input": "4 1\n1 2 3 0\n4",
"output": "No"
},
{
"input": "2 2\n0 0\n1 2",
"output": "Yes"
},
{
"input": "3 2\n1 0 0\n2 3",
"output": "Yes"
},
{
"input": "4 2\n1 0 4 0\n5 2",
"output": "Yes"
},
{
"input": "2 1\n0 1\n2",
"output": "Yes"
},
{
"input": "5 2\n1 0 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 4 5\n1",
"output": "Yes"
},
{
"input": "3 1\n0 2 3\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 5 0\n6",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n5 0 2\n7",
"output": "Yes"
},
{
"input": "4 1\n4 5 0 8\n3",
"output": "Yes"
},
{
"input": "5 1\n10 11 12 0 14\n13",
"output": "No"
},
{
"input": "4 1\n1 2 0 4\n5",
"output": "Yes"
},
{
"input": "3 1\n0 11 14\n12",
"output": "Yes"
},
{
"input": "4 1\n1 3 0 4\n2",
"output": "Yes"
},
{
"input": "2 1\n0 5\n1",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 7\n5",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n1",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 5 4\n6",
"output": "Yes"
},
{
"input": "4 2\n11 0 0 14\n13 12",
"output": "Yes"
},
{
"input": "2 1\n1 0\n2",
"output": "No"
},
{
"input": "3 1\n1 2 0\n3",
"output": "No"
},
{
"input": "4 1\n1 0 3 2\n4",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n5",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n3",
"output": "Yes"
},
{
"input": "4 1\n0 2 3 4\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n1 2 0\n5",
"output": "No"
},
{
"input": "4 2\n1 0 0 4\n3 2",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 5 7\n6",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n4",
"output": "No"
},
{
"input": "3 1\n1 0 11\n5",
"output": "No"
},
{
"input": "4 1\n7 9 5 0\n8",
"output": "Yes"
},
{
"input": "6 2\n1 2 3 0 5 0\n6 4",
"output": "Yes"
},
{
"input": "3 2\n0 1 0\n3 2",
"output": "Yes"
},
{
"input": "4 1\n6 9 5 0\n8",
"output": "Yes"
},
{
"input": "2 1\n0 3\n6",
"output": "Yes"
},
{
"input": "5 2\n1 2 0 0 5\n4 3",
"output": "Yes"
},
{
"input": "4 2\n2 0 0 8\n3 4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n3",
"output": "Yes"
},
{
"input": "3 1\n0 4 5\n6",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 0 5\n6",
"output": "Yes"
},
{
"input": "2 1\n2 0\n3",
"output": "No"
},
{
"input": "4 2\n11 0 0 200\n100 199",
"output": "Yes"
},
{
"input": "2 1\n5 0\n4",
"output": "Yes"
},
{
"input": "3 1\n1 0 5\n10",
"output": "Yes"
},
{
"input": "6 2\n1 2 0 0 5 6\n3 4",
"output": "Yes"
},
{
"input": "5 2\n1 0 3 0 5\n2 4",
"output": "Yes"
},
{
"input": "4 1\n1 4 0 8\n3",
"output": "Yes"
},
{
"input": "4 1\n5 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 7\n3 2",
"output": "Yes"
},
{
"input": "3 3\n0 0 0\n1 4 3",
"output": "Yes"
},
{
"input": "5 5\n0 0 0 0 0\n5 4 3 2 1",
"output": "Yes"
},
{
"input": "4 1\n3 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 4\n2 3",
"output": "Yes"
},
{
"input": "6 1\n2 4 0 8 9 10\n3",
"output": "Yes"
},
{
"input": "4 1\n0 3 5 6\n9",
"output": "Yes"
},
{
"input": "4 2\n1 2 0 0\n3 4",
"output": "Yes"
},
{
"input": "5 1\n2 3 4 5 0\n1",
"output": "Yes"
},
{
"input": "3 1\n2 0 4\n5",
"output": "Yes"
}
] | 1,497,017,712 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | I = lambda: map(int,input().split())
n,m = I()
a,b = list(I()),list(I())
if(m==1):
a[a.index(0)] = b[0]
if(a.sort() == a):
print("No")
exit(0)
print("Yes")
| Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing.
Input Specification:
The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements.
The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total.
Output Specification:
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
Demo Input:
['4 2\n11 0 0 14\n5 4\n', '6 1\n2 3 0 8 9 10\n5\n', '4 1\n8 94 0 4\n89\n', '7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n', 'Yes\n']
Note:
In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid. | ```python
I = lambda: map(int,input().split())
n,m = I()
a,b = list(I()),list(I())
if(m==1):
a[a.index(0)] = b[0]
if(a.sort() == a):
print("No")
exit(0)
print("Yes")
``` | 0 |
|
613 | A | Peter and Snow Blower | PROGRAMMING | 1,900 | [
"binary search",
"geometry",
"ternary search"
] | null | null | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.
Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.
Peter decided to tie his car to point *P* and now he is wondering what is the area of the region that will be cleared from snow. Help him. | The first line of the input contains three integers — the number of vertices of the polygon *n* (), and coordinates of point *P*.
Each of the next *n* lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.
All the numbers in the input are integers that do not exceed 1<=000<=000 in their absolute value. | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"3 0 0\n0 1\n-1 2\n1 2\n",
"4 1 -1\n0 0\n1 2\n2 0\n1 1\n"
] | [
"12.566370614359172464\n",
"21.991148575128551812\n"
] | In the first sample snow will be removed from that area: | 750 | [
{
"input": "3 0 0\n0 1\n-1 2\n1 2",
"output": "12.566370614359172464"
},
{
"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1",
"output": "21.991148575128551812"
},
{
"input": "3 0 0\n-1 1\n0 3\n1 1",
"output": "25.132741228718344928"
},
{
"input": "3 -4 2\n-3 2\n5 -5\n5 3",
"output": "405.26545231308331191"
},
{
"input": "3 -84 8\n-83 8\n21 -62\n3 53",
"output": "50026.721415763865583"
},
{
"input": "6 -94 -51\n-93 -51\n48 -25\n61 27\n73 76\n-10 87\n-48 38",
"output": "138283.48383306192359"
},
{
"input": "5 -94 52\n-93 52\n-78 -56\n-54 -81\n56 -87\n97 85",
"output": "131381.40477312514811"
},
{
"input": "10 -100 90\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96 -2\n100 36\n99 59\n27 83\n-14 93",
"output": "198410.42563011697403"
},
{
"input": "11 -97 -15\n-96 -15\n-83 -84\n-61 -97\n64 -92\n81 -82\n100 -63\n86 80\n58 95\n15 99\n-48 83\n-91 49",
"output": "133558.52848206287476"
},
{
"input": "10 -500 420\n-499 420\n-489 -173\n-455 -480\n160 -464\n374 -437\n452 -352\n481 -281\n465 75\n326 392\n-398 468",
"output": "4719573.802783449531"
},
{
"input": "10 -498 -161\n-497 -161\n-427 -458\n-325 -475\n349 -500\n441 -220\n473 28\n475 62\n468 498\n-444 492\n-465 264",
"output": "4295926.8918542123392"
},
{
"input": "5 -1 -1\n0 0\n8 5\n10 7\n7 5\n2 5",
"output": "574.91145560693214023"
},
{
"input": "5 -1 -1\n0 0\n20 3\n26 17\n23 21\n98 96",
"output": "60343.711690152746165"
},
{
"input": "10 -1 -1\n0 0\n94 7\n100 52\n87 48\n37 26\n74 61\n59 57\n87 90\n52 90\n26 73",
"output": "50337.739088469255101"
},
{
"input": "10 -1 -1\n0 0\n78 22\n53 24\n78 50\n46 39\n45 56\n21 46\n2 7\n24 97\n5 59",
"output": "32129.068068262814194"
},
{
"input": "49 -1 -1\n0 0\n95 2\n47 1\n42 1\n93 7\n56 6\n47 7\n63 13\n98 24\n94 27\n90 28\n86 28\n17 6\n64 24\n42 19\n66 35\n63 35\n98 60\n75 48\n28 18\n71 46\n69 46\n99 68\n64 47\n56 43\n72 58\n35 29\n82 81\n68 69\n79 84\n72 77\n79 86\n54 59\n35 39\n20 23\n73 86\n80 97\n79 100\n69 99\n29 45\n26 63\n23 56\n12 33\n13 39\n25 85\n27 96\n6 23\n4 47\n1 60",
"output": "52147.296456936975932"
},
{
"input": "49 -1 -1\n0 0\n69 2\n74 7\n62 10\n64 15\n93 22\n78 22\n56 17\n86 29\n24 9\n91 43\n8 4\n90 50\n99 57\n39 23\n81 50\n91 58\n67 46\n95 66\n52 39\n91 69\n69 54\n93 84\n93 98\n70 80\n85 98\n30 39\n55 79\n41 59\n50 72\n57 88\n58 92\n58 94\n37 63\n43 87\n30 63\n19 40\n38 81\n40 86\n38 100\n2 6\n30 100\n23 89\n16 62\n11 49\n12 64\n9 52\n5 62\n1 88",
"output": "58543.579099645794717"
},
{
"input": "27 -999899 136015\n-999898 136015\n-999877 -297518\n-999832 -906080\n-999320 -977222\n-998896 -995106\n-962959 -999497\n-747200 -999814\n417261 -999929\n844204 -999911\n959527 -999826\n998944 -999180\n999413 -989979\n999556 -943026\n999871 -774660\n999993 -261535\n999963 938964\n998309 991397\n989894 997814\n988982 998459\n987145 999235\n972224 999741\n603140 999994\n-812452 999962\n-980920 999788\n-996671 987674\n-999472 977919\n-999808 639816",
"output": "16600304470662.964855"
},
{
"input": "19 -995486 -247212\n-995485 -247212\n-995004 -492984\n-993898 -887860\n-938506 -961227\n-688481 -971489\n178005 -999731\n541526 -999819\n799710 -988908\n905862 -967693\n987335 -887414\n983567 824667\n973128 892799\n914017 960546\n669333 986330\n-441349 986800\n-813005 986924\n-980671 973524\n-988356 849906\n-995289 404864",
"output": "16257949833603.158278"
},
{
"input": "15 -994057 554462\n-994056 554462\n-975707 -994167\n-711551 -996810\n13909 -997149\n809315 -993832\n980809 -984682\n996788 -303578\n993267 173570\n978439 877361\n898589 957311\n725925 992298\n-57849 999563\n-335564 997722\n-989580 990530\n-993875 973633",
"output": "19694832748836.689348"
},
{
"input": "23 -999840 738880\n-999839 738880\n-998291 -847192\n-995443 -982237\n-906770 -996569\n360950 -999295\n800714 -998808\n985348 -995579\n990091 -928438\n996690 -817256\n998844 -736918\n998377 674949\n998008 862436\n993320 971157\n978831 979400\n853341 986660\n802107 989497\n513719 996183\n140983 998592\n-158810 999459\n-677966 999174\n-949021 981608\n-982951 976421\n-993452 962292",
"output": "21831930831113.094931"
},
{
"input": "20 -999719 -377746\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n994737 985066\n640032 998502\n-87871 999984\n-450900 999751\n-910919 999086\n-971174 995672\n-995406 975642\n-998685 946525\n-999684 673031",
"output": "18331542740428.216614"
},
{
"input": "26 -999922 -339832\n-999921 -339832\n-999666 -565163\n-998004 -942175\n-992140 -985584\n-965753 -998838\n-961074 -999911\n120315 -999489\n308422 -999258\n696427 -997199\n724780 -996955\n995651 -985203\n997267 -975745\n999745 -941705\n999897 -770648\n999841 -211766\n999436 865172\n999016 992181\n980442 997414\n799072 998987\n348022 999183\n-178144 999329\n-729638 998617\n-953068 997984\n-991172 990824\n-997976 939889\n-999483 581509",
"output": "18127026556380.411608"
},
{
"input": "22 -999930 -362070\n-999929 -362070\n-994861 -919993\n-989365 -946982\n-964007 -997050\n-418950 -998064\n351746 -998882\n830925 -996765\n867755 -996352\n964401 -992258\n996299 -964402\n997257 -930788\n999795 -616866\n999689 327482\n997898 996234\n923521 997809\n631104 998389\n-261788 999672\n-609744 999782\n-694662 999001\n-941227 993687\n-997105 992436\n-999550 895326",
"output": "18335297542813.80731"
},
{
"input": "29 -999961 689169\n-999960 689169\n-999927 -938525\n-999735 -989464\n-993714 -997911\n-870186 -999686\n-796253 -999950\n-139940 -999968\n969552 -999972\n985446 -999398\n992690 -997295\n999706 -973137\n999898 -848630\n999997 -192297\n999969 773408\n999495 960350\n999143 981671\n998324 993987\n997640 998103\n986157 998977\n966840 999418\n670113 999809\n477888 999856\n129160 999900\n-373564 999947\n-797543 999976\n-860769 999903\n-995496 999355\n-998771 984570\n-999768 927157",
"output": "21409384775316.574772"
},
{
"input": "3 -3 3\n-3 2\n5 -5\n5 3",
"output": "399.0305992005743379"
},
{
"input": "3 -9 7\n-9 6\n3 -6\n4 2",
"output": "980.17690792001545219"
},
{
"input": "5 -9 8\n-9 7\n-6 -1\n-3 -6\n1 -3\n10 8",
"output": "1130.9820337250702449"
},
{
"input": "6 -6 -1\n-6 -2\n0 -7\n8 -9\n9 -1\n5 10\n-5 0",
"output": "816.18577140262825159"
},
{
"input": "10 -99 91\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96 -2\n100 36\n99 59\n27 83\n-14 93",
"output": "198309.89857373595223"
},
{
"input": "11 -96 -14\n-96 -15\n-83 -84\n-61 -97\n64 -92\n81 -82\n100 -63\n86 80\n58 95\n15 99\n-48 83\n-91 49",
"output": "131821.20868619133483"
},
{
"input": "13 -98 25\n-98 24\n-96 10\n-80 -71\n-71 -78\n-31 -99\n82 -98\n92 -39\n94 -2\n94 40\n90 80\n50 96\n-41 97\n-86 80",
"output": "149316.61930888936332"
},
{
"input": "17 -99 -53\n-99 -54\n-97 -71\n-67 -99\n-61 -99\n56 -98\n82 -85\n95 -47\n90 -2\n82 30\n63 87\n54 95\n-12 99\n-38 99\n-87 89\n-90 87\n-95 67\n-96 49",
"output": "144023.17094830233827"
},
{
"input": "19 -995485 -247211\n-995485 -247212\n-995004 -492984\n-993898 -887860\n-938506 -961227\n-688481 -971489\n178005 -999731\n541526 -999819\n799710 -988908\n905862 -967693\n987335 -887414\n983567 824667\n973128 892799\n914017 960546\n669333 986330\n-441349 986800\n-813005 986924\n-980671 973524\n-988356 849906\n-995289 404864",
"output": "16257930301545.657524"
},
{
"input": "15 -994056 554463\n-994056 554462\n-975707 -994167\n-711551 -996810\n13909 -997149\n809315 -993832\n980809 -984682\n996788 -303578\n993267 173570\n978439 877361\n898589 957311\n725925 992298\n-57849 999563\n-335564 997722\n-989580 990530\n-993875 973633",
"output": "19694830011124.045712"
},
{
"input": "23 -999839 738881\n-999839 738880\n-998291 -847192\n-995443 -982237\n-906770 -996569\n360950 -999295\n800714 -998808\n985348 -995579\n990091 -928438\n996690 -817256\n998844 -736918\n998377 674949\n998008 862436\n993320 971157\n978831 979400\n853341 986660\n802107 989497\n513719 996183\n140983 998592\n-158810 999459\n-677966 999174\n-949021 981608\n-982951 976421\n-993452 962292",
"output": "21831929255745.74826"
},
{
"input": "20 -999718 -377745\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n994737 985066\n640032 998502\n-87871 999984\n-450900 999751\n-910919 999086\n-971174 995672\n-995406 975642\n-998685 946525\n-999684 673031",
"output": "18331521646100.671528"
},
{
"input": "26 -999921 -339831\n-999921 -339832\n-999666 -565163\n-998004 -942175\n-992140 -985584\n-965753 -998838\n-961074 -999911\n120315 -999489\n308422 -999258\n696427 -997199\n724780 -996955\n995651 -985203\n997267 -975745\n999745 -941705\n999897 -770648\n999841 -211766\n999436 865172\n999016 992181\n980442 997414\n799072 998987\n348022 999183\n-178144 999329\n-729638 998617\n-953068 997984\n-991172 990824\n-997976 939889\n-999483 581509",
"output": "18127005627407.454252"
},
{
"input": "22 -999929 -362069\n-999929 -362070\n-994861 -919993\n-989365 -946982\n-964007 -997050\n-418950 -998064\n351746 -998882\n830925 -996765\n867755 -996352\n964401 -992258\n996299 -964402\n997257 -930788\n999795 -616866\n999689 327482\n997898 996234\n923521 997809\n631104 998389\n-261788 999672\n-609744 999782\n-694662 999001\n-941227 993687\n-997105 992436\n-999550 895326",
"output": "18335276455623.960732"
},
{
"input": "27 -999898 136016\n-999898 136015\n-999877 -297518\n-999832 -906080\n-999320 -977222\n-998896 -995106\n-962959 -999497\n-747200 -999814\n417261 -999929\n844204 -999911\n959527 -999826\n998944 -999180\n999413 -989979\n999556 -943026\n999871 -774660\n999993 -261535\n999963 938964\n998309 991397\n989894 997814\n988982 998459\n987145 999235\n972224 999741\n603140 999994\n-812452 999962\n-980920 999788\n-996671 987674\n-999472 977919\n-999808 639816",
"output": "16600299044211.965457"
},
{
"input": "13 -1000000 -1000000\n-1000000 0\n0 -1000000\n999417 840\n999781 33421\n999994 131490\n999993 998865\n962080 999911\n629402 999973\n378696 999988\n53978 999788\n25311 999558\n6082 999282\n1565 998489",
"output": "23547598153913.984406"
},
{
"input": "16 -1000000 -1000000\n-1000000 0\n0 -1000000\n999744 572\n999931 96510\n1000000 254372\n999939 748173\n999894 953785\n999683 986098\n999051 999815\n980586 999969\n637250 999988\n118331 999983\n27254 999966\n9197 999405\n4810 997733\n1661 995339",
"output": "23547697574489.259052"
},
{
"input": "4 0 0\n1 -1\n1 3\n3 3\n3 -1",
"output": "53.407075111026482965"
},
{
"input": "3 0 0\n-10 1\n0 2\n1 1",
"output": "314.1592653589793116"
},
{
"input": "3 0 0\n-1 1\n4 1\n0 2",
"output": "50.265482457436689849"
}
] | 1,452,789,456 | 156 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | import math
maxx = -1
minn = 10000000000
a, b, c = map(int, input().split(' '))
for i in range(a):
x, y = map(int, input().split(' '))
dist = ((b-x)**2+(c-y)**2)**0.5
maxx = max(maxx, dist)
minn = min(minn, dist)
print((maxx*maxx-minn*minn)*math.pi)
| Title: Peter and Snow Blower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.
Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.
Peter decided to tie his car to point *P* and now he is wondering what is the area of the region that will be cleared from snow. Help him.
Input Specification:
The first line of the input contains three integers — the number of vertices of the polygon *n* (), and coordinates of point *P*.
Each of the next *n* lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.
All the numbers in the input are integers that do not exceed 1<=000<=000 in their absolute value.
Output Specification:
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['3 0 0\n0 1\n-1 2\n1 2\n', '4 1 -1\n0 0\n1 2\n2 0\n1 1\n']
Demo Output:
['12.566370614359172464\n', '21.991148575128551812\n']
Note:
In the first sample snow will be removed from that area: | ```python
import math
maxx = -1
minn = 10000000000
a, b, c = map(int, input().split(' '))
for i in range(a):
x, y = map(int, input().split(' '))
dist = ((b-x)**2+(c-y)**2)**0.5
maxx = max(maxx, dist)
minn = min(minn, dist)
print((maxx*maxx-minn*minn)*math.pi)
``` | 0 |
|
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459",
"output": "21"
},
{
"input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815",
"output": "16"
},
{
"input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663",
"output": "10"
},
{
"input": "1\n321 88",
"output": "0"
},
{
"input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689",
"output": "7"
},
{
"input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510",
"output": "6"
},
{
"input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888",
"output": "5"
},
{
"input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802",
"output": "13"
},
{
"input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662",
"output": "11"
},
{
"input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786",
"output": "38"
},
{
"input": "3\n175 201\n907 909\n388 360",
"output": "2"
},
{
"input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86",
"output": "6"
},
{
"input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820",
"output": "16"
},
{
"input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901",
"output": "31"
},
{
"input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210",
"output": "29"
},
{
"input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894",
"output": "29"
},
{
"input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823",
"output": "13"
},
{
"input": "5\n175 158\n16 2\n397 381\n668 686\n957 945",
"output": "4"
},
{
"input": "5\n312 284\n490 509\n730 747\n504 497\n782 793",
"output": "4"
},
{
"input": "2\n802 903\n476 348",
"output": "1"
},
{
"input": "4\n325 343\n425 442\n785 798\n275 270",
"output": "3"
},
{
"input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653",
"output": "25"
},
{
"input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124",
"output": "34"
},
{
"input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255",
"output": "29"
},
{
"input": "5\n664 666\n951 941\n739 742\n844 842\n2 2",
"output": "4"
},
{
"input": "3\n939 867\n411 427\n757 708",
"output": "2"
},
{
"input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636",
"output": "34"
},
{
"input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195",
"output": "28"
},
{
"input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488",
"output": "22"
},
{
"input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235",
"output": "8"
},
{
"input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621",
"output": "22"
},
{
"input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461",
"output": "22"
},
{
"input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924",
"output": "6"
},
{
"input": "3\n1 1\n2 1\n2 2",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "5\n1 1\n1 2\n2 2\n3 1\n3 3",
"output": "0"
},
{
"input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3",
"output": "0"
},
{
"input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10",
"output": "1"
},
{
"input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11",
"output": "1"
},
{
"input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11",
"output": "3"
},
{
"input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25",
"output": "7"
},
{
"input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28",
"output": "5"
},
{
"input": "3\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n1 2",
"output": "0"
},
{
"input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4",
"output": "1"
},
{
"input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100",
"output": "6"
},
{
"input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "4\n3 1\n2 1\n2 2\n1 2",
"output": "0"
},
{
"input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "0"
},
{
"input": "4\n1 1\n2 2\n1 2\n2 1",
"output": "0"
},
{
"input": "4\n1 3\n2 1\n3 2\n3 1",
"output": "1"
},
{
"input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4",
"output": "0"
},
{
"input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700",
"output": "2"
},
{
"input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9",
"output": "1"
},
{
"input": "4\n1 1\n2 2\n3 2\n3 1",
"output": "0"
},
{
"input": "3\n1 2\n3 4\n3 2",
"output": "0"
},
{
"input": "3\n1 1\n1 2\n2 2",
"output": "0"
},
{
"input": "4\n5 5\n5 4\n6 3\n6 4",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n2 1",
"output": "0"
}
] | 1,549,188,347 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | def dfs(v):
global marked, g
marked[v] = True
for nv in g[v]:
if not marked[nv]:
dfs(nv)
n = int(input())
g = [[] for _ in range(n+1)]
x = [0 for _ in range(n+1)]
y = [0 for _ in range(n+1)]
marked = [False for _ in range(n+1)]
for i in range(1, n+1):
x[i], y[i] = map(int, input().split())
for j in range(1, i):
if (x[j] == x[i] and y[j] == y[i]):
g[i].append(j)
g[j].append(i)
cnt = 0
for i in range(1, n+1):
if not marked[i]:
dfs(i)
cnt+=1
print(cnt-1)
| Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input Specification:
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output Specification:
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Demo Input:
['2\n2 1\n1 2\n', '2\n2 1\n4 1\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
def dfs(v):
global marked, g
marked[v] = True
for nv in g[v]:
if not marked[nv]:
dfs(nv)
n = int(input())
g = [[] for _ in range(n+1)]
x = [0 for _ in range(n+1)]
y = [0 for _ in range(n+1)]
marked = [False for _ in range(n+1)]
for i in range(1, n+1):
x[i], y[i] = map(int, input().split())
for j in range(1, i):
if (x[j] == x[i] and y[j] == y[i]):
g[i].append(j)
g[j].append(i)
cnt = 0
for i in range(1, n+1):
if not marked[i]:
dfs(i)
cnt+=1
print(cnt-1)
``` | 0 |
|
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,674,008,422 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 171 | 2,867,200 | r,c=map(int,input().split())
l=[*range(1,55,4)]
for i in range(r):
for j in range(c):
if(i%2==0):
print("#",end="")
else:
if(i in l and j==c-1):
print("#",end="")
elif(i not in l and j==0):
print("#",end="")
else:
print(".",end="")
print()
| Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none | ```python
r,c=map(int,input().split())
l=[*range(1,55,4)]
for i in range(r):
for j in range(c):
if(i%2==0):
print("#",end="")
else:
if(i in l and j==c-1):
print("#",end="")
elif(i not in l and j==0):
print("#",end="")
else:
print(".",end="")
print()
``` | 3 |
|
268 | B | Buttons | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario. | A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. | In a single line print the number of times Manao has to push a button in the worst-case scenario. | [
"2\n",
"3\n"
] | [
"3\n",
"7\n"
] | Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "14"
},
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "175"
},
{
"input": "2000",
"output": "1333335000"
},
{
"input": "1747",
"output": "888644743"
},
{
"input": "889",
"output": "117099969"
},
{
"input": "1999",
"output": "1331335999"
},
{
"input": "914",
"output": "127259419"
},
{
"input": "996",
"output": "164675486"
},
{
"input": "17",
"output": "833"
},
{
"input": "50",
"output": "20875"
},
{
"input": "91",
"output": "125671"
},
{
"input": "92",
"output": "129858"
},
{
"input": "256",
"output": "2796416"
},
{
"input": "512",
"output": "22370048"
},
{
"input": "666",
"output": "49235271"
},
{
"input": "667",
"output": "49457383"
},
{
"input": "314",
"output": "5160119"
},
{
"input": "1241",
"output": "318541121"
},
{
"input": "1500",
"output": "562501250"
},
{
"input": "1837",
"output": "1033182073"
},
{
"input": "1000",
"output": "166667500"
}
] | 1,672,266,613 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n = int(input());print("1" if n=="1" else int(n*(n-1)*0.5 + (n-2)**2 + n))
| Title: Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
Output Specification:
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Demo Input:
['2\n', '3\n']
Demo Output:
['3\n', '7\n']
Note:
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | ```python
n = int(input());print("1" if n=="1" else int(n*(n-1)*0.5 + (n-2)**2 + n))
``` | 0 |
|
440 | B | Balancer | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configuration? | The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*. | Print the total minimum number of moves. | [
"6\n1 6 2 5 3 7\n"
] | [
"12\n"
] | none | 1,000 | [
{
"input": "6\n1 6 2 5 3 7",
"output": "12"
},
{
"input": "6\n6 6 6 0 0 0",
"output": "27"
},
{
"input": "6\n0 0 0 6 6 6",
"output": "27"
},
{
"input": "6\n6 6 0 0 6 6",
"output": "12"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "10\n0 100 0 100 0 100 0 100 0 100",
"output": "250"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "4\n0 0 0 0",
"output": "0"
},
{
"input": "2\n921 29111",
"output": "14095"
},
{
"input": "2\n0 1000000000",
"output": "500000000"
},
{
"input": "2\n291911 1",
"output": "145955"
},
{
"input": "2\n20180000 0",
"output": "10090000"
},
{
"input": "10\n10 9 7 13 7 5 13 15 10 11",
"output": "27"
},
{
"input": "100\n6 3 4 5 3 4 2 4 1 2 4 1 8 5 2 2 4 4 6 8 4 10 4 4 6 8 6 5 5 4 8 4 3 3 6 5 7 2 9 7 6 5 6 3 2 6 8 10 3 6 8 7 2 3 5 4 8 6 5 6 6 8 4 1 5 6 1 8 12 5 3 3 8 2 4 2 4 5 6 6 9 5 1 2 8 8 3 7 5 3 4 5 7 6 3 9 4 6 3 6",
"output": "867"
},
{
"input": "10\n1 1 1 1 1 999999999 999999999 999999999 999999999 999999999",
"output": "12499999975"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 1000000000",
"output": "4499999999"
},
{
"input": "14\n0 0 0 0 0 0 0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "24500000000"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999",
"output": "49999999900"
},
{
"input": "20\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 2 2 2 2 2 2 2 2 2 2",
"output": "49999999900"
}
] | 1,401,817,023 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 500 | 921,600 | n=int(input())
a=list(map(int,input().split()))
k=0
for i in range(n):
k+=a[i]
aver=k//n
h=0
x=0
y=1
while max(a)!=aver and min(a)!=aver:
if a[x]<aver:
d=aver-a[x]
h+=d
a[x]+=d
a[y]-=d
if a[x]>aver:
d=a[x]-aver
h+=d
a[x]-=d
a[y]+=d
x+=1
y+=1
print(h)
| Title: Balancer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configuration?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*.
Output Specification:
Print the total minimum number of moves.
Demo Input:
['6\n1 6 2 5 3 7\n']
Demo Output:
['12\n']
Note:
none | ```python
n=int(input())
a=list(map(int,input().split()))
k=0
for i in range(n):
k+=a[i]
aver=k//n
h=0
x=0
y=1
while max(a)!=aver and min(a)!=aver:
if a[x]<aver:
d=aver-a[x]
h+=d
a[x]+=d
a[y]-=d
if a[x]>aver:
d=a[x]-aver
h+=d
a[x]-=d
a[y]+=d
x+=1
y+=1
print(h)
``` | 0 |
|
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given *N*. | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
},
{
"input": "6",
"output": "12"
},
{
"input": "7",
"output": "16"
},
{
"input": "8",
"output": "20"
},
{
"input": "9",
"output": "25"
},
{
"input": "10",
"output": "30"
},
{
"input": "11",
"output": "36"
},
{
"input": "12",
"output": "42"
},
{
"input": "13",
"output": "49"
},
{
"input": "14",
"output": "56"
},
{
"input": "15",
"output": "64"
},
{
"input": "16",
"output": "72"
},
{
"input": "17",
"output": "81"
},
{
"input": "18",
"output": "90"
},
{
"input": "19",
"output": "100"
},
{
"input": "20",
"output": "110"
},
{
"input": "22",
"output": "132"
},
{
"input": "23",
"output": "144"
},
{
"input": "24",
"output": "156"
},
{
"input": "25",
"output": "169"
},
{
"input": "26",
"output": "182"
},
{
"input": "27",
"output": "196"
},
{
"input": "28",
"output": "210"
},
{
"input": "29",
"output": "225"
},
{
"input": "30",
"output": "240"
},
{
"input": "31",
"output": "256"
},
{
"input": "32",
"output": "272"
},
{
"input": "33",
"output": "289"
},
{
"input": "34",
"output": "306"
},
{
"input": "35",
"output": "324"
},
{
"input": "36",
"output": "342"
},
{
"input": "37",
"output": "361"
},
{
"input": "38",
"output": "380"
},
{
"input": "39",
"output": "400"
},
{
"input": "40",
"output": "420"
},
{
"input": "41",
"output": "441"
},
{
"input": "42",
"output": "462"
},
{
"input": "43",
"output": "484"
},
{
"input": "44",
"output": "506"
},
{
"input": "45",
"output": "529"
},
{
"input": "46",
"output": "552"
},
{
"input": "47",
"output": "576"
},
{
"input": "48",
"output": "600"
},
{
"input": "49",
"output": "625"
},
{
"input": "50",
"output": "650"
},
{
"input": "51",
"output": "676"
},
{
"input": "52",
"output": "702"
},
{
"input": "53",
"output": "729"
},
{
"input": "54",
"output": "756"
},
{
"input": "55",
"output": "784"
},
{
"input": "56",
"output": "812"
},
{
"input": "57",
"output": "841"
},
{
"input": "58",
"output": "870"
},
{
"input": "59",
"output": "900"
},
{
"input": "60",
"output": "930"
},
{
"input": "61",
"output": "961"
},
{
"input": "62",
"output": "992"
},
{
"input": "63",
"output": "1024"
},
{
"input": "64",
"output": "1056"
},
{
"input": "65",
"output": "1089"
},
{
"input": "66",
"output": "1122"
},
{
"input": "67",
"output": "1156"
},
{
"input": "68",
"output": "1190"
},
{
"input": "69",
"output": "1225"
},
{
"input": "70",
"output": "1260"
},
{
"input": "71",
"output": "1296"
},
{
"input": "72",
"output": "1332"
},
{
"input": "73",
"output": "1369"
},
{
"input": "74",
"output": "1406"
},
{
"input": "75",
"output": "1444"
},
{
"input": "76",
"output": "1482"
},
{
"input": "77",
"output": "1521"
},
{
"input": "78",
"output": "1560"
},
{
"input": "79",
"output": "1600"
},
{
"input": "80",
"output": "1640"
},
{
"input": "81",
"output": "1681"
},
{
"input": "82",
"output": "1722"
},
{
"input": "83",
"output": "1764"
},
{
"input": "84",
"output": "1806"
},
{
"input": "85",
"output": "1849"
},
{
"input": "86",
"output": "1892"
},
{
"input": "87",
"output": "1936"
},
{
"input": "88",
"output": "1980"
},
{
"input": "89",
"output": "2025"
},
{
"input": "90",
"output": "2070"
},
{
"input": "91",
"output": "2116"
},
{
"input": "92",
"output": "2162"
},
{
"input": "93",
"output": "2209"
},
{
"input": "94",
"output": "2256"
},
{
"input": "95",
"output": "2304"
},
{
"input": "96",
"output": "2352"
},
{
"input": "97",
"output": "2401"
},
{
"input": "98",
"output": "2450"
},
{
"input": "99",
"output": "2500"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
}
] | 1,641,496,192 | 592 | PyPy 3-64 | OK | TESTS | 102 | 108 | 0 | def process(n):
if n % 2==1:
return ((n+1)//2)**2
return (n//2)*(n//2+1)
n = int(input())
print(process(n))
| Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given *N*.
Input Specification:
The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100).
Output Specification:
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
Demo Input:
['2\n', '3\n', '4\n']
Demo Output:
['2\n', '4\n', '6\n']
Note:
As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | ```python
def process(n):
if n % 2==1:
return ((n+1)//2)**2
return (n//2)*(n//2+1)
n = int(input())
print(process(n))
``` | 3 |
|
452 | C | Magic Trick | PROGRAMMING | 2,100 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards.
The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.
You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case. | First line of the input consists of two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000), separated by space — number of cards in each deck, and number of decks. | On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10<=-<=6. | [
"2 2\n",
"4 4\n",
"1 2\n"
] | [
"0.6666666666666666\n",
"0.4000000000000000\n",
"1.0000000000000000\n"
] | In the first sample, with probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/64c94d13eeb330b494061e86538db66574ad0f7d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Alex will perform the trick with two cards with the same value from two different decks. In this case the trick is guaranteed to succeed.
With the remaining <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/14b21b617fcd2e25700376368355f7bbf975d8de.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability he took two different cards, and the probability of pulling off the trick is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb946338365d9781f7d2e9ec692c26702d0ae3a7.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
The resulting probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f54a03c9fa9df64ba08161730756d50b780a5f43.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 2",
"output": "0.6666666666666666"
},
{
"input": "4 4",
"output": "0.4000000000000000"
},
{
"input": "1 2",
"output": "1.0000000000000000"
},
{
"input": "2 1",
"output": "0.5000000000000000"
},
{
"input": "10 10",
"output": "0.1818181818181818"
},
{
"input": "1000 1000",
"output": "0.0019980019980020"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "987 123",
"output": "0.0020170953866492"
},
{
"input": "999 999",
"output": "0.0020000000000000"
},
{
"input": "1 999",
"output": "1.0000000000000000"
},
{
"input": "998 1",
"output": "0.0010020040080160"
},
{
"input": "2 987",
"output": "0.7498732894069944"
},
{
"input": "555 543",
"output": "0.0035970508143694"
},
{
"input": "321 123",
"output": "0.0061956542837219"
},
{
"input": "2 3",
"output": "0.7000000000000000"
},
{
"input": "461 1000",
"output": "0.0043315295751250"
},
{
"input": "678 231",
"output": "0.0029413109179425"
}
] | 1,600,573,348 | 2,147,483,647 | PyPy 3 | OK | TESTS | 17 | 155 | 1,638,400 | def cal(m,n,i):
tot=1
for j in range(1,n-i+1):
tot=tot*(n*m-m-n+i+j)/(n*m-n+i+j)
for j in range(1,i+1):
tot=tot*(m-i+j)/(n*m-n+j)
for j in range(1,i+1):
tot=tot/j*(n-i+j)
return tot
n,m = input().split()
n = int(n)
m = int(m)
ans = 0
for i in range(1, min(n,m)+1):
ans += i * i /n * cal(m,n,i)
print(ans)
| Title: Magic Trick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards.
The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.
You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case.
Input Specification:
First line of the input consists of two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000), separated by space — number of cards in each deck, and number of decks.
Output Specification:
On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10<=-<=6.
Demo Input:
['2 2\n', '4 4\n', '1 2\n']
Demo Output:
['0.6666666666666666\n', '0.4000000000000000\n', '1.0000000000000000\n']
Note:
In the first sample, with probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/64c94d13eeb330b494061e86538db66574ad0f7d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Alex will perform the trick with two cards with the same value from two different decks. In this case the trick is guaranteed to succeed.
With the remaining <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/14b21b617fcd2e25700376368355f7bbf975d8de.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability he took two different cards, and the probability of pulling off the trick is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb946338365d9781f7d2e9ec692c26702d0ae3a7.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
The resulting probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f54a03c9fa9df64ba08161730756d50b780a5f43.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
def cal(m,n,i):
tot=1
for j in range(1,n-i+1):
tot=tot*(n*m-m-n+i+j)/(n*m-n+i+j)
for j in range(1,i+1):
tot=tot*(m-i+j)/(n*m-n+j)
for j in range(1,i+1):
tot=tot/j*(n-i+j)
return tot
n,m = input().split()
n = int(n)
m = int(m)
ans = 0
for i in range(1, min(n,m)+1):
ans += i * i /n * cal(m,n,i)
print(ans)
``` | 3 |
|
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output": "No"
},
{
"input": "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC",
"output": "No"
},
{
"input": "1\nC",
"output": "No"
},
{
"input": "1\n?",
"output": "Yes"
},
{
"input": "2\nMY",
"output": "No"
},
{
"input": "2\n?M",
"output": "Yes"
},
{
"input": "2\nY?",
"output": "Yes"
},
{
"input": "2\n??",
"output": "Yes"
},
{
"input": "3\n??C",
"output": "Yes"
},
{
"input": "3\nM??",
"output": "Yes"
},
{
"input": "3\nYCM",
"output": "No"
},
{
"input": "3\n?C?",
"output": "Yes"
},
{
"input": "3\nMC?",
"output": "Yes"
},
{
"input": "4\nCYCM",
"output": "No"
},
{
"input": "4\nM?CM",
"output": "No"
},
{
"input": "4\n??YM",
"output": "Yes"
},
{
"input": "4\nC???",
"output": "Yes"
},
{
"input": "10\nMCYM?MYM?C",
"output": "Yes"
},
{
"input": "50\nCMCMCYM?MY?C?MC??YM?CY?YM??M?MCMCYCYMCYCMCM?MCM?MC",
"output": "Yes"
},
{
"input": "97\nMCM?YCMYM?YMY?MY?MYCY?CMCMCYC?YMY?MYCMC?M?YCMC?YM?C?MCMCMYMCMY?MCM?YC?YMYMY?MYCYCM?YC?YCY?MYMYMYC",
"output": "No"
},
{
"input": "100\nC?M?M?M?YM??YMYC?MCYMYM??Y??YC?CYC???YM?YM??MYMY?CYCYMYC?YC?C?CYCMY??CMC?YMCMYCYCYMYM?CYM?M?MCMCMY?Y",
"output": "Yes"
},
{
"input": "100\n?YYYYYYYYYYYYYYYYYYYYYYYYYYYYY??YYY?YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?",
"output": "No"
},
{
"input": "100\n????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "Yes"
},
{
"input": "100\nY?CYMYMYMYCYMY?CMCYMYMC?MYCY?CMCYCYMCM?YCMCYMYCYCY?MYMYCYCYCM?CYMYMY?CY?MYCYCY?M?YMYCY?CMCMCY?CY?M?C",
"output": "No"
},
{
"input": "4\nM??C",
"output": "Yes"
},
{
"input": "6\nY?C??C",
"output": "Yes"
},
{
"input": "5\nC???Y",
"output": "Yes"
},
{
"input": "5\nC??MY",
"output": "Yes"
},
{
"input": "5\nCY??M",
"output": "Yes"
},
{
"input": "4\nC??Y",
"output": "Yes"
},
{
"input": "52\n??????????????????????????????????????????????????YY",
"output": "No"
},
{
"input": "3\nYY?",
"output": "No"
},
{
"input": "5\nCC??Y",
"output": "No"
},
{
"input": "8\nCMC??MCM",
"output": "Yes"
},
{
"input": "7\nM?YCM??",
"output": "Yes"
},
{
"input": "6\n?CC???",
"output": "No"
},
{
"input": "100\n??????????????????????????????????????????????????????????????????????????????????????????????????MM",
"output": "No"
},
{
"input": "4\nC??M",
"output": "Yes"
},
{
"input": "4\n?C?M",
"output": "Yes"
},
{
"input": "6\nMC??MC",
"output": "Yes"
}
] | 1,672,573,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def solve():
n = int(input())
x = input()
if 'CC' in x:
return 'No'
if 'MM' in x:
return 'No'
if 'YY' in x:
return 'No'
for i in range(n):
if i > 0 and i < n - 1:
if x[i] == '?':
left = x[i-1]
right = x[i+1]
if left == right:
return 'Yes'
return 'No'
print(solve())
| Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
Output Specification:
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Demo Input:
['5\nCY??Y\n', '5\nC?C?Y\n', '5\n?CYC?\n', '5\nC??MM\n', '3\nMMY\n']
Demo Output:
['Yes\n', 'Yes\n', 'Yes\n', 'No\n', 'No\n']
Note:
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | ```python
def solve():
n = int(input())
x = input()
if 'CC' in x:
return 'No'
if 'MM' in x:
return 'No'
if 'YY' in x:
return 'No'
for i in range(n):
if i > 0 and i < n - 1:
if x[i] == '?':
left = x[i-1]
right = x[i+1]
if left == right:
return 'Yes'
return 'No'
print(solve())
``` | 0 |
|
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
{
"input": "8",
"output": "2 4 7 3 8 6 5"
},
{
"input": "9",
"output": "2 4 7 2 7 4 2 1"
},
{
"input": "2",
"output": "2"
},
{
"input": "11",
"output": "2 4 7 11 5 11 7 4 2 1"
},
{
"input": "12",
"output": "2 4 7 11 4 10 5 1 10 8 7"
},
{
"input": "13",
"output": "2 4 7 11 3 9 3 11 7 4 2 1"
},
{
"input": "20",
"output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11"
},
{
"input": "25",
"output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1"
},
{
"input": "30",
"output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16"
},
{
"input": "35",
"output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1"
},
{
"input": "40",
"output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21"
},
{
"input": "45",
"output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1"
},
{
"input": "50",
"output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26"
},
{
"input": "55",
"output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "60",
"output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31"
},
{
"input": "65",
"output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "70",
"output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36"
},
{
"input": "75",
"output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "80",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41"
},
{
"input": "85",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "90",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46"
},
{
"input": "95",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "96",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49"
},
{
"input": "97",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "98",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50"
},
{
"input": "99",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "100",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51"
}
] | 1,574,660,434 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 280 | 0 | n = int(input())
ls = [2]
for i in range(n-2):
m = (ls[i] + i+2)%n
if m == 0:
m = n
ls.append(m)
print(*ls)
| Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
Output Specification:
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
Demo Input:
['10\n', '3\n']
Demo Output:
['2 4 7 1 6 2 9 7 6\n', '2 1\n']
Note:
none | ```python
n = int(input())
ls = [2]
for i in range(n-2):
m = (ls[i] + i+2)%n
if m == 0:
m = n
ls.append(m)
print(*ls)
``` | 3.93 |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25",
"output": "840"
},
{
"input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44",
"output": "922"
},
{
"input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59",
"output": "674"
},
{
"input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82",
"output": "848"
},
{
"input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93",
"output": "902"
},
{
"input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20",
"output": "798"
},
{
"input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31",
"output": "632"
},
{
"input": "1\n4",
"output": "4"
},
{
"input": "2\n1 4",
"output": "4"
},
{
"input": "3\n1 2 4",
"output": "6"
},
{
"input": "2\n9 3",
"output": "12"
},
{
"input": "2\n1000000000 1001",
"output": "1000000000"
},
{
"input": "3\n1 8 4",
"output": "12"
},
{
"input": "3\n7 4 4",
"output": "8"
},
{
"input": "5\n2 3 4 5 3",
"output": "14"
},
{
"input": "2\n4 5",
"output": "4"
},
{
"input": "3\n2 4 5",
"output": "6"
},
{
"input": "3\n2 2 3",
"output": "4"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "4\n2 3 7 7",
"output": "16"
},
{
"input": "2\n999999999 2",
"output": "2"
},
{
"input": "2\n2 5",
"output": "2"
},
{
"input": "3\n5 3 1",
"output": "8"
},
{
"input": "4\n3 2 5 7",
"output": "14"
}
] | 1,624,346,058 | 2,147,483,647 | PyPy 3 | OK | TESTS | 87 | 187 | 10,956,800 | n=int(input())
s=0
m=100000000000
for i in map(int,input().split()):
s+=i
if(i%2!=0):m=min(i,m)
if(s%2!=0):s-=m
print(s) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
Input Specification:
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Output Specification:
Print the maximum possible even sum that can be obtained if we use some of the given integers.
Demo Input:
['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n']
Demo Output:
['6', '3999999996']
Note:
In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | ```python
n=int(input())
s=0
m=100000000000
for i in map(int,input().split()):
s+=i
if(i%2!=0):m=min(i,m)
if(s%2!=0):s-=m
print(s)
``` | 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,578,066,212 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 248 | 0 | n = int(input())
l = []
total = 0
for i in range(n):
l.append(list(map(int, input().split())))
for j in l:
for k in j:
total += k
if total == 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())
l = []
total = 0
for i in range(n):
l.append(list(map(int, input().split())))
for j in l:
for k in j:
total += k
if total == 0:
print("YES")
else:
print("NO")
``` | 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,719,385 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 78 | 7,065,600 | # cook your dish here
n, k, m, d = [int(x) for x in input().split()]
res = -1
for i in range(1,d+1):
iter = (i-1)*k + 1
max_x = n//iter
min_x = n//(i*k)
if min_x > m:
continue
if max_x > m:
res = max(res, i*m)
else:
res = max(res, i*max_x)
print(int(res)) | 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
# cook your dish here
n, k, m, d = [int(x) for x in input().split()]
res = -1
for i in range(1,d+1):
iter = (i-1)*k + 1
max_x = n//iter
min_x = n//(i*k)
if min_x > m:
continue
if max_x > m:
res = max(res, i*m)
else:
res = max(res, i*max_x)
print(int(res))
``` | 3 |
|
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,620,086,100 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | import math
x = int(input())
y = input().split()
a = y[0]
b = y[1]
c = y[2]
if (x == 3):
z0 = (math.pi*(int(b)*int(b)))-(math.pi*(int(c)*int(c)))+(math.pi(int(a)*int(a)))
print (z0)
elif (x == 2):
z1 = (math.pi*(int(b)*int(b)))+(math.pi(int(a)*int(a)))
print (z1)
else:
z2 = (math.pi*(int(a)*int(a)))
print (z2)
| 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
x = int(input())
y = input().split()
a = y[0]
b = y[1]
c = y[2]
if (x == 3):
z0 = (math.pi*(int(b)*int(b)))-(math.pi*(int(c)*int(c)))+(math.pi(int(a)*int(a)))
print (z0)
elif (x == 2):
z1 = (math.pi*(int(b)*int(b)))+(math.pi(int(a)*int(a)))
print (z1)
else:
z2 = (math.pi*(int(a)*int(a)))
print (z2)
``` | -1 |
|
678 | D | Iterated Linear Function | PROGRAMMING | 1,700 | [
"math",
"number theory"
] | null | null | Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. | The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement.
Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7. | [
"3 4 1 1\n",
"3 4 2 1\n",
"3 4 3 1\n"
] | [
"7\n",
"25\n",
"79\n"
] | none | 0 | [
{
"input": "3 4 1 1",
"output": "7"
},
{
"input": "3 4 2 1",
"output": "25"
},
{
"input": "3 4 3 1",
"output": "79"
},
{
"input": "1 1 1 1",
"output": "2"
},
{
"input": "3 10 723 6",
"output": "443623217"
},
{
"input": "14 81 51 82",
"output": "908370438"
},
{
"input": "826504481 101791432 76 486624528",
"output": "621999403"
},
{
"input": "475965351 844435993 96338 972382431",
"output": "83709654"
},
{
"input": "528774798 650132512 6406119 36569714",
"output": "505858307"
},
{
"input": "632656975 851906850 1 310973933",
"output": "230360736"
},
{
"input": "1 1 352875518515340737 1",
"output": "45212126"
},
{
"input": "978837295 606974665 846646545585165081 745145208",
"output": "154788991"
},
{
"input": "277677243 142088706 8846851 253942280",
"output": "221036825"
},
{
"input": "1 192783664 1000000000000000000 596438713",
"output": "42838179"
},
{
"input": "1 1000000000 1000000000000000000 1",
"output": "999999665"
},
{
"input": "1 1000000000 1000000000000000000 1000000000",
"output": "999999657"
},
{
"input": "1 100000000 10000000000000 1000000000",
"output": "48993"
},
{
"input": "1 1171281 1000000000000000000 100",
"output": "57392869"
},
{
"input": "1 1000000000 100000000000000000 1000000000",
"output": "899999965"
},
{
"input": "1 100000000 100000000000000000 10000",
"output": "490010000"
},
{
"input": "1 100000456 10000000000000000 54165",
"output": "129054389"
},
{
"input": "1 1000000000 10000000000000 1",
"output": "490001"
},
{
"input": "1 100000000 10000000000000000 10000",
"output": "49010000"
},
{
"input": "1 1000000000 10000000000 12",
"output": "502"
},
{
"input": "1 999999999 999999999999999999 12345678",
"output": "12345294"
},
{
"input": "1 1000000 1000000000000000000 100000",
"output": "49100000"
},
{
"input": "1 1000000000 1000000000000 12",
"output": "49012"
},
{
"input": "1 10000 1000000000000000000 5",
"output": "490005"
},
{
"input": "1 10000 1000000000000000000 10000",
"output": "500000"
},
{
"input": "1 1000000000 10000000000000 12",
"output": "490012"
},
{
"input": "1 1000000000 1000000000000000 12",
"output": "49000012"
},
{
"input": "1 1000000000 1000000000000000000 12",
"output": "999999676"
},
{
"input": "1 10000000 100000000000000000 100000",
"output": "49100000"
},
{
"input": "114514 114514 114514 114514",
"output": "623380685"
},
{
"input": "2 1 1000000006 1",
"output": "1"
},
{
"input": "1 1234 10 9",
"output": "12349"
}
] | 1,698,106,131 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 140 | 0 | # we are applying a linear function many times.
# multiplies 2 2x2 matrices and returns that
mod = 7+10**9
def matmul(a, b):
c = [[0,0],[0,0]]
for i in range(2):
for j in range(2):
for k in range(2):
c[i][j] += a[i][k] * b[k][j]
c[i][j] %= mod
return c
def binpow(a, n):
c = [[1,0],[0,1]]
while n != 0:
if (n&1):
c = matmul(a,c)
a = matmul(a,a)
n//=2
return c
A,B,n,x = [int(i) for i in input().split(" ")]
matDef = [[A,B],[0,1]]
matDef = binpow(matDef,n)
print((matDef[0][0] * x + matDef[0][1]) % mod)
| Title: Iterated Linear Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7.
Input Specification:
The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement.
Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output Specification:
Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7.
Demo Input:
['3 4 1 1\n', '3 4 2 1\n', '3 4 3 1\n']
Demo Output:
['7\n', '25\n', '79\n']
Note:
none | ```python
# we are applying a linear function many times.
# multiplies 2 2x2 matrices and returns that
mod = 7+10**9
def matmul(a, b):
c = [[0,0],[0,0]]
for i in range(2):
for j in range(2):
for k in range(2):
c[i][j] += a[i][k] * b[k][j]
c[i][j] %= mod
return c
def binpow(a, n):
c = [[1,0],[0,1]]
while n != 0:
if (n&1):
c = matmul(a,c)
a = matmul(a,a)
n//=2
return c
A,B,n,x = [int(i) for i in input().split(" ")]
matDef = [[A,B],[0,1]]
matDef = binpow(matDef,n)
print((matDef[0][0] * x + matDef[0][1]) % mod)
``` | 3 |
|
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "100 100 100",
"output": "300"
},
{
"input": "1 1 1",
"output": "2"
},
{
"input": "30 70 35",
"output": "130"
},
{
"input": "89 44 76",
"output": "208"
},
{
"input": "0 100 100",
"output": "200"
},
{
"input": "100 0 100",
"output": "200"
},
{
"input": "100 1 100",
"output": "200"
},
{
"input": "1 100 100",
"output": "200"
},
{
"input": "100 100 0",
"output": "200"
},
{
"input": "100 100 1",
"output": "200"
},
{
"input": "1 2 1",
"output": "4"
},
{
"input": "0 0 100",
"output": "100"
},
{
"input": "0 100 0",
"output": "0"
},
{
"input": "100 0 0",
"output": "0"
},
{
"input": "10 8 7",
"output": "24"
},
{
"input": "45 47 16",
"output": "108"
},
{
"input": "59 43 100",
"output": "202"
},
{
"input": "34 1 30",
"output": "62"
},
{
"input": "14 81 1",
"output": "30"
},
{
"input": "53 96 94",
"output": "242"
},
{
"input": "62 81 75",
"output": "218"
},
{
"input": "21 71 97",
"output": "188"
},
{
"input": "49 82 73",
"output": "204"
},
{
"input": "88 19 29",
"output": "96"
},
{
"input": "89 4 62",
"output": "132"
},
{
"input": "58 3 65",
"output": "126"
},
{
"input": "27 86 11",
"output": "76"
},
{
"input": "35 19 80",
"output": "134"
},
{
"input": "4 86 74",
"output": "156"
},
{
"input": "32 61 89",
"output": "182"
},
{
"input": "68 60 98",
"output": "226"
},
{
"input": "37 89 34",
"output": "142"
},
{
"input": "92 9 28",
"output": "74"
},
{
"input": "79 58 98",
"output": "234"
},
{
"input": "35 44 88",
"output": "166"
},
{
"input": "16 24 19",
"output": "58"
},
{
"input": "74 71 75",
"output": "220"
},
{
"input": "83 86 99",
"output": "268"
},
{
"input": "97 73 15",
"output": "176"
},
{
"input": "77 76 73",
"output": "226"
},
{
"input": "48 85 55",
"output": "188"
},
{
"input": "1 2 2",
"output": "4"
},
{
"input": "2 2 2",
"output": "6"
},
{
"input": "2 1 2",
"output": "4"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "3 2 1",
"output": "6"
},
{
"input": "1 2 3",
"output": "6"
},
{
"input": "1 3 2",
"output": "6"
},
{
"input": "2 1 3",
"output": "6"
},
{
"input": "2 3 1",
"output": "6"
},
{
"input": "3 1 2",
"output": "6"
},
{
"input": "99 99 99",
"output": "296"
},
{
"input": "99 99 100",
"output": "298"
},
{
"input": "99 100 99",
"output": "298"
},
{
"input": "99 100 100",
"output": "298"
},
{
"input": "100 99 99",
"output": "298"
},
{
"input": "100 99 100",
"output": "298"
},
{
"input": "100 100 99",
"output": "298"
},
{
"input": "89 32 23",
"output": "110"
},
{
"input": "4 5 0",
"output": "8"
},
{
"input": "3 0 3",
"output": "6"
},
{
"input": "0 0 2",
"output": "2"
},
{
"input": "97 97 0",
"output": "194"
},
{
"input": "1 4 0",
"output": "2"
},
{
"input": "5 2 0",
"output": "4"
},
{
"input": "0 5 10",
"output": "14"
},
{
"input": "0 1 2",
"output": "2"
},
{
"input": "5 2 3",
"output": "10"
},
{
"input": "5 5 0",
"output": "10"
},
{
"input": "0 0 10",
"output": "10"
},
{
"input": "0 1 1",
"output": "2"
},
{
"input": "0 0 1",
"output": "0"
}
] | 1,572,682,728 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | l,r,a=map(int,input().split())
if l+a<=r:
r=l+a
l=l+a
else:
x=a-l
y=a-r
l=l+x
r=r+y
if l==r==a:
if a%2==1:
a=a-1
a=a/2
l=l+a
r=r+a
else:
a=a/2
l=l+a
r=r+a
print(int(l+r)) | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
Input Specification:
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Output Specification:
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
Demo Input:
['1 4 2\n', '5 5 5\n', '0 2 0\n']
Demo Output:
['6\n', '14\n', '0\n']
Note:
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | ```python
l,r,a=map(int,input().split())
if l+a<=r:
r=l+a
l=l+a
else:
x=a-l
y=a-r
l=l+x
r=r+y
if l==r==a:
if a%2==1:
a=a-1
a=a/2
l=l+a
r=r+a
else:
a=a/2
l=l+a
r=r+a
print(int(l+r))
``` | 0 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"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, 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, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,687,527,055 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | values_str = input()
val = values_str.split(",")
new_list = []
for element in val:
if element not in new_list:
new_list.append(element)
values = new_list
new_list[0] = new_list[0].split("{")[1]
new_list[-1] = new_list[-1].split("}")[0]
myset = set(new_list)
print(len(myset)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
values_str = input()
val = values_str.split(",")
new_list = []
for element in val:
if element not in new_list:
new_list.append(element)
values = new_list
new_list[0] = new_list[0].split("{")[1]
new_list[-1] = new_list[-1].split("}")[0]
myset = set(new_list)
print(len(myset))
``` | 0 |
|
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit.
Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.
Sergey wrote certain values of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n10",
"output": "2"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "10\n0000000000",
"output": "1"
},
{
"input": "20\n11111111110110001100",
"output": "11"
},
{
"input": "50\n01011110100010000001010000100001001101001101101011",
"output": "1"
},
{
"input": "60\n111111111101111111111111111111111111111111111111111111111111",
"output": "11"
},
{
"input": "60\n111111111111111111111111111111111111111111111111111111111111",
"output": "60"
},
{
"input": "66\n111111010010011001110011000111000100011110011001111110011111111101",
"output": "7"
},
{
"input": "90\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "91\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "2"
},
{
"input": "92\n11111111101011111011111111111111111111111011101111111111011111111111111101111111101011111101",
"output": "10"
},
{
"input": "100\n0001011110100011001100100010111001000001111101101001001001001011110100101101010000000110100101110010",
"output": "1"
},
{
"input": "100\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "100"
},
{
"input": "100\n1011001110001000011111110011000100001110010110111101110110011011011000010100110001111100000010110010",
"output": "2"
},
{
"input": "100\n1101111011001111111111110011110111101110111111111111111111111111111111011111111111110111111111111111",
"output": "3"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "100"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110",
"output": "100"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101",
"output": "99"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000",
"output": "96"
},
{
"input": "100\n1111111111111111111111111111111110011000110110001010101100100100001000010010010010000100110000010101",
"output": "34"
}
] | 1,599,379,310 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 0 | n = int(input())
s = (input())
num = (s[::-1])
ans = 0
rem = 1
while num:
x = int(num)%10
num = num[:-1]
if x==1 and rem==1:
ans+=1
rem = 1
elif x==0 and rem==1:
ans += 1
rem = 0
else:
rem = 0
print(ans) | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit.
Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.
Sergey wrote certain values of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.
Output Specification:
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
Demo Input:
['4\n1100\n', '4\n1111\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample the cell ends up with value 0010, in the second sample — with 0000. | ```python
n = int(input())
s = (input())
num = (s[::-1])
ans = 0
rem = 1
while num:
x = int(num)%10
num = num[:-1]
if x==1 and rem==1:
ans+=1
rem = 1
elif x==0 and rem==1:
ans += 1
rem = 0
else:
rem = 0
print(ans)
``` | 3 |
|
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "10 10\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 2\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 1\nbbabbabbba",
"output": "6"
},
{
"input": "10 10\nbbabbbaabb",
"output": "10"
},
{
"input": "10 9\nbabababbba",
"output": "10"
},
{
"input": "10 4\nbababbaaab",
"output": "9"
},
{
"input": "10 10\naabaaabaaa",
"output": "10"
},
{
"input": "10 10\naaaabbbaaa",
"output": "10"
},
{
"input": "10 1\nbaaaaaaaab",
"output": "9"
},
{
"input": "10 5\naaaaabaaaa",
"output": "10"
},
{
"input": "10 4\naaaaaaaaaa",
"output": "10"
},
{
"input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100"
},
{
"input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab",
"output": "93"
},
{
"input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba",
"output": "100"
},
{
"input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb",
"output": "34"
},
{
"input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab",
"output": "100"
},
{
"input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba",
"output": "17"
},
{
"input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa",
"output": "80"
},
{
"input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa",
"output": "61"
},
{
"input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa",
"output": "76"
},
{
"input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa",
"output": "100"
},
{
"input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100"
},
{
"input": "10 0\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 0\nbbbbabbbbb",
"output": "5"
},
{
"input": "10 0\nbbabbbabba",
"output": "3"
},
{
"input": "10 0\nbaabbbbaba",
"output": "4"
},
{
"input": "10 0\naababbbbaa",
"output": "4"
},
{
"input": "10 2\nabbbbbaaba",
"output": "8"
},
{
"input": "10 0\nabbaaabaaa",
"output": "3"
},
{
"input": "10 0\naabbaaabaa",
"output": "3"
},
{
"input": "10 1\naaaaaababa",
"output": "8"
},
{
"input": "10 0\nbaaaaaaaaa",
"output": "9"
},
{
"input": "10 0\naaaaaaaaaa",
"output": "10"
},
{
"input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100"
},
{
"input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab",
"output": "40"
},
{
"input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb",
"output": "65"
},
{
"input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb",
"output": "33"
},
{
"input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab",
"output": "65"
},
{
"input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb",
"output": "26"
},
{
"input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba",
"output": "22"
},
{
"input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa",
"output": "49"
},
{
"input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa",
"output": "56"
},
{
"input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba",
"output": "86"
},
{
"input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100"
}
] | 1,676,915,274 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n, k = map(int, input().split())
s = input()
# n = len(s)
ans = 0
count = 0
r = 0
for i in range(n):
while r < n and count <= k:
if count == k and s[r] != 'a':
break
if s[r] != 'a':
count += 1
r += 1
# print(i, r)
ans = max(ans, r - i)
if s[i] != 'a':
count -= 1
print(ans)
| Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
Output Specification:
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
Demo Input:
['4 2\nabba\n', '8 1\naabaabaa\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | ```python
n, k = map(int, input().split())
s = input()
# n = len(s)
ans = 0
count = 0
r = 0
for i in range(n):
while r < n and count <= k:
if count == k and s[r] != 'a':
break
if s[r] != 'a':
count += 1
r += 1
# print(i, r)
ans = max(ans, r - i)
if s[i] != 'a':
count -= 1
print(ans)
``` | 0 |
|
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"input": "49152 0 0 0 0 81920",
"output": "No"
},
{
"input": "1 -1 4 4 2 -3",
"output": "No"
},
{
"input": "-2 -2 1 4 -2 0",
"output": "No"
},
{
"input": "5 0 4 -2 0 1",
"output": "No"
},
{
"input": "-4 -3 2 -1 -3 4",
"output": "No"
},
{
"input": "-3 -3 5 2 3 -1",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 0 1000000000 999999999",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 0 1000000000 1000000000",
"output": "No"
},
{
"input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564",
"output": "No"
},
{
"input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734",
"output": "No"
},
{
"input": "419578772 -125025887 169314071 89851312 961404059 21419450",
"output": "No"
},
{
"input": "-607353321 -620687860 248029390 477864359 728255275 -264646027",
"output": "No"
},
{
"input": "299948862 -648908808 338174789 841279400 -850322448 350263551",
"output": "No"
},
{
"input": "48517753 416240699 7672672 272460100 -917845051 199790781",
"output": "No"
},
{
"input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665",
"output": "No"
},
{
"input": "-685673792 -488079395 909733355 385950193 -705890324 256550506",
"output": "No"
},
{
"input": "-326038504 547872194 49630307 713863100 303770000 -556852524",
"output": "No"
},
{
"input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000",
"output": "Yes"
},
{
"input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000",
"output": "Yes"
},
{
"input": "-999999999 -1000000000 0 0 1000000000 999999999",
"output": "Yes"
},
{
"input": "-1000000000 -999999999 0 0 1000000000 999999999",
"output": "No"
},
{
"input": "-1 -1000000000 0 1000000000 1 -1000000000",
"output": "Yes"
},
{
"input": "0 1000000000 1 0 0 -1000000000",
"output": "Yes"
},
{
"input": "0 1000000000 0 0 0 -1000000000",
"output": "No"
},
{
"input": "0 1 1 2 2 3",
"output": "No"
},
{
"input": "999999999 1000000000 0 0 -1000000000 -999999999",
"output": "Yes"
},
{
"input": "0 0 1 1 2 0",
"output": "Yes"
},
{
"input": "0 0 1 1 2 2",
"output": "No"
},
{
"input": "1 1 2 2 3 3",
"output": "No"
},
{
"input": "0 2 0 3 0 4",
"output": "No"
},
{
"input": "1 1 1 2 1 3",
"output": "No"
},
{
"input": "0 0 3 4 3 9",
"output": "Yes"
},
{
"input": "589824 196608 262144 196608 0 0",
"output": "Yes"
},
{
"input": "0 0 1000000000 1 1000000000 -999999999",
"output": "No"
},
{
"input": "0 0 2 45 0 90",
"output": "Yes"
},
{
"input": "0 0 0 2 0 1",
"output": "No"
},
{
"input": "0 2 4 5 4 0",
"output": "Yes"
},
{
"input": "0 0 2 0 4 0",
"output": "No"
},
{
"input": "1 1 3 3 5 5",
"output": "No"
},
{
"input": "1 1 2 2 3 1",
"output": "Yes"
}
] | 1,514,012,140 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 5,529,600 | x1,y1,x2,y2,x3,y3=map(int,input().split())
if x1 == x2 and x1 == x3:
if y1 == (y2+y3)/2 or y2 == (y1+y3)/2 or y3 == (y2+y1)/2:
a = 1
else:
print('No')
exit(0)
if y1 == y2 and y1 == y3:
if x1 == (x2+x3)/2 or x2 == (x1+x3)/2 or x3 == (x2+x1)/2:
a = 1
else:
print('No')
exit(0)
m = (x1-x2)**2 + (y1-y2)**2
p = (x2-x3)**2 + (y2-y3)**2
q = (x1-x3)**2 + (y1-y3)**2
if m == p or m == q or p == q:
print('Yes')
exit(0)
print('No') | Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input Specification:
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Output Specification:
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | ```python
x1,y1,x2,y2,x3,y3=map(int,input().split())
if x1 == x2 and x1 == x3:
if y1 == (y2+y3)/2 or y2 == (y1+y3)/2 or y3 == (y2+y1)/2:
a = 1
else:
print('No')
exit(0)
if y1 == y2 and y1 == y3:
if x1 == (x2+x3)/2 or x2 == (x1+x3)/2 or x3 == (x2+x1)/2:
a = 1
else:
print('No')
exit(0)
m = (x1-x2)**2 + (y1-y2)**2
p = (x2-x3)**2 + (y2-y3)**2
q = (x1-x3)**2 + (y1-y3)**2
if m == p or m == q or p == q:
print('Yes')
exit(0)
print('No')
``` | 0 |
|
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
"output": "-1"
},
{
"input": "20",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "-1"
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "11",
"output": "-1"
},
{
"input": "21",
"output": "-1"
},
{
"input": "50",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 "
},
{
"input": "51",
"output": "-1"
},
{
"input": "52",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 "
},
{
"input": "84",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 "
},
{
"input": "86",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "33",
"output": "-1"
},
{
"input": "34",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 "
},
{
"input": "36",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 "
},
{
"input": "38",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 "
},
{
"input": "40",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 "
},
{
"input": "42",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 "
},
{
"input": "44",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 "
},
{
"input": "46",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 "
},
{
"input": "48",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 "
}
] | 1,696,005,412 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n = int(input())
arr = [0] * n
for i in range(n):
if i % 2 == 0:
arr[i] = i + 2
else:
arr[i] = i
if n != 1 and n % 2 == 0:
print(*arr)
else:
print(-1)
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
Input Specification:
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
Output Specification:
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
Demo Input:
['1\n', '2\n', '4\n']
Demo Output:
['-1\n', '2 1 \n', '2 1 4 3 \n']
Note:
none | ```python
n = int(input())
arr = [0] * n
for i in range(n):
if i % 2 == 0:
arr[i] = i + 2
else:
arr[i] = i
if n != 1 and n % 2 == 0:
print(*arr)
else:
print(-1)
``` | 3 |
|
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,680,971,746 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 810 | 0 | b=[]
def dfs(s):
depth=1
while s-1>=0:
depth+=1
s=b[s-1]
return depth
n=int(input())
for i in range(n):
b.append(int(input()))
m=1
for i in b:
p=dfs(i)
m=max(m,p)
print(m) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
b=[]
def dfs(s):
depth=1
while s-1>=0:
depth+=1
s=b[s-1]
return depth
n=int(input())
for i in range(n):
b.append(int(input()))
m=1
for i in b:
p=dfs(i)
m=max(m,p)
print(m)
``` | 3 |
|
198 | A | About Bacteria | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria.
The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point.
For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment.
Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment. | The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. | Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube. | [
"3 1 3 5\n",
"1 4 4 7\n",
"2 2 4 100\n"
] | [
"2",
"3",
"0"
] | none | 500 | [
{
"input": "3 1 3 5",
"output": "2"
},
{
"input": "1 4 4 7",
"output": "3"
},
{
"input": "2 2 4 100",
"output": "0"
},
{
"input": "1 2 3 100",
"output": "0"
},
{
"input": "10 10 10 123456",
"output": "6"
},
{
"input": "847 374 283 485756",
"output": "282"
},
{
"input": "37 1 283475 8347",
"output": "283473"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 1 1 1000000",
"output": "0"
},
{
"input": "1 1 1000000 1",
"output": "1000000"
},
{
"input": "1 1 1000000 1000000",
"output": "1"
},
{
"input": "1 1000000 1 1",
"output": "1"
},
{
"input": "1 1000000 1 1000000",
"output": "1"
},
{
"input": "1 1000000 1000000 1",
"output": "1000000"
},
{
"input": "1 1000000 1000000 1000000",
"output": "1000000"
},
{
"input": "1000000 1 1 1",
"output": "1"
},
{
"input": "1000000 1 1 1000000",
"output": "1"
},
{
"input": "1000000 1 1000000 1",
"output": "1000000"
},
{
"input": "1000000 1 1000000 1000000",
"output": "1000000"
},
{
"input": "1000000 1000000 1 1",
"output": "1"
},
{
"input": "1000000 1000000 1 1000000",
"output": "1"
},
{
"input": "1000000 1000000 1000000 1",
"output": "1000000"
},
{
"input": "1000000 1000000 1000000 1000000",
"output": "1000000"
},
{
"input": "1 160 748 108",
"output": "748"
},
{
"input": "1 6099 4415 2783",
"output": "4415"
},
{
"input": "1 1047 230 1199",
"output": "229"
},
{
"input": "1 82435 53193 37909",
"output": "53193"
},
{
"input": "1 96840 99008 63621",
"output": "99008"
},
{
"input": "1 250685 823830 494528",
"output": "823829"
},
{
"input": "1 421986 2348 320240",
"output": "2348"
},
{
"input": "2 8 16 397208",
"output": "1"
},
{
"input": "2 96 676 215286",
"output": "665"
},
{
"input": "2 575 321 606104",
"output": "311"
},
{
"input": "2 8048 37852 278843",
"output": "37847"
},
{
"input": "2 46658 377071 909469",
"output": "377067"
},
{
"input": "3 10 90 567680",
"output": "80"
},
{
"input": "4 4 149 609208",
"output": "141"
},
{
"input": "5 4 3204 986907",
"output": "3196"
},
{
"input": "6 5 5832 885406",
"output": "5825"
},
{
"input": "7 10 141725 219601",
"output": "141720"
},
{
"input": "38 86 441826 91486",
"output": "441824"
},
{
"input": "185 58 579474 889969",
"output": "579472"
},
{
"input": "3901 18 41607 412558",
"output": "41606"
},
{
"input": "9821 62 965712 703044",
"output": "965711"
},
{
"input": "29487 60 3239 483550",
"output": "3238"
},
{
"input": "78993 99 646044 456226",
"output": "646043"
},
{
"input": "193877 3 362586 6779",
"output": "362586"
},
{
"input": "702841 39 622448 218727",
"output": "622448"
},
{
"input": "987899 74 490126 87643",
"output": "490126"
},
{
"input": "1000000 69 296123 144040",
"output": "296123"
},
{
"input": "2 5 501022 406855",
"output": "501006"
},
{
"input": "2 2 420084 748919",
"output": "420067"
},
{
"input": "2 3 822794 574631",
"output": "822777"
},
{
"input": "2 2 968609 433047",
"output": "968592"
},
{
"input": "2 1 371319 775111",
"output": "371301"
},
{
"input": "3 2 942777 573452",
"output": "942766"
},
{
"input": "3 2 312783 882812",
"output": "312772"
},
{
"input": "3 4 715494 741228",
"output": "715483"
},
{
"input": "3 1 410364 566940",
"output": "410353"
},
{
"input": "3 2 780370 425356",
"output": "780359"
},
{
"input": "1 5 71 551204",
"output": "0"
},
{
"input": "1 10 29 409620",
"output": "0"
},
{
"input": "2 1 14 637985",
"output": "0"
},
{
"input": "2 6 73 947345",
"output": "56"
},
{
"input": "3 8 66 951518",
"output": "55"
},
{
"input": "3 3 24 293582",
"output": "14"
},
{
"input": "4 9 10 489244",
"output": "2"
},
{
"input": "4 6 16 831308",
"output": "7"
},
{
"input": "5 6 62 835481",
"output": "55"
},
{
"input": "5 2 68 144841",
"output": "61"
},
{
"input": "1 1 1000000 500000",
"output": "500001"
},
{
"input": "5 2 100 7",
"output": "99"
},
{
"input": "3 1 3 4",
"output": "2"
},
{
"input": "126480 295416 829274 421896",
"output": "829273"
},
{
"input": "999991 5 1000000 999997",
"output": "999999"
},
{
"input": "54772 1 1000000 1000000",
"output": "999999"
},
{
"input": "5 5 2 10",
"output": "1"
},
{
"input": "1 1 2 2",
"output": "1"
},
{
"input": "100000 100000 10 1000000",
"output": "9"
},
{
"input": "2 2 5 4",
"output": "4"
},
{
"input": "999997 1 100000 1000000",
"output": "99999"
},
{
"input": "5 2 100 38",
"output": "98"
},
{
"input": "1 4 1 5",
"output": "0"
},
{
"input": "1 2149 1000000 1000000",
"output": "999535"
},
{
"input": "99999 99999 10 1000000",
"output": "9"
},
{
"input": "999998 1 1000000 1000000",
"output": "999999"
},
{
"input": "1 1 10 2",
"output": "9"
},
{
"input": "1 1 100 1000",
"output": "0"
},
{
"input": "1 1 1000000 553211",
"output": "446790"
},
{
"input": "1 1 10 1",
"output": "10"
},
{
"input": "3 1 3 1",
"output": "3"
},
{
"input": "888888 2 4 999999",
"output": "3"
},
{
"input": "3 5 10 29",
"output": "8"
},
{
"input": "1 1 100 2",
"output": "99"
},
{
"input": "5 5 2 1",
"output": "2"
},
{
"input": "50000 42 1337 999999",
"output": "1336"
},
{
"input": "2 345678 908765 987654",
"output": "908764"
},
{
"input": "1 7 15 7",
"output": "15"
},
{
"input": "842717 8581 19342 851297",
"output": "19342"
},
{
"input": "5 4 1 4",
"output": "1"
},
{
"input": "2 2 5 94",
"output": "0"
},
{
"input": "2 100000 5 10",
"output": "5"
},
{
"input": "722229 410423 118215 838505",
"output": "118215"
},
{
"input": "3 1 3 13",
"output": "1"
},
{
"input": "900000 1 100 1000000",
"output": "99"
},
{
"input": "2 4 4 36",
"output": "1"
},
{
"input": "999990 1 1000000 1000000",
"output": "999999"
},
{
"input": "100000 100000 1000000 1000000",
"output": "999999"
},
{
"input": "999998 1 5 1000000",
"output": "4"
},
{
"input": "1 1 10 4",
"output": "7"
},
{
"input": "2 3 4 5",
"output": "3"
},
{
"input": "3 1 3 40",
"output": "0"
},
{
"input": "1 10 10 100",
"output": "1"
},
{
"input": "999987 123456 1000000 1",
"output": "1000000"
}
] | 1,690,062,627 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 10,240,000 | k, b, n, t = map(int,input().split())
val, ct = 1, 0
for i in range(n) :
val *= k
val += b
while t < val :
t *= k
t += b
ct += 1
print(ct) | Title: About Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria.
The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point.
For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment.
Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment.
Input Specification:
The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.
Output Specification:
Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube.
Demo Input:
['3 1 3 5\n', '1 4 4 7\n', '2 2 4 100\n']
Demo Output:
['2', '3', '0']
Note:
none | ```python
k, b, n, t = map(int,input().split())
val, ct = 1, 0
for i in range(n) :
val *= k
val += b
while t < val :
t *= k
t += b
ct += 1
print(ct)
``` | 0 |
|
166 | A | Rank List | PROGRAMMING | 1,100 | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*t**b*.
It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place.
Your task is to count what number of teams from the given list shared the *k*-th place. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
- 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1
The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | 500 | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2",
"output": "1"
},
{
"input": "3 2\n3 3\n3 3\n3 3",
"output": "3"
},
{
"input": "4 3\n10 3\n6 10\n5 2\n5 2",
"output": "2"
},
{
"input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3",
"output": "3"
},
{
"input": "3 1\n2 1\n1 1\n1 2",
"output": "1"
},
{
"input": "1 1\n28 28",
"output": "1"
},
{
"input": "2 2\n1 2\n1 2",
"output": "2"
},
{
"input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5",
"output": "1"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8",
"output": "1"
},
{
"input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10",
"output": "1"
},
{
"input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "50"
},
{
"input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2",
"output": "13"
},
{
"input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2",
"output": "5"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3",
"output": "1"
},
{
"input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2",
"output": "1"
},
{
"input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6",
"output": "1"
},
{
"input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1",
"output": "3"
},
{
"input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "20"
},
{
"input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2",
"output": "6"
},
{
"input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "30"
},
{
"input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1",
"output": "13"
},
{
"input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1",
"output": "5"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3",
"output": "1"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8",
"output": "1"
},
{
"input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14",
"output": "1"
},
{
"input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30",
"output": "2"
},
{
"input": "2 1\n50 50\n50 50",
"output": "2"
},
{
"input": "2 2\n50 50\n50 50",
"output": "2"
},
{
"input": "2 1\n50 50\n50 49",
"output": "1"
},
{
"input": "2 2\n50 50\n50 49",
"output": "1"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50",
"output": "50"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50",
"output": "1"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49",
"output": "49"
},
{
"input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4",
"output": "1"
},
{
"input": "4 3\n1 1\n1 2\n2 1\n2 2",
"output": "1"
},
{
"input": "4 2\n1 2\n1 3\n1 5\n1 2",
"output": "2"
},
{
"input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3",
"output": "1"
},
{
"input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1",
"output": "2"
},
{
"input": "3 1\n1 1\n1 2\n1 3",
"output": "1"
},
{
"input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4",
"output": "4"
},
{
"input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5",
"output": "2"
},
{
"input": "4 1\n1 1\n1 1\n1 2\n1 3",
"output": "2"
}
] | 1,660,967,484 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n, k = [int(i) for i in input().split()]
scores = []
for _ in range(n):
p,t = [int(i) for i in input().split()]
scores.append([p,t])
scores.sort(key= lambda x: x[1])
scores.sort(key = lambda x: x[0], reverse=True)
res = 0
for i in scores:
if i == scores[k]:
res +=1
print(res)
| Title: Rank List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*t**b*.
It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place.
Your task is to count what number of teams from the given list shared the *k*-th place.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
Output Specification:
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
Demo Input:
['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n']
Demo Output:
['3\n', '4\n']
Note:
The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
- 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1
The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | ```python
n, k = [int(i) for i in input().split()]
scores = []
for _ in range(n):
p,t = [int(i) for i in input().split()]
scores.append([p,t])
scores.sort(key= lambda x: x[1])
scores.sort(key = lambda x: x[0], reverse=True)
res = 0
for i in scores:
if i == scores[k]:
res +=1
print(res)
``` | 0 |
|
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,649,077,429 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 3,379,200 | # coding=utf-8
t=int(input())
for i in range(t):
x=int(input())
s=0
turn=1
while x>0:
if x%2==1:
if turn==1:
s+=1
turn=0
else:
turn=1
x-=1
else:
if x%4==0:
if x//4==1:
if turn==1:
s+=x//2
turn=0
else:
turn=1
x=x//2
else:
if turn==1:
s+=1
turn=0
else:
turn=1
x-=1
else:
if turn==1:
s+=x//2
turn=0
else:
turn=1
x=x//2
print(s)
| Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
# coding=utf-8
t=int(input())
for i in range(t):
x=int(input())
s=0
turn=1
while x>0:
if x%2==1:
if turn==1:
s+=1
turn=0
else:
turn=1
x-=1
else:
if x%4==0:
if x//4==1:
if turn==1:
s+=x//2
turn=0
else:
turn=1
x=x//2
else:
if turn==1:
s+=1
turn=0
else:
turn=1
x-=1
else:
if turn==1:
s+=x//2
turn=0
else:
turn=1
x=x//2
print(s)
``` | -1 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,689,522,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a, b = map(int, input().split())
min_days = min(a, b)
same_socks_days = max(a, b) - min_days
print(min_days, same_socks_days) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
a, b = map(int, input().split())
min_days = min(a, b)
same_socks_days = max(a, b) - min_days
print(min_days, same_socks_days)
``` | 0 |
|
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4",
"output": "Chris"
},
{
"input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4",
"output": "Friendship is magic!^^"
},
{
"input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3",
"output": "Mishka"
},
{
"input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6",
"output": "Friendship is magic!^^"
},
{
"input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2",
"output": "Mishka"
},
{
"input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4",
"output": "Chris"
},
{
"input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1",
"output": "Mishka"
},
{
"input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4",
"output": "Chris"
},
{
"input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6",
"output": "Chris"
},
{
"input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1",
"output": "Mishka"
},
{
"input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4",
"output": "Friendship is magic!^^"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4",
"output": "Chris"
},
{
"input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4",
"output": "Mishka"
},
{
"input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3",
"output": "Mishka"
},
{
"input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5",
"output": "Chris"
},
{
"input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3",
"output": "Chris"
},
{
"input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6",
"output": "Mishka"
},
{
"input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2",
"output": "Mishka"
},
{
"input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1",
"output": "Chris"
},
{
"input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2",
"output": "Chris"
},
{
"input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 1,691,789,030 | 2,147,483,647 | PyPy 3 | OK | TESTS | 69 | 93 | 0 | # Read the number of game rounds
n = int(input())
# Initialize counters for Mishka and Chris
mishka_wins = 0
chris_wins = 0
# Process each round
for _ in range(n):
# Read the values on dice upper face for Mishka and Chris
mi, ci = map(int, input().split())
# Compare the values and update the counters
if mi > ci:
mishka_wins += 1
elif ci > mi:
chris_wins += 1
# Determine the result of the game
if mishka_wins > chris_wins:
print("Mishka")
elif chris_wins > mishka_wins:
print("Chris")
else:
print("Friendship is magic!^^")
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | ```python
# Read the number of game rounds
n = int(input())
# Initialize counters for Mishka and Chris
mishka_wins = 0
chris_wins = 0
# Process each round
for _ in range(n):
# Read the values on dice upper face for Mishka and Chris
mi, ci = map(int, input().split())
# Compare the values and update the counters
if mi > ci:
mishka_wins += 1
elif ci > mi:
chris_wins += 1
# Determine the result of the game
if mishka_wins > chris_wins:
print("Mishka")
elif chris_wins > mishka_wins:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 |
|
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day. | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"output": "19"
},
{
"input": "10 9",
"output": "11"
},
{
"input": "100 100",
"output": "101"
},
{
"input": "2 27",
"output": "2"
},
{
"input": "99 100",
"output": "99"
},
{
"input": "99 2",
"output": "197"
},
{
"input": "100 3",
"output": "149"
},
{
"input": "98 3",
"output": "146"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 2",
"output": "199"
},
{
"input": "62 4",
"output": "82"
},
{
"input": "99 10",
"output": "109"
},
{
"input": "100 5",
"output": "124"
},
{
"input": "80 80",
"output": "81"
},
{
"input": "95 16",
"output": "101"
},
{
"input": "75 16",
"output": "79"
},
{
"input": "99 74",
"output": "100"
},
{
"input": "20 21",
"output": "20"
},
{
"input": "52 96",
"output": "52"
},
{
"input": "24 5",
"output": "29"
}
] | 1,641,484,648 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | n,m=map(int, input().split())
s=n
while (n//m)>=1:
s+=(n//m)
n=((n//m)+(n%m))
print(s) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
Input Specification:
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['2 2\n', '9 3\n']
Demo Output:
['3\n', '13\n']
Note:
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day. | ```python
n,m=map(int, input().split())
s=n
while (n//m)>=1:
s+=(n//m)
n=((n//m)+(n%m))
print(s)
``` | 3 |
|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,694,725,228 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | rounds = int(input())
andrew = 0
mike = 0
crnt = ''
for x in range(rounds):
a = str.split(input(), " ")
name = a[0]
score = int(a[1])
if name == "andrew":
andrew += score
else:
mike += score
if andrew > mike:
crnt = 'andrew'
elif andrew < mike:
crnt = 'mike'
print(crnt) | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
rounds = int(input())
andrew = 0
mike = 0
crnt = ''
for x in range(rounds):
a = str.split(input(), " ")
name = a[0]
score = int(a[1])
if name == "andrew":
andrew += score
else:
mike += score
if andrew > mike:
crnt = 'andrew'
elif andrew < mike:
crnt = 'mike'
print(crnt)
``` | 0 |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner. | The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* — the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "100 99 56",
"output": "85"
},
{
"input": "1000 1000 1002",
"output": "1000"
},
{
"input": "0 1 1000000000",
"output": "1"
},
{
"input": "500000000 1000000000 500000000",
"output": "666666666"
},
{
"input": "1000000000 2000000000 1000000000",
"output": "1333333333"
},
{
"input": "2000000000 2000000000 2000000000",
"output": "2000000000"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "1 2000000000 1000000000",
"output": "1000000000"
},
{
"input": "1585222789 1889821127 2000000000",
"output": "1825014638"
},
{
"input": "10000 7500 7500",
"output": "8333"
},
{
"input": "150000 75000 75000",
"output": "100000"
},
{
"input": "999288131 55884921 109298382",
"output": "165183303"
},
{
"input": "100500 100500 3",
"output": "67001"
},
{
"input": "1463615122 1988383731 837331500",
"output": "1429776784"
},
{
"input": "1938 8999 1882",
"output": "3820"
},
{
"input": "45 33 76",
"output": "51"
},
{
"input": "100000 1 2",
"output": "3"
},
{
"input": "198488 50 18",
"output": "68"
},
{
"input": "82728372 939848 100139442",
"output": "61269220"
},
{
"input": "99 5747 5298",
"output": "3714"
},
{
"input": "3 5 2",
"output": "3"
},
{
"input": "7511 7512 7513",
"output": "7512"
},
{
"input": "1234567890 123456789 987654321",
"output": "781893000"
},
{
"input": "500000000 2000000000 500000000",
"output": "1000000000"
},
{
"input": "500000002 2000000000 500000001",
"output": "1000000001"
},
{
"input": "520000000 1000000033 501000000",
"output": "673666677"
},
{
"input": "10000 1000 100000",
"output": "11000"
},
{
"input": "2000000000 500000000 499999999",
"output": "999999999"
},
{
"input": "1999999999 500000000 500000000",
"output": "999999999"
},
{
"input": "1 1 9",
"output": "2"
},
{
"input": "3 0 0",
"output": "0"
},
{
"input": "6 1 1",
"output": "2"
},
{
"input": "2000000000 1999999999 1999999999",
"output": "1999999999"
},
{
"input": "3 4 9",
"output": "5"
},
{
"input": "3 3 6",
"output": "4"
}
] | 1,671,362,475 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 46 | 0 | import sys
input = sys.stdin.readline
A = list(map(int, input().split()))
ans = 0
if max(A)-min(A) <=1:
print(sum(A)//3)
else:
S = A[1]+A[2]
ans += A[0]
S -= 2*A[0]
ans += S//3
print(ans) | Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner.
Input Specification:
The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Output Specification:
Print a single integer *t* — the maximum number of tables that can be decorated in the required manner.
Demo Input:
['5 4 3\n', '1 1 1\n', '2 3 3\n']
Demo Output:
['4\n', '1\n', '2\n']
Note:
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | ```python
import sys
input = sys.stdin.readline
A = list(map(int, input().split()))
ans = 0
if max(A)-min(A) <=1:
print(sum(A)//3)
else:
S = A[1]+A[2]
ans += A[0]
S -= 2*A[0]
ans += S//3
print(ans)
``` | 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*<=><=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,698,487,568 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | x= int(input())
steps = x // 5
if x %5 != 0:
steps +=1
print(steps) | 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*<=><=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
x= int(input())
steps = x // 5
if x %5 != 0:
steps +=1
print(steps)
``` | 3 |
|
815 | A | Karen and Game | PROGRAMMING | 1,700 | [
"brute force",
"greedy",
"implementation"
] | null | null | On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.
To win the level, after all the moves, the number in the cell at the *i*-th row and *j*-th column should be equal to *g**i*,<=*j*.
Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! | The first line of input contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of rows and the number of columns in the grid, respectively.
The next *n* lines each contain *m* integers. In particular, the *j*-th integer in the *i*-th of these rows contains *g**i*,<=*j* (0<=≤<=*g**i*,<=*j*<=≤<=500). | If there is an error and it is actually not possible to beat the level, output a single integer -1.
Otherwise, on the first line, output a single integer *k*, the minimum number of moves necessary to beat the level.
The next *k* lines should each contain one of the following, describing the moves in the order they must be done:
- row *x*, (1<=≤<=*x*<=≤<=*n*) describing a move of the form "choose the *x*-th row". - col *x*, (1<=≤<=*x*<=≤<=*m*) describing a move of the form "choose the *x*-th column".
If there are multiple optimal solutions, output any one of them. | [
"3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1\n",
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"3 3\n1 1 1\n1 1 1\n1 1 1\n"
] | [
"4\nrow 1\nrow 1\ncol 4\nrow 3\n",
"-1\n",
"3\nrow 1\nrow 2\nrow 3\n"
] | In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:
In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.
In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level:
Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3. | 500 | [
{
"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1",
"output": "4\nrow 1\nrow 1\ncol 4\nrow 3"
},
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "-1"
},
{
"input": "3 3\n1 1 1\n1 1 1\n1 1 1",
"output": "3\nrow 1\nrow 2\nrow 3"
},
{
"input": "3 5\n2 4 2 2 3\n0 2 0 0 1\n1 3 1 1 2",
"output": "6\nrow 1\nrow 1\ncol 2\ncol 2\ncol 5\nrow 3"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "-1"
},
{
"input": "9 10\n14 5 6 4 8 9 4 14 14 13\n13 4 5 3 7 8 3 13 13 12\n16 7 8 6 10 11 6 16 16 15\n10 1 2 0 4 5 0 10 10 9\n11 2 3 1 5 6 1 11 11 10\n10 1 2 0 4 5 0 10 10 9\n12 3 4 2 6 7 2 12 12 11\n13 4 5 3 7 8 3 13 13 12\n13 4 5 3 7 8 3 13 13 12",
"output": "73\nrow 1\nrow 1\nrow 1\nrow 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 2\ncol 3\ncol 3\ncol 5\ncol 5\ncol 5\ncol 5\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 8\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\ncol 10\nrow 2\nrow 2\nrow 2\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 3\nrow 5\nrow 7\nrow 7\nrow 8\nrow 8\nrow 8\nrow 9\nr..."
},
{
"input": "10 10\n30 30 30 33 30 33 30 33 30 33\n431 431 431 434 431 434 431 434 431 434\n19 19 19 22 19 22 19 22 19 22\n24 24 24 27 24 27 24 27 24 27\n5 5 5 8 5 8 5 8 5 8\n0 0 0 3 0 3 0 3 0 3\n0 0 0 3 0 3 0 3 0 3\n0 0 0 3 0 3 0 3 0 3\n0 0 0 3 0 3 0 3 0 3\n0 0 0 3 0 3 0 3 0 3",
"output": "521\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\ncol 4\ncol 4\ncol 4\ncol 6\ncol 6\ncol 6\ncol 8\ncol 8\ncol 8\ncol 10\ncol 10\ncol 10\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\n..."
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n500",
"output": "500\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nro..."
},
{
"input": "10 10\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1",
"output": "9\nrow 1\nrow 2\nrow 3\nrow 4\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10"
},
{
"input": "10 10\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 0 1 1 1",
"output": "9\ncol 1\ncol 2\ncol 3\ncol 4\ncol 5\ncol 6\ncol 8\ncol 9\ncol 10"
},
{
"input": "10 11\n8 7 10 15 5 13 12 9 14 11 6\n6 5 8 13 3 11 10 7 12 9 4\n10 9 12 17 7 15 14 11 16 13 8\n9 8 11 16 6 14 13 10 15 12 7\n12 11 14 19 9 17 16 13 18 15 10\n14 13 16 21 11 19 18 15 20 17 12\n7 6 9 14 4 12 11 8 13 10 5\n5 4 7 12 2 10 9 6 11 8 3\n11 10 13 18 8 16 15 12 17 14 9\n13 12 15 20 10 18 17 14 19 16 11",
"output": "120\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 1\nrow 1\ncol 1\ncol 1\ncol 1\ncol 2\ncol 2\ncol 3\ncol 3\ncol 3\ncol 3\ncol 3\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 4\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 6\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 7\ncol 8\ncol 8\ncol 8\ncol 8\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 9\ncol 10\n..."
},
{
"input": "5 3\n2 2 2\n2 2 2\n2 2 2\n1 1 1\n2 2 2",
"output": "7\ncol 1\ncol 2\ncol 3\nrow 1\nrow 2\nrow 3\nrow 5"
},
{
"input": "3 5\n2 2 2 1 2\n2 2 2 1 2\n2 2 2 1 2",
"output": "7\nrow 1\nrow 2\nrow 3\ncol 1\ncol 2\ncol 3\ncol 5"
},
{
"input": "1 100\n396 314 350 362 287 349 266 289 297 305 235 226 256 385 302 304 253 192 298 238 360 366 163 340 247 395 318 260 252 281 178 188 252 379 212 187 354 232 225 159 290 335 387 234 383 215 356 182 323 280 195 209 263 215 322 262 334 157 189 214 195 386 220 209 177 193 368 174 270 329 388 237 260 343 230 173 254 371 327 266 193 178 161 209 335 310 323 323 353 172 368 307 329 234 363 264 334 266 305 209",
"output": "11960\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\n..."
},
{
"input": "100 1\n173\n164\n99\n114\n255\n223\n280\n235\n207\n190\n136\n204\n206\n282\n253\n335\n267\n184\n288\n299\n263\n243\n341\n111\n278\n111\n214\n133\n125\n245\n99\n144\n232\n203\n131\n204\n117\n315\n269\n206\n262\n125\n212\n95\n220\n243\n141\n163\n311\n171\n222\n266\n141\n314\n329\n138\n187\n342\n272\n181\n300\n261\n339\n110\n194\n187\n183\n129\n151\n187\n129\n185\n322\n167\n99\n340\n285\n99\n176\n175\n272\n126\n220\n164\n237\n214\n96\n162\n129\n141\n144\n135\n172\n191\n155\n333\n186\n324\n237\n318",
"output": "11282\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\n..."
},
{
"input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "0"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1\nrow 1"
},
{
"input": "100 1\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\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\n1\n1\n1\n1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "1 100\n500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500",
"output": "500\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nro..."
},
{
"input": "100 1\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500\n500",
"output": "500\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\nco..."
},
{
"input": "2 1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "4 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "3\ncol 1\ncol 2\ncol 3"
},
{
"input": "2 1\n2\n2",
"output": "2\ncol 1\ncol 1"
},
{
"input": "3 2\n1 1\n1 1\n1 1",
"output": "2\ncol 1\ncol 2"
},
{
"input": "2 1\n1\n2",
"output": "2\ncol 1\nrow 2"
},
{
"input": "2 3\n1 1 1\n1 1 1",
"output": "2\nrow 1\nrow 2"
},
{
"input": "1 2\n1 1",
"output": "1\nrow 1"
},
{
"input": "5 1\n1\n1\n1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "10 3\n101 201 301\n102 202 302\n103 203 303\n104 204 304\n105 205 305\n106 206 306\n107 207 307\n108 208 308\n109 209 309\n111 211 311",
"output": "649\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\nco..."
},
{
"input": "2 1\n10\n10",
"output": "10\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1"
},
{
"input": "4 3\n2 2 2\n2 2 2\n2 2 2\n2 2 2",
"output": "6\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3"
},
{
"input": "3 1\n1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "8 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "1 2\n2 2",
"output": "2\nrow 1\nrow 1"
},
{
"input": "3 2\n2 3\n2 3\n2 3",
"output": "5\ncol 1\ncol 2\ncol 1\ncol 2\ncol 2"
},
{
"input": "2 1\n3\n3",
"output": "3\ncol 1\ncol 1\ncol 1"
},
{
"input": "6 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "2\ncol 1\ncol 2"
},
{
"input": "4 1\n1\n1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "2 5\n1 1 1 1 1\n1 1 1 1 1",
"output": "2\nrow 1\nrow 2"
},
{
"input": "3 1\n500\n500\n500",
"output": "500\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\nco..."
},
{
"input": "5 2\n1 1\n2 2\n2 2\n2 2\n2 2",
"output": "6\ncol 1\ncol 2\nrow 2\nrow 3\nrow 4\nrow 5"
},
{
"input": "4 3\n3 3 3\n3 3 3\n3 3 3\n3 3 3",
"output": "9\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3"
},
{
"input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "2\ncol 1\ncol 2"
},
{
"input": "1 4\n1 1 1 1",
"output": "1\nrow 1"
},
{
"input": "3 1\n2\n3\n2",
"output": "3\ncol 1\ncol 1\nrow 2"
},
{
"input": "1 5\n1 1 1 1 1",
"output": "1\nrow 1"
},
{
"input": "2 4\n3 1 1 1\n3 1 1 1",
"output": "4\nrow 1\nrow 2\ncol 1\ncol 1"
},
{
"input": "3 3\n1 1 1\n0 1 0\n0 0 0",
"output": "-1"
},
{
"input": "3 2\n2 2\n1 1\n2 2",
"output": "4\ncol 1\ncol 2\nrow 1\nrow 3"
},
{
"input": "2 1\n9\n9",
"output": "9\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1"
},
{
"input": "1 7\n3 3 3 3 3 3 3",
"output": "3\nrow 1\nrow 1\nrow 1"
},
{
"input": "5 2\n3 3\n3 3\n3 3\n3 3\n3 3",
"output": "6\ncol 1\ncol 2\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "10 11\n250 198 192 182 85 239 295 91 318 216 249\n290 238 232 222 125 279 335 131 358 256 289\n409 357 351 341 244 398 454 250 477 375 408\n362 310 304 294 197 351 407 203 430 328 361\n352 300 294 284 187 341 397 193 420 318 351\n409 357 351 341 244 398 454 250 477 375 408\n209 157 151 141 44 198 254 50 277 175 208\n313 261 255 245 148 302 358 154 381 279 312\n171 119 113 103 6 160 216 12 239 137 170\n275 223 217 207 110 264 320 116 343 241 274",
"output": "2770\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\nrow 9\nrow 10\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nro..."
},
{
"input": "7 1\n1\n1\n1\n1\n1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "5 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "3\ncol 1\ncol 2\ncol 3"
},
{
"input": "5 3\n3 3 3\n3 3 3\n3 3 3\n3 3 3\n3 3 3",
"output": "9\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3"
},
{
"input": "2 1\n4\n5",
"output": "5\ncol 1\ncol 1\ncol 1\ncol 1\nrow 2"
},
{
"input": "4 2\n3 3\n3 3\n3 3\n3 3",
"output": "6\ncol 1\ncol 2\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "6 3\n2 2 2\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "4\ncol 1\ncol 2\ncol 3\nrow 1"
},
{
"input": "5 1\n1\n2\n3\n4\n5",
"output": "11\ncol 1\nrow 2\nrow 3\nrow 3\nrow 4\nrow 4\nrow 4\nrow 5\nrow 5\nrow 5\nrow 5"
},
{
"input": "2 1\n1\n3",
"output": "3\ncol 1\nrow 2\nrow 2"
},
{
"input": "3 2\n1 500\n1 500\n1 500",
"output": "501\ncol 1\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\nco..."
},
{
"input": "10 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "1\ncol 1"
},
{
"input": "6 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "3 5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "3\nrow 1\nrow 2\nrow 3"
},
{
"input": "2 3\n2 1 2\n2 1 2",
"output": "4\nrow 1\nrow 2\ncol 1\ncol 3"
},
{
"input": "5 2\n2 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "1 2\n1 3",
"output": "3\nrow 1\ncol 2\ncol 2"
},
{
"input": "4 3\n2 2 2\n1 1 1\n1 1 1\n1 1 1",
"output": "4\ncol 1\ncol 2\ncol 3\nrow 1"
},
{
"input": "3 2\n1 1\n2 2\n3 3",
"output": "5\ncol 1\ncol 2\nrow 2\nrow 3\nrow 3"
},
{
"input": "4 2\n1 1\n1 1\n1 1\n1 1",
"output": "2\ncol 1\ncol 2"
},
{
"input": "3 4\n1 1 1 1\n1 1 1 1\n1 1 1 1",
"output": "3\nrow 1\nrow 2\nrow 3"
},
{
"input": "2 1\n2\n3",
"output": "3\ncol 1\ncol 1\nrow 2"
},
{
"input": "5 3\n2 2 2\n2 2 2\n2 2 2\n2 2 2\n2 2 2",
"output": "6\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3"
},
{
"input": "3 2\n1 0\n2 1\n2 1",
"output": "3\ncol 1\nrow 2\nrow 3"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "6\ncol 1\ncol 2\ncol 2\nrow 2\nrow 3\nrow 3"
},
{
"input": "3 3\n1 1 1\n1 2 1\n1 1 1",
"output": "-1"
},
{
"input": "4 3\n2 1 1\n2 1 1\n2 1 1\n2 1 1",
"output": "4\ncol 1\ncol 2\ncol 3\ncol 1"
},
{
"input": "4 1\n3\n3\n3\n3",
"output": "3\ncol 1\ncol 1\ncol 1"
},
{
"input": "1 3\n2 3 2",
"output": "3\nrow 1\nrow 1\ncol 2"
},
{
"input": "1 2\n1 2",
"output": "2\nrow 1\ncol 2"
},
{
"input": "3 2\n2 2\n2 2\n2 2",
"output": "4\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "1 3\n1 1 1",
"output": "1\nrow 1"
},
{
"input": "6 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "3\ncol 1\ncol 2\ncol 3"
},
{
"input": "3 1\n2\n2\n2",
"output": "2\ncol 1\ncol 1"
},
{
"input": "3 1\n3\n3\n3",
"output": "3\ncol 1\ncol 1\ncol 1"
},
{
"input": "3 2\n2 2\n1 1\n1 1",
"output": "3\ncol 1\ncol 2\nrow 1"
},
{
"input": "5 3\n1 1 2\n1 1 2\n1 1 2\n1 1 2\n1 1 2",
"output": "4\ncol 1\ncol 2\ncol 3\ncol 3"
},
{
"input": "1 2\n2 3",
"output": "3\nrow 1\nrow 1\ncol 2"
},
{
"input": "5 1\n2\n2\n2\n2\n2",
"output": "2\ncol 1\ncol 1"
},
{
"input": "3 2\n1 1\n2 2\n2 2",
"output": "4\ncol 1\ncol 2\nrow 2\nrow 3"
},
{
"input": "3 3\n1 1 1\n2 3 3\n4 4 4",
"output": "-1"
},
{
"input": "2 1\n5\n2",
"output": "5\ncol 1\ncol 1\nrow 1\nrow 1\nrow 1"
},
{
"input": "4 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "3 2\n5 10\n5 10\n5 10",
"output": "15\ncol 1\ncol 2\ncol 1\ncol 2\ncol 1\ncol 2\ncol 1\ncol 2\ncol 1\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2\ncol 2"
},
{
"input": "4 3\n3 4 3\n5 6 5\n3 4 3\n3 4 3",
"output": "12\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 1\ncol 2\ncol 3\ncol 2\nrow 2\nrow 2"
},
{
"input": "4 2\n1 1\n1 1\n1 1\n2 2",
"output": "3\ncol 1\ncol 2\nrow 4"
},
{
"input": "2 3\n1 1 1\n500 500 500",
"output": "501\nrow 1\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nrow 2\nro..."
},
{
"input": "4 1\n4\n4\n4\n4",
"output": "4\ncol 1\ncol 1\ncol 1\ncol 1"
},
{
"input": "3 2\n1 1\n1 1\n2 2",
"output": "3\ncol 1\ncol 2\nrow 3"
},
{
"input": "2 3\n2 2 2\n2 2 2",
"output": "4\nrow 1\nrow 2\nrow 1\nrow 2"
},
{
"input": "3 2\n3 3\n3 3\n3 3",
"output": "6\ncol 1\ncol 2\ncol 1\ncol 2\ncol 1\ncol 2"
},
{
"input": "2 3\n10 10 10\n5 5 5",
"output": "15\nrow 1\nrow 2\nrow 1\nrow 2\nrow 1\nrow 2\nrow 1\nrow 2\nrow 1\nrow 2\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1"
},
{
"input": "5 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "3\ncol 1\ncol 2\ncol 2"
},
{
"input": "1 2\n500 500",
"output": "500\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nrow 1\nro..."
},
{
"input": "2 1\n5\n5",
"output": "5\ncol 1\ncol 1\ncol 1\ncol 1\ncol 1"
}
] | 1,662,573,362 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 177 | 218 | 16,588,800 | from collections import defaultdict as dc
n,m=[int(x) for x in input().split()]
arr=list()
check=dc(lambda:False)
check2=dc(lambda:False)
ans,ans2=list(),list()
for _ in range(n):
tmp=list(map(int,input().split()))
arr.append(tmp)
pair,pair2=list(),list()
for i in range(n):
tmp=list()
for j in range(m):tmp.append((arr[i][j],j))
pair.append(tmp)
for i in range(n):pair[i]=sorted(pair[i],reverse=True)
for i in range(n):
for j in range(m):
x=pair[i][j][0]-pair[i][-1][0]
if x==0:break
idx=pair[i][j][1]
if check[idx+1]==True:continue
while x:ans.append(("col",idx+1)); x-=1; check[idx+1]=True
x=pair[i][-1][0]
if x:
for aa in range(1,m+1):check[aa]=True
while x:ans.append(("row",i+1)); x-=1
#print(ans)
Flag1=True
comp=list()
for i in range(n):
tmp=list()
for j in range(m):tmp.append(0)
comp.append(tmp)
for i in ans:
if i[0]=='row':
for j in range(m):comp[i[1]-1][j]+=1
else:
for j in range(n):comp[j][i[1]-1]+=1
if comp!=arr:Flag1=False
########################################
for i in range(m):
tmp=list()
for j in range(n):tmp.append((arr[j][i],j))
pair2.append(tmp)
for i in range(m):pair2[i]=sorted(pair2[i],reverse=True)
#print(pair2)
for j in range(m):
for i in range(n):
x=pair2[j][i][0]-pair2[j][-1][0]
if x==0:break
idx=pair2[j][i][1]
if check2[idx+1]==True:continue
while x:ans2.append(("row",idx+1)); x-=1; check2[idx+1]=True
x=pair2[j][-1][0]
if x:
for aa in range(1,m+1):check2[aa]=True
while x:
ans2.append(("col",j+1)); x-=1
#print(ans2)
Flag2=True
comp=list()
for i in range(n):
tmp=list()
for j in range(m):tmp.append(0)
comp.append(tmp)
for i in ans2:
if i[0]=='row':
for j in range(m):comp[i[1]-1][j]+=1
else:
for j in range(n):comp[j][i[1]-1]+=1
if comp!=arr:Flag2=False
if Flag1==Flag2 and Flag1==False:print(-1)
else:
if len(ans)==len(ans2) or len(ans)<len(ans2) or Flag2==False:
print(len(ans))
for i in ans:
print(i[0],i[1])
else:
print(len(ans2))
for i in ans2:
print(i[0],i[1]) | Title: Karen and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.
To win the level, after all the moves, the number in the cell at the *i*-th row and *j*-th column should be equal to *g**i*,<=*j*.
Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
Input Specification:
The first line of input contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of rows and the number of columns in the grid, respectively.
The next *n* lines each contain *m* integers. In particular, the *j*-th integer in the *i*-th of these rows contains *g**i*,<=*j* (0<=≤<=*g**i*,<=*j*<=≤<=500).
Output Specification:
If there is an error and it is actually not possible to beat the level, output a single integer -1.
Otherwise, on the first line, output a single integer *k*, the minimum number of moves necessary to beat the level.
The next *k* lines should each contain one of the following, describing the moves in the order they must be done:
- row *x*, (1<=≤<=*x*<=≤<=*n*) describing a move of the form "choose the *x*-th row". - col *x*, (1<=≤<=*x*<=≤<=*m*) describing a move of the form "choose the *x*-th column".
If there are multiple optimal solutions, output any one of them.
Demo Input:
['3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1\n', '3 3\n0 0 0\n0 1 0\n0 0 0\n', '3 3\n1 1 1\n1 1 1\n1 1 1\n']
Demo Output:
['4\nrow 1\nrow 1\ncol 4\nrow 3\n', '-1\n', '3\nrow 1\nrow 2\nrow 3\n']
Note:
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:
In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.
In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level:
Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3. | ```python
from collections import defaultdict as dc
n,m=[int(x) for x in input().split()]
arr=list()
check=dc(lambda:False)
check2=dc(lambda:False)
ans,ans2=list(),list()
for _ in range(n):
tmp=list(map(int,input().split()))
arr.append(tmp)
pair,pair2=list(),list()
for i in range(n):
tmp=list()
for j in range(m):tmp.append((arr[i][j],j))
pair.append(tmp)
for i in range(n):pair[i]=sorted(pair[i],reverse=True)
for i in range(n):
for j in range(m):
x=pair[i][j][0]-pair[i][-1][0]
if x==0:break
idx=pair[i][j][1]
if check[idx+1]==True:continue
while x:ans.append(("col",idx+1)); x-=1; check[idx+1]=True
x=pair[i][-1][0]
if x:
for aa in range(1,m+1):check[aa]=True
while x:ans.append(("row",i+1)); x-=1
#print(ans)
Flag1=True
comp=list()
for i in range(n):
tmp=list()
for j in range(m):tmp.append(0)
comp.append(tmp)
for i in ans:
if i[0]=='row':
for j in range(m):comp[i[1]-1][j]+=1
else:
for j in range(n):comp[j][i[1]-1]+=1
if comp!=arr:Flag1=False
########################################
for i in range(m):
tmp=list()
for j in range(n):tmp.append((arr[j][i],j))
pair2.append(tmp)
for i in range(m):pair2[i]=sorted(pair2[i],reverse=True)
#print(pair2)
for j in range(m):
for i in range(n):
x=pair2[j][i][0]-pair2[j][-1][0]
if x==0:break
idx=pair2[j][i][1]
if check2[idx+1]==True:continue
while x:ans2.append(("row",idx+1)); x-=1; check2[idx+1]=True
x=pair2[j][-1][0]
if x:
for aa in range(1,m+1):check2[aa]=True
while x:
ans2.append(("col",j+1)); x-=1
#print(ans2)
Flag2=True
comp=list()
for i in range(n):
tmp=list()
for j in range(m):tmp.append(0)
comp.append(tmp)
for i in ans2:
if i[0]=='row':
for j in range(m):comp[i[1]-1][j]+=1
else:
for j in range(n):comp[j][i[1]-1]+=1
if comp!=arr:Flag2=False
if Flag1==Flag2 and Flag1==False:print(-1)
else:
if len(ans)==len(ans2) or len(ans)<len(ans2) or Flag2==False:
print(len(ans))
for i in ans:
print(i[0],i[1])
else:
print(len(ans2))
for i in ans2:
print(i[0],i[1])
``` | 3 |
|
920 | F | SUM and REPLACE | PROGRAMMING | 2,000 | [
"brute force",
"data structures",
"dsu",
"number theory"
] | null | null | Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* integers. You have to process two types of queries:
1. REPLACE *l* *r* — for every replace *a**i* with *D*(*a**i*); 1. SUM *l* *r* — calculate .
Print the answer for each SUM query. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array.
Then *m* lines follow, each containing 3 integers *t**i*, *l**i*, *r**i* denoting *i*-th query. If *t**i*<==<=1, then *i*-th query is REPLACE *l**i* *r**i*, otherwise it's SUM *l**i* *r**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
There is at least one SUM query. | For each SUM query print the answer to it. | [
"7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n"
] | [
"30\n13\n4\n22\n"
] | none | 0 | [
{
"input": "7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7",
"output": "30\n13\n4\n22"
},
{
"input": "4 2\n1 1 1 3\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 9\n1 1 10\n2 1 10",
"output": "12"
},
{
"input": "4 2\n1 1 3 1\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "5 3\n1 1 1 1 3\n2 1 5\n1 1 5\n2 1 5",
"output": "7\n6"
},
{
"input": "7 10\n1 1 1 1 1 1 1\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n2 1 7",
"output": "7"
}
] | 1,518,980,941 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 19,558,400 | n,m = map(int,input().split())
a = list(map(int,input().split()))
for z in range(m):
x,l,r = map(int,input().split())
if(x==1):
b = a[l-1:r]
p = l-1
q = r
for i in b:
k=0
for j in range(1,i+1):
if(i%j==0):
k+=1
a[p] = k
p+=1
else:
print(sum(a[l-1:r]))
| Title: SUM and REPLACE
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* integers. You have to process two types of queries:
1. REPLACE *l* *r* — for every replace *a**i* with *D*(*a**i*); 1. SUM *l* *r* — calculate .
Print the answer for each SUM query.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array.
Then *m* lines follow, each containing 3 integers *t**i*, *l**i*, *r**i* denoting *i*-th query. If *t**i*<==<=1, then *i*-th query is REPLACE *l**i* *r**i*, otherwise it's SUM *l**i* *r**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
There is at least one SUM query.
Output Specification:
For each SUM query print the answer to it.
Demo Input:
['7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n']
Demo Output:
['30\n13\n4\n22\n']
Note:
none | ```python
n,m = map(int,input().split())
a = list(map(int,input().split()))
for z in range(m):
x,l,r = map(int,input().split())
if(x==1):
b = a[l-1:r]
p = l-1
q = r
for i in b:
k=0
for j in range(1,i+1):
if(i%j==0):
k+=1
a[p] = k
p+=1
else:
print(sum(a[l-1:r]))
``` | 0 |
|
665 | A | Buses Between Cities | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | Buses run between the cities *A* and *B*, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city *A* departs every *a* minutes and arrives to the city *B* in a *t**a* minutes, and a bus from the city *B* departs every *b* minutes and arrives to the city *A* in a *t**b* minutes.
The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.
You know the time when Simion departed from the city *A* to the city *B*. Calculate the number of buses Simion will meet to be sure in his counting. | The first line contains two integers *a*,<=*t**a* (1<=≤<=*a*,<=*t**a*<=≤<=120) — the frequency of the buses from the city *A* to the city *B* and the travel time. Both values are given in minutes.
The second line contains two integers *b*,<=*t**b* (1<=≤<=*b*,<=*t**b*<=≤<=120) — the frequency of the buses from the city *B* to the city *A* and the travel time. Both values are given in minutes.
The last line contains the departure time of Simion from the city *A* in the format hh:mm. It is guaranteed that there are a bus from the city *A* at that time. Note that the hours and the minutes are given with exactly two digits. | Print the only integer *z* — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities *A* and *B*. | [
"10 30\n10 35\n05:20\n",
"60 120\n24 100\n13:00\n"
] | [
"5\n",
"9\n"
] | In the first example Simion departs form the city *A* at 05:20 AM and arrives to the city *B* at 05:50 AM. He will meet the first 5 buses from the city *B* that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city *B* at 05:50 AM, but he will not count it.
Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed). | 0 | [
{
"input": "10 30\n10 35\n05:20",
"output": "5"
},
{
"input": "60 120\n24 100\n13:00",
"output": "9"
},
{
"input": "30 60\n60 60\n22:30",
"output": "2"
},
{
"input": "30 60\n10 60\n23:30",
"output": "8"
},
{
"input": "5 45\n4 60\n21:00",
"output": "26"
},
{
"input": "1 1\n1 1\n10:28",
"output": "1"
},
{
"input": "4 1\n5 4\n18:40",
"output": "1"
},
{
"input": "8 8\n1 1\n13:24",
"output": "8"
},
{
"input": "20 4\n1 20\n06:20",
"output": "23"
},
{
"input": "15 24\n23 6\n21:15",
"output": "1"
},
{
"input": "30 19\n21 4\n10:30",
"output": "1"
},
{
"input": "31 15\n36 25\n07:04",
"output": "1"
},
{
"input": "24 3\n54 9\n18:12",
"output": "0"
},
{
"input": "18 69\n62 54\n08:00",
"output": "2"
},
{
"input": "33 58\n70 78\n22:36",
"output": "2"
},
{
"input": "68 34\n84 78\n10:40",
"output": "1"
},
{
"input": "15 14\n32 65\n05:45",
"output": "2"
},
{
"input": "40 74\n100 42\n05:40",
"output": "2"
},
{
"input": "65 49\n24 90\n07:10",
"output": "6"
},
{
"input": "1 1\n1 1\n23:59",
"output": "1"
},
{
"input": "23 118\n118 20\n23:24",
"output": "0"
},
{
"input": "3 88\n17 38\n22:33",
"output": "8"
},
{
"input": "3 1\n2 3\n05:03",
"output": "1"
},
{
"input": "1 1\n3 2\n08:44",
"output": "0"
},
{
"input": "1 3\n1 2\n21:43",
"output": "4"
},
{
"input": "2 28\n2 12\n05:12",
"output": "19"
},
{
"input": "60 120\n17 120\n23:00",
"output": "11"
},
{
"input": "1 55\n1 54\n23:59",
"output": "54"
},
{
"input": "66 75\n1 82\n06:06",
"output": "141"
},
{
"input": "1 90\n1 88\n23:59",
"output": "88"
},
{
"input": "1 120\n1 100\n23:59",
"output": "100"
}
] | 1,461,166,385 | 1,985 | PyPy 3 | OK | TESTS | 31 | 186 | 23,244,800 | a, t1 = map(int, input().split())
b, t2 = map(int, input().split())
hour, minute = map(int, input().split(':'))
minutef = minute + hour * 60 + t1
minutes = minute + hour * 60 - t2
cnt = 0
time = 300
while time < minutef and time < 240 * 6:
if time > minutes:
cnt += 1
time += b
print(cnt) | Title: Buses Between Cities
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Buses run between the cities *A* and *B*, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city *A* departs every *a* minutes and arrives to the city *B* in a *t**a* minutes, and a bus from the city *B* departs every *b* minutes and arrives to the city *A* in a *t**b* minutes.
The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.
You know the time when Simion departed from the city *A* to the city *B*. Calculate the number of buses Simion will meet to be sure in his counting.
Input Specification:
The first line contains two integers *a*,<=*t**a* (1<=≤<=*a*,<=*t**a*<=≤<=120) — the frequency of the buses from the city *A* to the city *B* and the travel time. Both values are given in minutes.
The second line contains two integers *b*,<=*t**b* (1<=≤<=*b*,<=*t**b*<=≤<=120) — the frequency of the buses from the city *B* to the city *A* and the travel time. Both values are given in minutes.
The last line contains the departure time of Simion from the city *A* in the format hh:mm. It is guaranteed that there are a bus from the city *A* at that time. Note that the hours and the minutes are given with exactly two digits.
Output Specification:
Print the only integer *z* — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities *A* and *B*.
Demo Input:
['10 30\n10 35\n05:20\n', '60 120\n24 100\n13:00\n']
Demo Output:
['5\n', '9\n']
Note:
In the first example Simion departs form the city *A* at 05:20 AM and arrives to the city *B* at 05:50 AM. He will meet the first 5 buses from the city *B* that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city *B* at 05:50 AM, but he will not count it.
Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed). | ```python
a, t1 = map(int, input().split())
b, t2 = map(int, input().split())
hour, minute = map(int, input().split(':'))
minutef = minute + hour * 60 + t1
minutes = minute + hour * 60 - t2
cnt = 0
time = 300
while time < minutef and time < 240 * 6:
if time > minutes:
cnt += 1
time += b
print(cnt)
``` | 3 |
|
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.
Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value). | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach any city from any other by the roads. | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n1 47\n1 13\n1 46\n60 1\n1 6\n23 1\n20 1\n1 52\n2 1\n26 1\n1 59\n1 66\n10 1\n1 62\n1 68\n1 55\n50 1\n33 1\n44 1\n1 34\n1 35\n1 61\n14 1\n67 1\n49 1",
"output": "1.000000000000000"
},
{
"input": "10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1",
"output": "1.500000000000000"
},
{
"input": "1",
"output": "0.000000000000000"
}
] | 1,666,189,769 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 102,400 | from collections import deque
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
u, v = map(int, input().split())
graph[u-1].append(v-1)
graph[v-1].append(u-1)
queue = deque([[1,0]])
visited = set()
distances, cities = 0, 0
while queue:
cur, dist = queue.popleft()
visited.add(cur)
if len(graph[cur]) == 1:
cities += 1
distances += dist
for neighbor in graph[cur]:
if neighbor not in visited:
queue.append([neighbor, dist+1])
print(distances / cities) | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.
Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value).
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach any city from any other by the roads.
Output Specification:
Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['4\n1 2\n1 3\n2 4\n', '5\n1 2\n1 3\n3 4\n2 5\n']
Demo Output:
['1.500000000000000\n', '2.000000000000000\n']
Note:
In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | ```python
from collections import deque
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
u, v = map(int, input().split())
graph[u-1].append(v-1)
graph[v-1].append(u-1)
queue = deque([[1,0]])
visited = set()
distances, cities = 0, 0
while queue:
cur, dist = queue.popleft()
visited.add(cur)
if len(graph[cur]) == 1:
cities += 1
distances += dist
for neighbor in graph[cur]:
if neighbor not in visited:
queue.append([neighbor, dist+1])
print(distances / cities)
``` | 0 |
|
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,457,880,199 | 9,799 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 12 | 3,000 | 1,024,000 | n=int(input())
a=[]
for i in range(n):
b=input()
if a.count(b)==0:
a.append(b)
else:
a.remove(b)
a.append(b)
a.reverse()
for elem in a:
print(elem)
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
n=int(input())
a=[]
for i in range(n):
b=input()
if a.count(b)==0:
a.append(b)
else:
a.remove(b)
a.append(b)
a.reverse()
for elem in a:
print(elem)
``` | 0 |
|
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order. | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
{
"input": "CACCBAA.BC",
"output": "Yes"
},
{
"input": ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.",
"output": "Yes"
},
{
"input": "A",
"output": "No"
},
{
"input": "..",
"output": "No"
},
{
"input": "BC",
"output": "No"
},
{
"input": "CAB",
"output": "Yes"
},
{
"input": "A.CB",
"output": "No"
},
{
"input": "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB",
"output": "Yes"
},
{
"input": "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.B.CB..CA.C.C.",
"output": "No"
},
{
"input": "AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC",
"output": "Yes"
},
{
"input": "CA.ABB.CC.B.C.BBBABAAB.BBBAACACAAA.C.AACA.AAC.C.BCCB.CCBC.C..CCACA.CBCCB.CCAABAAB.AACAA..A.AAA.",
"output": "No"
},
{
"input": "CBC...AC.BBBB.BBABABA.CAAACC.AAABB..A.BA..BC.CBBBC.BBBBCCCAA.ACCBB.AB.C.BA..CC..AAAC...AB.A.AAABBA.A",
"output": "No"
},
{
"input": "CC.AAAC.BA.BBB.AABABBCCAA.A.CBCCB.B.BC.ABCBCBBAA.CACA.CCCA.CB.CCB.A.BCCCB...C.A.BCCBC..B.ABABB.C.BCB",
"output": "Yes"
},
{
"input": "CCC..A..CACACCA.CA.ABAAB.BBA..C.AAA...ACB.ACA.CA.B.AB.A..C.BC.BC.A.C....ABBCCACCCBCC.BBBAA.ACCACB.BB",
"output": "Yes"
},
{
"input": "BC.ABACAACC..AC.A..CCCAABBCCACAC.AA.CC.BAABABABBCBB.BA..C.C.C.A.BBA.C..BC.ACACCC.AAAACCCCC.AAC.AC.AB",
"output": "Yes"
},
{
"input": "ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB",
"output": "Yes"
},
{
"input": "CCAC.BCBC.A.ABBAB.C.C.BC.CCABBCBCCBC..B.AA.C.BC...B..BAA.ACCCCBBB.AAAACA.CAACCB.CCB.CC.BCCAB.BBBBABB",
"output": "Yes"
},
{
"input": ".AACAA.AAAAC.BBBB.BC...CCACCACAAA.A..CCA..BCC.AB.ABAAB..AABA...B.C.CBAB.BAAB.A.C.AAC.BBBA.ACAAA.BB.C",
"output": "Yes"
},
{
"input": "CC.ACCC.BCCCCAA.BBAACB.ABABAAAA.A.CBAB.CBACBBC..C.CA.AAA..AA..ABBB.A.C..CBBCAAACC.B..CC.AC..CAABACB.",
"output": "Yes"
},
{
"input": ".BAB.",
"output": "No"
},
{
"input": "BBBBBBBBB",
"output": "No"
},
{
"input": "..AAC..",
"output": "No"
},
{
"input": ".AAABBBCCC.",
"output": "No"
},
{
"input": "AAABC",
"output": "Yes"
},
{
"input": "BBB",
"output": "No"
},
{
"input": "AAAAABABAAAAA",
"output": "No"
},
{
"input": "AABBCC",
"output": "No"
},
{
"input": ".BA",
"output": "No"
},
{
"input": "CAAAAB",
"output": "No"
}
] | 1,645,354,211 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | string = input()
if "ABC" or "ACB" or "BAC" or "BCA" or "CBA" or "CBA" in string:
print ("Yes")
else:
print ("No") | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input Specification:
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output Specification:
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['.BAC.\n', 'AA..CB\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | ```python
string = input()
if "ABC" or "ACB" or "BAC" or "BCA" or "CBA" or "CBA" in string:
print ("Yes")
else:
print ("No")
``` | 0 |
|
412 | C | Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.
Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters. | In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | [
"2\n?ab\n??b\n",
"2\na\nb\n",
"1\n?a?b\n"
] | [
"xab\n",
"?\n",
"cacb\n"
] | Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on. | 1,500 | [
{
"input": "2\n?ab\n??b",
"output": "xab"
},
{
"input": "2\na\nb",
"output": "?"
},
{
"input": "1\n?a?b",
"output": "cacb"
},
{
"input": "1\n?",
"output": "x"
},
{
"input": "3\nabacaba\nabacaba\nabacaba",
"output": "abacaba"
},
{
"input": "3\nabc?t\n?bc?z\nab??t",
"output": "abcx?"
},
{
"input": "4\nabc\ndef\n???\nxyz",
"output": "???"
},
{
"input": "2\n?????\n?????",
"output": "xxxxx"
},
{
"input": "2\na\na",
"output": "a"
},
{
"input": "3\nabc\n???\naxc",
"output": "a?c"
},
{
"input": "1\n?m??x?xxexxx?xxmxx??",
"output": "cmccxcxxexxxcxxmxxcc"
},
{
"input": "2\nhszhh?zszs\nhhzhz?zzhs",
"output": "h?zh?cz??s"
},
{
"input": "3\neddzde\needded\nzdde?z",
"output": "??d???"
},
{
"input": "4\nff?o?\nfk?of\nk?kof\nfk?oo",
"output": "??ko?"
},
{
"input": "5\nyigi\ne?gi\niig?\n?eg?\n??gi",
"output": "??gi"
},
{
"input": "100\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz",
"output": "z"
},
{
"input": "100\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?",
"output": "bc"
},
{
"input": "1\nq",
"output": "q"
},
{
"input": "2\n?\n?",
"output": "x"
},
{
"input": "2\n?\na",
"output": "a"
},
{
"input": "2\n?\nb",
"output": "b"
},
{
"input": "3\n?\na\na",
"output": "a"
},
{
"input": "3\na\n?\na",
"output": "a"
},
{
"input": "3\na\nb\n?",
"output": "?"
},
{
"input": "3\n?\na\nb",
"output": "?"
},
{
"input": "3\nb\n?\na",
"output": "?"
},
{
"input": "2\n???\naaa",
"output": "aaa"
},
{
"input": "2\n??\nss",
"output": "ss"
}
] | 1,654,175,513 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 218 | 4,198,400 | for s in zip(*(input()for p in range(int(input())))):
l=set(s)-{'?'}
print('?'if len(l)>1 else l.pop()if l else 'a',end='') | Title: Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.
Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.
Output Specification:
In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.
Demo Input:
['2\n?ab\n??b\n', '2\na\nb\n', '1\n?a?b\n']
Demo Output:
['xab\n', '?\n', 'cacb\n']
Note:
Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on. | ```python
for s in zip(*(input()for p in range(int(input())))):
l=set(s)-{'?'}
print('?'if len(l)>1 else l.pop()if l else 'a',end='')
``` | 3 |
|
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn",
"output": "IGNORE HIM!"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx",
"output": "CHAT WITH HER!"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt",
"output": "IGNORE HIM!"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk",
"output": "IGNORE HIM!"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz",
"output": "IGNORE HIM!"
},
{
"input": "tgcdptnkc",
"output": "IGNORE HIM!"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi",
"output": "IGNORE HIM!"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp",
"output": "IGNORE HIM!"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia",
"output": "IGNORE HIM!"
},
{
"input": "fpellxwskyekoyvrfnuf",
"output": "CHAT WITH HER!"
},
{
"input": "xninyvkuvakfbs",
"output": "IGNORE HIM!"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak",
"output": "CHAT WITH HER!"
},
{
"input": "kmsk",
"output": "IGNORE HIM!"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz",
"output": "CHAT WITH HER!"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq",
"output": "CHAT WITH HER!"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm",
"output": "IGNORE HIM!"
},
{
"input": "ppcpbnhwoizajrl",
"output": "IGNORE HIM!"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv",
"output": "CHAT WITH HER!"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw",
"output": "IGNORE HIM!"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu",
"output": "CHAT WITH HER!"
},
{
"input": "ojjvpnkrxibyevxk",
"output": "CHAT WITH HER!"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg",
"output": "IGNORE HIM!"
},
{
"input": "hkdbykboclchfdsuovvpknwqr",
"output": "IGNORE HIM!"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu",
"output": "IGNORE HIM!"
},
{
"input": "rafcaanqytfclvfdegak",
"output": "CHAT WITH HER!"
},
{
"input": "xczn",
"output": "CHAT WITH HER!"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp",
"output": "IGNORE HIM!"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika",
"output": "CHAT WITH HER!"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh",
"output": "CHAT WITH HER!"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg",
"output": "CHAT WITH HER!"
},
{
"input": "udlpagtpq",
"output": "CHAT WITH HER!"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy",
"output": "CHAT WITH HER!"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten",
"output": "CHAT WITH HER!"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb",
"output": "CHAT WITH HER!"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr",
"output": "CHAT WITH HER!"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc",
"output": "IGNORE HIM!"
},
{
"input": "lnpdosnceumubvk",
"output": "IGNORE HIM!"
},
{
"input": "efrk",
"output": "CHAT WITH HER!"
},
{
"input": "temnownneghnrujforif",
"output": "IGNORE HIM!"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta",
"output": "IGNORE HIM!"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh",
"output": "IGNORE HIM!"
},
{
"input": "gwntwbpj",
"output": "IGNORE HIM!"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim",
"output": "IGNORE HIM!"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd",
"output": "CHAT WITH HER!"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx",
"output": "IGNORE HIM!"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks",
"output": "CHAT WITH HER!"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx",
"output": "CHAT WITH HER!"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc",
"output": "CHAT WITH HER!"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr",
"output": "IGNORE HIM!"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc",
"output": "IGNORE HIM!"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq",
"output": "CHAT WITH HER!"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj",
"output": "IGNORE HIM!"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom",
"output": "CHAT WITH HER!"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo",
"output": "CHAT WITH HER!"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh",
"output": "IGNORE HIM!"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa",
"output": "CHAT WITH HER!"
},
{
"input": "oh",
"output": "CHAT WITH HER!"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri",
"output": "IGNORE HIM!"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp",
"output": "CHAT WITH HER!"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp",
"output": "CHAT WITH HER!"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo",
"output": "CHAT WITH HER!"
},
{
"input": "mnmbupgo",
"output": "IGNORE HIM!"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl",
"output": "IGNORE HIM!"
},
{
"input": "yocxrzspinchmhtmqo",
"output": "CHAT WITH HER!"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv",
"output": "CHAT WITH HER!"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad",
"output": "IGNORE HIM!"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli",
"output": "CHAT WITH HER!"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy",
"output": "IGNORE HIM!"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd",
"output": "IGNORE HIM!"
},
{
"input": "acrzbavz",
"output": "CHAT WITH HER!"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza",
"output": "IGNORE HIM!"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws",
"output": "CHAT WITH HER!"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff",
"output": "CHAT WITH HER!"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu",
"output": "CHAT WITH HER!"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw",
"output": "IGNORE HIM!"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy",
"output": "CHAT WITH HER!"
},
{
"input": "rhh",
"output": "CHAT WITH HER!"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo",
"output": "IGNORE HIM!"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn",
"output": "CHAT WITH HER!"
},
{
"input": "urigreuzpxnej",
"output": "CHAT WITH HER!"
}
] | 1,695,470,297 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | name=(input('Введите своё имя'))
a=len(name)
c=int(len(a))
if c%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
| Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
Input Specification:
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
Output Specification:
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
Demo Input:
['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n']
Demo Output:
['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n']
Note:
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | ```python
name=(input('Введите своё имя'))
a=len(name)
c=int(len(a))
if c%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
``` | -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,612,379,223 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 62 | 0 | x=int(input())
s="123456789101112131415161718192021222324252627282930"
print(s[x-1]) | 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
x=int(input())
s="123456789101112131415161718192021222324252627282930"
print(s[x-1])
``` | -1 |
|
312 | A | Whose sentence is it? | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n"
] | [
"Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"
] | none | 500 | [
{
"input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .",
"output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iapelala.\nCFPlbUgObrXLejPNu.F\nZSUfvisiHyrIMjMlala.\nmiao. lala.\nd,IWSeumytrVlala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's"
},
{
"input": "10\nmiao.,taUvXPVlala.\nmiao.txEeId.X_lala.\nLZIeAEd JaeBVlala.\ncKPIsWpwIlala.\nfYp.eSvn,g\nKMx,nFEslala.\nmiao.QtMyxYqiajjuM\nDutxNkCqywgcnCYskcd\ngFLKACjeqfD\n,Ss UmY.wJvcX",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.Plala.\nDVm,VYslala.\nmiao.rlala.\nmiao.,KQNL.fO_.QRc\nUBLCKEUePlala.\nIouS.Alala.\nmiao.lala.\nmiao.rlala.\nEJZwRJeKlala.\nmiao.Olala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nRainbow's\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.grFTpju.jCLRnZ\ng.pVHYA_Usnm\nlloWONolcMFElala.\nAW,n.JJkOTe.Nd\n.bP.HvKlala.\nGziqPGQa,lala.\nmiao.,QkOCH.vFlala.\n.PUtOwImvUsoeh \nmiao.Z,KIds.R\nmiao.,_MDzoaAiJlala.",
"output": "Rainbow's\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.xWfjV\nHFVrGCDQXyZ,Sbm\nLMDS.xVkTCAY.vm\nmiao.lLBglala.\nnl,jRPyClala.\nFYnHoXlala.\nmiao. oxaHE\n.WTrw_mNpOQCa\nHOk..wHYoyMhl\nQX,XpMuPIROM",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nJBQqiXlala.\npUNUWQRiMPCXv\nAiLnfNHWznwkC.lala.\nmiao.Dl_Oy\nxJJJkVkdfOzQBH_SmKh\nfgD_IHvdHiorE,W\nmiao.usBKixglala.\nwCpqPUzEtD\nmiao.rlala.\nmiao.JylcGvWlala.",
"output": "Freda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao..FLhPl_Wjslala.\nmiao. tdEGtfdJlala.\nGAzEUlala.\nKCcmOa .aKBlZyYsdu.V\nmiao.lala.\njKylnM,FXK\nmiao.GBWqjGH.v\nmiao.RefxS Cni.\nOxaaEihuHQR_s,\nmiao.a,Axtlala.",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nNo.I_aTXlala.\nmiao.JKSCoRZS\nnOBMIlala.\nmiao.nlala.\nmiao._xqxoHIIlala.\nmiao.NJPy SWyiUDWc\nmiao.cCnahFaqqj.Xqp\nnreSMDeXPPYAQxI,W\nAktPajWimdd_qRn\nmiao.QHwKCYlala.",
"output": "Freda's\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\n \n,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ \n \nmiao.miao.miao.\nlala.lala.lala.\nlala.miao.\nmiaolala. \nmiao.lala\nmiaolala_\n,.._ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nduClyjMIPsEuWmx_Ce.byVoizYlTM,sF\nuZHsNip_,Mwtg,FZjM_LzPC,_pSvEOyTHfAOvoZXvxCZdgYDTCDdCAoSVZWyxXGcLgWlala.\nEGtJFPAvTEcqjkhaGxdduaQ_rmUzF.WaU, EIuX B,aVzFFpFrxpwADXuayRD azDfj \n_tJqYzXyqc.,u.F,mUYukveBPWnPq,f,dJnPHuBazdnbRHfzwNUdRbheAIjcoaPcnLvocrzcioxCapb R\n.YUBeb_zmwUt.QQuUdQIiOXtqshcsycEe,HLytHlala.\ndJndLqGBHt.GfpN.BgvsbXoLh_DIzAJOtFDmLSCYEztvPcS_GHPxivzV,NPMmSAtfk.Mg.w,A UcCt_lCD.csEzyJJBYtSMkzqiA\nmiao.qlala.\nmiao.FmDlY\nmiao.UQI.aJmnanNvRLskuVaMybDMsOlala.\nmiao.lala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.vyscfysAtWcPkpFHdwZqAQ,UPPcjhKQTlala.\nmiao.KESqus DybUuYFoWVpo..LWZh.UqEdUsTHFlKfzqkThAUPklala.\nUNoE vfZIAdxkiWKhsHPfsqRPTNQoHgAxooVLYxRzugHjo jaEHWQFF\nCCmdIwr.UkoiYWK.Z,,ZesMpISTXNgnpYnJaWquCyL,gO\n.JvOayhXK_bgoYbfAtnXg\nbvdSzRrXoGxVgWvdXnsjEnEfxDzIQo_aZVGDGrzwuAMtzVAHioMBx_DHuTxyieGbGuSRNUojOREqxBBxvCgqAOMzwIWT\nMBuaWduZmRaOGyIPzWOsBVeqtDrblAbXxmM_uRfqMvnVlLEuhVKlhidN_aigiXyq,ZEDqQAx\nmiao.wCHVCuVKNePKmIUFLL_lala.\nmiao.iAqstXHUv\n pMO yvPkNtnNwmUCao W,wW.OvIMVaEeVYHmqaniWq.ivlala.",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's"
},
{
"input": "10\nmiao.\nmiao.jrwLBCpNaDCjyoK.PFzbwWU.h.. wfQquG_P..lala.\nmiao.LGlYdKjw__.Chlala.\nW.wtr qG KDOHj.xWxPbXIXjD_,GJZDaAZ,JBHphsjWJwSKcZAIAi\nmiao.pHsGAZQDWPJQwKC.zHjJituLgp.eUrzObTI.wrpect.FMUJqu,Zuslala.\nmiao.YVlOpXccUA_YU igbsbZbhOVwyYTyOjnWqgiTmxwAuFa.flCHn.,MtVbqxZQl_BGHXWkwijGjuL, ,ezyNlala.\nmiao.xCrVSz.aMv UOSOroDlQxWeBmlWe.FA.ZfUmviMlala.\nxebAlala.\nmiao.qVSxqf vOTlala.\nD.oBUwsLQRgXAoNkQJhQN.w.oMhuvtujnmiwgQYMfjlNTSHh .lSKgI.OEp",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nZXXzYlTiQU\nkXE.DdcbOojSaSgjMcFBPubKHefEVAzbi,PDFgSZIz,lala.\nxEfrTCjKhhwBC.UNmJXgTGUdkQeVDlala.\nLfaEw.jvMmuOBWtfoiJNtDIlQAVWNU,xWK_efBBtfkM\nqtBpqKZMWZMX_NKrUAEKYyQcLZWQlqbM\nmiao.PrJEbUtInremuaKRItqXOrfQEjQcAak VQ\nMpGCq awvQaHRvDr uvtVMKsvZI\nmiao.A.RVGu.szCEp.pXQJwL EuTltlN.WradoTvWHJyhcNSoulala.\nmiao.rzlUHzUdxtDRpWRuc,QZwEBfsKKGHMLGtFymPPQdptLFlzZ_ORWqrlfOrlntuDkpXEvz.CxwAsFYUvpnOnFWG\nmiao.VXUoNBwlgBwcna_n.CgAAcKKUuiVA.doOJKHpMdwNwlHAcLpdfN.Awa SthrlEWpUcuOonUTxIQNszYcHDXxnhArrM..A",
"output": "OMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's"
},
{
"input": "10\nmiao.qbxBFzrjtWv.yOk\nDBgi,loApO AACrGnwssCHN\nmiao.LV.wbQEE_V.BSAtdTIHTQOJVJ_nGOthbL,nJvQ.UeWFpsa.GGsK_Uv,HQxHS,AN_bkrolala.\nmiao.tBEqk rIQuByGKhfq_iP.BW,nySZEfrfySEcqnnIzxC,lrjIiivbxlkoVXJFiegGFRn NO,txGPhVBcv.CVhMmNO zlala.\nmiao.aBZWDWxk.wkR ,NyCzGxJnJDqBZpetdUPAmmBZDXl_Tbflala.\nmiao. XN,uMwWm. VqloYr..jTLszlala.\n.rshcgfZ.eZOdMu_RMh\nmiao.ahiwpECEe.lala.\nLeoUSroTekQAMSO__M L_ZEeRD_tUihYvQETFB,RzJmFtFiKrU\nBtygQG_OoFEFBL.KsVWTYbtqtalXoStFCZ RINHda.NuLmlkRB.vAQJFvelbsfoJ.T,M sJn",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nYoYBCcaqhXLfvKKf.UYMODTHyPZlala.\ncxgWn J.Q\nmiao.nwH.IHntgKYDhdsjU DMTHXEVRyeJP ZaAecCIBJXuv.YjhEmtbjvjKnK.U,oc,x\nmiao.EcQ.FDtRJgmpAzxhq.RwXBLxjyC,IeMqaFoheMPFCGWBcwUAFnbiwlbz_fcsEGPfJaeryCtFocBNEWTlala.\nmiao.W\nmiao. ZQpIeyCXJSnFgAIzu.THfrmyoogYWQzFqblala.\nmiao.ifzdCwnTDcxpvdr OTC.YqPv.MKDp..utICtAsbfYyGlala.\nmiao.\nmiao.tS.U.wH.s,CxORZJsBAHLi,fXeoDJWVBH\nrcUMpeupOVRKrcIRAvU.rP kgUEfoeXcrFPQOBYG.BNvAQPg.XHMWizhLpZNljXc .LQmVXCi",
"output": "Freda's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nlala.\nmiao.milalala.lmmialamiao.la.o.iao.a.ao.\nmialala.o.\nmiao.millala.allala.amiao..miao.miao.lala.ao.miammiao.iao.o.\nmiao.miaomiao..\nlalmiao.amiao..\nmiao.lala.lamiamiaolala..o.lalala.miao..\nmlala.iao.lalamiao..\nlmlala.iao.alalamiao.lmialala.lala.miao.o.alala..lala..lalmiaomiao..lalmiao.a.lalamiao..miao.alala..\nlalllamiao.la.lala.alamiao.lalalala.lala..miao.lamiao.la.lallalamiao..a..a.",
"output": "Freda's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nlalllala.ala.lala.a.mmimiao.aomiao.lllala.ala.amiao.la.mialalala.la.o..imiao.miao.amlala.iao.o.\nmilala.alllala.ala.amiao.lamiao..o.\nlala.lalalala..lalalala..\nlala.miao.\nmimiao.ao.lala.\nlalmiao.amlala.iamialala.o.o..\nlalammlala.iaolammiao.imiao.ao.la..iao..\nmiao.mialala.omiao..mlala.iaolala..\nmiamiao.o.llallala.ala.la.miao.ala.miao.mimialmiao.ala.o.alala.miaomiao..olala..\nmialala.lamiao.la.lala.miao.ollala.allala.ala.lmiaommiao.imiao.ao.lallallala.a.miao.a..a..",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nlamiao.lamiao.mimiao.ao..\nllala.almiaomiao..lala.miao.a.\nlalala.lala.lalala.lala.lalala..la.\nlalala.la.miao.\nmiao.llalallala.miao.a.la.lala.almimiao.ao.a.\nmiao.mlala.ilala.aomilala.ao..\nmilala.ao.\nmmiao.iao.\nmlala.lala.ialalmiao.alala..olala.lala..\nlala.lmlalalalalala...iao.milala.aommiao.iao..alamiaolallala.milala.ao.a..lalalmiao.a..llala.amiao..",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "4\n \n miao. \n lala. \n ",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "1\nMiao.",
"output": "OMG>.< I don't know!"
},
{
"input": "1\nm",
"output": "OMG>.< I don't know!"
},
{
"input": "1\nMiAo.sdsdlala.",
"output": "Freda's"
},
{
"input": "1\nLalA.",
"output": "OMG>.< I don't know!"
},
{
"input": "3\n.\nm\nl",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
}
] | 1,612,692,782 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,048,000 | n = int(input())
for _ in range(n+1):
s = list(input().split(' '))
if(s[(len(s))-1] == "miao."):
print("Rainbow's")
elif(s[(len(s))-1] == "lala."):
print("Freda's")
else:
print("OMG>.< I don't know!") | Title: Whose sentence is it?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100.
Output Specification:
For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions.
Demo Input:
['5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n']
Demo Output:
["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"]
Note:
none | ```python
n = int(input())
for _ in range(n+1):
s = list(input().split(' '))
if(s[(len(s))-1] == "miao."):
print("Rainbow's")
elif(s[(len(s))-1] == "lala."):
print("Freda's")
else:
print("OMG>.< I don't know!")
``` | -1 |
|
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*! | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"input": "3 70 58",
"output": "35"
},
{
"input": "5 7 10",
"output": "3"
},
{
"input": "5 30 22",
"output": "10"
},
{
"input": "5 5 6",
"output": "2"
},
{
"input": "2 4 3",
"output": "3"
},
{
"input": "10 10 31",
"output": "3"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "10 98 99",
"output": "19"
},
{
"input": "4 10 16",
"output": "5"
},
{
"input": "11 4 8",
"output": "1"
},
{
"input": "5 10 14",
"output": "4"
},
{
"input": "6 7 35",
"output": "7"
},
{
"input": "5 6 7",
"output": "2"
},
{
"input": "4 15 3",
"output": "3"
},
{
"input": "7 48 77",
"output": "16"
},
{
"input": "4 4 10",
"output": "3"
},
{
"input": "4 7 20",
"output": "6"
},
{
"input": "5 2 8",
"output": "2"
},
{
"input": "3 2 3",
"output": "1"
},
{
"input": "14 95 1",
"output": "1"
},
{
"input": "99 82 53",
"output": "1"
},
{
"input": "10 71 27",
"output": "9"
},
{
"input": "5 7 8",
"output": "2"
},
{
"input": "11 77 77",
"output": "12"
},
{
"input": "10 5 28",
"output": "3"
},
{
"input": "7 3 12",
"output": "2"
},
{
"input": "10 15 17",
"output": "3"
},
{
"input": "7 7 7",
"output": "1"
},
{
"input": "4 11 18",
"output": "6"
},
{
"input": "3 3 4",
"output": "2"
},
{
"input": "9 2 10",
"output": "1"
},
{
"input": "100 90 20",
"output": "1"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "12 45 60",
"output": "8"
},
{
"input": "3 94 79",
"output": "47"
},
{
"input": "41 67 34",
"output": "2"
},
{
"input": "9 3 23",
"output": "2"
},
{
"input": "10 20 57",
"output": "7"
},
{
"input": "55 27 30",
"output": "1"
},
{
"input": "100 100 10",
"output": "1"
},
{
"input": "20 8 70",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 9 15",
"output": "5"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "2 94 94",
"output": "94"
},
{
"input": "5 3 11",
"output": "2"
},
{
"input": "4 3 2",
"output": "1"
},
{
"input": "12 12 100",
"output": "9"
},
{
"input": "6 75 91",
"output": "25"
},
{
"input": "3 4 3",
"output": "2"
},
{
"input": "3 2 5",
"output": "2"
},
{
"input": "6 5 15",
"output": "3"
},
{
"input": "4 3 6",
"output": "2"
},
{
"input": "3 9 9",
"output": "4"
},
{
"input": "26 93 76",
"output": "6"
},
{
"input": "41 34 67",
"output": "2"
},
{
"input": "6 12 6",
"output": "3"
},
{
"input": "5 20 8",
"output": "5"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "35 66 99",
"output": "4"
},
{
"input": "30 7 91",
"output": "3"
},
{
"input": "5 22 30",
"output": "10"
},
{
"input": "8 19 71",
"output": "10"
},
{
"input": "3 5 6",
"output": "3"
},
{
"input": "5 3 8",
"output": "2"
},
{
"input": "2 4 2",
"output": "2"
},
{
"input": "4 3 7",
"output": "2"
},
{
"input": "5 20 10",
"output": "5"
},
{
"input": "5 100 50",
"output": "25"
},
{
"input": "6 3 10",
"output": "2"
},
{
"input": "2 90 95",
"output": "90"
},
{
"input": "4 8 6",
"output": "3"
},
{
"input": "6 10 3",
"output": "2"
},
{
"input": "3 3 5",
"output": "2"
},
{
"input": "5 33 33",
"output": "11"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "19 24 34",
"output": "3"
},
{
"input": "5 5 12",
"output": "3"
},
{
"input": "8 7 10",
"output": "2"
},
{
"input": "5 56 35",
"output": "17"
},
{
"input": "4 3 5",
"output": "1"
},
{
"input": "18 100 50",
"output": "8"
},
{
"input": "5 6 8",
"output": "2"
},
{
"input": "5 98 100",
"output": "33"
},
{
"input": "6 5 8",
"output": "2"
},
{
"input": "3 40 80",
"output": "40"
},
{
"input": "4 8 11",
"output": "4"
},
{
"input": "66 100 99",
"output": "3"
},
{
"input": "17 100 79",
"output": "10"
},
{
"input": "3 2 10",
"output": "2"
},
{
"input": "99 100 99",
"output": "2"
},
{
"input": "21 100 5",
"output": "5"
},
{
"input": "3 10 2",
"output": "2"
},
{
"input": "4 100 63",
"output": "33"
},
{
"input": "2 2 10",
"output": "2"
},
{
"input": "5 94 79",
"output": "31"
},
{
"input": "4 12 5",
"output": "4"
},
{
"input": "5 5 40",
"output": "5"
},
{
"input": "99 99 99",
"output": "1"
},
{
"input": "8 97 44",
"output": "16"
},
{
"input": "11 4 10",
"output": "1"
},
{
"input": "6 3 3",
"output": "1"
},
{
"input": "7 3 4",
"output": "1"
},
{
"input": "8 4 4",
"output": "1"
},
{
"input": "9 4 5",
"output": "1"
},
{
"input": "12 6 6",
"output": "1"
},
{
"input": "4 48 89",
"output": "29"
},
{
"input": "8 3 6",
"output": "1"
},
{
"input": "4 6 3",
"output": "2"
},
{
"input": "5 5 1",
"output": "1"
},
{
"input": "11 6 5",
"output": "1"
},
{
"input": "4 5 4",
"output": "2"
},
{
"input": "6 6 4",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "4 1 3",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "9 4 6",
"output": "1"
},
{
"input": "6 5 6",
"output": "1"
},
{
"input": "2 2 3",
"output": "2"
},
{
"input": "4 5 1",
"output": "1"
},
{
"input": "13 6 7",
"output": "1"
},
{
"input": "14 7 7",
"output": "1"
},
{
"input": "12 97 13",
"output": "8"
},
{
"input": "4 2 9",
"output": "2"
},
{
"input": "10 20 59",
"output": "7"
},
{
"input": "12 34 56",
"output": "7"
},
{
"input": "4 5 9",
"output": "3"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "4 66 41",
"output": "22"
}
] | 1,636,562,854 | 2,147,483,647 | PyPy 3 | OK | TESTS | 135 | 93 | 17,715,200 | import sys,math
#sys.stdin=open('input.txt','r')
#sys.stdout=open('output.txt','w')
def solve():
n,a,b=map(int,input().split())
ans=0
for i in range(1,n):
mina=a//i
minb=b//(n-i)
ans1=min(mina,minb)
ans=max(ans,ans1)
print(ans)
solve()
| Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*!
Input Specification:
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Output Specification:
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
Demo Input:
['5 2 3\n', '4 7 10\n']
Demo Output:
['1\n', '3\n']
Note:
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | ```python
import sys,math
#sys.stdin=open('input.txt','r')
#sys.stdout=open('output.txt','w')
def solve():
n,a,b=map(int,input().split())
ans=0
for i in range(1,n):
mina=a//i
minb=b//(n-i)
ans1=min(mina,minb)
ans=max(ans,ans1)
print(ans)
solve()
``` | 3 |
|
371 | A | K-Periodic Array | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"math"
] | null | null | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*.
For example, any array is *n*-periodic, where *n* is the array length. Array [2,<=1,<=2,<=1,<=2,<=1] is at the same time 2-periodic and 6-periodic and array [1,<=2,<=1,<=1,<=2,<=1,<=1,<=2,<=1] is at the same time 3-periodic and 9-periodic.
For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0. | The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of the array. | Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. | [
"6 2\n2 1 2 2 2 1\n",
"8 4\n1 1 2 1 1 1 2 1\n",
"9 3\n2 1 1 1 2 1 1 1 2\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic. | 500 | [
{
"input": "6 2\n2 1 2 2 2 1",
"output": "1"
},
{
"input": "8 4\n1 1 2 1 1 1 2 1",
"output": "0"
},
{
"input": "9 3\n2 1 1 1 2 1 1 1 2",
"output": "3"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "100 1\n1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "8"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "3 1\n2 1 2",
"output": "1"
},
{
"input": "3 3\n1 2 1",
"output": "0"
},
{
"input": "4 2\n2 1 2 2",
"output": "1"
},
{
"input": "10 2\n2 2 2 1 1 2 2 2 2 1",
"output": "3"
},
{
"input": "10 5\n2 2 1 2 1 1 2 1 1 1",
"output": "2"
},
{
"input": "20 4\n2 2 1 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 1 2",
"output": "0"
},
{
"input": "20 5\n2 2 1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 1 1 2",
"output": "3"
},
{
"input": "20 10\n1 2 2 2 2 1 1 1 2 1 1 2 2 2 2 1 2 2 2 1",
"output": "2"
},
{
"input": "100 2\n2 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100 4\n1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 2 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 1 1 2 1 1",
"output": "8"
},
{
"input": "100 5\n2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 2",
"output": "16"
},
{
"input": "100 10\n2 1 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 2 2 1 2 1 1",
"output": "6"
},
{
"input": "100 20\n2 2 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 1 1 2 2 2 2 1 2 1 1 2 2 2 2 1 2 1 2 1 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 2 1 1 1",
"output": "13"
},
{
"input": "100 25\n2 2 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 1 2 1 1 2 2 2 2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2",
"output": "15"
},
{
"input": "100 10\n2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 1",
"output": "0"
}
] | 1,661,541,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n, k = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
possibilities_one = []
for i in range(k):
possibilities_one.append(0)
for i in range(len(array)):
if array[i] == 1:
possibilities_one[i%k] += 1
total_diff = 0
for ele in possibilities_one:
diff = (n/k) - ele
neg_diff = ele - (n/k)
if (abs(diff) > abs(neg_diff)): diff = abs(neg_diff)
if (diff != n/k and diff != 0):
total_diff += diff
print(int(total_diff))
| Title: K-Periodic Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*.
For example, any array is *n*-periodic, where *n* is the array length. Array [2,<=1,<=2,<=1,<=2,<=1] is at the same time 2-periodic and 6-periodic and array [1,<=2,<=1,<=1,<=2,<=1,<=1,<=2,<=1] is at the same time 3-periodic and 9-periodic.
For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0.
Input Specification:
The first line of the input contains a pair of integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), *a**i* is the *i*-th element of the array.
Output Specification:
Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0.
Demo Input:
['6 2\n2 1 2 2 2 1\n', '8 4\n1 1 2 1 1 1 2 1\n', '9 3\n2 1 1 1 2 1 1 1 2\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic. | ```python
n, k = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
possibilities_one = []
for i in range(k):
possibilities_one.append(0)
for i in range(len(array)):
if array[i] == 1:
possibilities_one[i%k] += 1
total_diff = 0
for ele in possibilities_one:
diff = (n/k) - ele
neg_diff = ele - (n/k)
if (abs(diff) > abs(neg_diff)): diff = abs(neg_diff)
if (diff != n/k and diff != 0):
total_diff += diff
print(int(total_diff))
``` | 0 |
|
408 | B | Garland | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.
Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of *m* pieces of paper in the garland. Calculate what the maximum total area of the pieces of paper in the garland Vasya can get. | The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make. | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | [
"aaabbac\naabbccac\n",
"a\nz\n"
] | [
"6\n",
"-1"
] | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*. | 1,000 | [
{
"input": "aaabbac\naabbccac",
"output": "6"
},
{
"input": "a\nz",
"output": "-1"
},
{
"input": "r\nr",
"output": "1"
},
{
"input": "stnsdn\nndnndsn",
"output": "4"
},
{
"input": "yqfqfp\ntttwtqq",
"output": "-1"
},
{
"input": "zzbbrrtrtzr\ntbbtrrrzr",
"output": "9"
},
{
"input": "ivvfisvsvii\npaihjinno",
"output": "-1"
},
{
"input": "zbvwnlgkshqerxptyod\nz",
"output": "1"
},
{
"input": "xlktwjymocqrahnbesf\nfoo",
"output": "2"
},
{
"input": "bbzmzqazmbambnmzaabznmbabzqnaabmabmnnabbmnzaanzzezebzabqaabzqaemeqqammmbazmmz\naznnbbmeebmanbeemzmemqbaeebnqenqzzbanebmnzqqebqmmnmqqzmmeqqqaaezemmazqqmqaqnnqqzbzeeazammmenbbamzbmnaenemenaaaebnmanebqmqnznqbenmqqnnnaeaebqmamennmqqeaaqqbammnzqmnmqnqbbezmemznqmanzmmqzzzzembqnzqbanamezqaqbazenenqqznqaebzaeezbqqbmeeaqnmmbnqbbnmaqqemaeaezaabmbnbzzaae",
"output": "77"
},
{
"input": "lccfdfnfflncddlksndcwnfcllnnaswcdnldafcalssfcdnkkaklwnnacsncfwanwnwfadawcsdcfwflnnlfsfclkfknlaldna\nuaaldlllhedgugugueahddhedbuddaedhaaeugdubaealbgbagedldbl",
"output": "-1"
},
{
"input": "hvewdvwdwudrwarwmddwnazmwauzatrmwptwwevavpmwrtruwnpwantewrnwmepdwvtmnveanunrvrtwpvhhnuhnmpptdttzmmndtvudmzhhannmmnahdpzamuvhzaavnhtnumwrwvttdetvuewaaennddwuvzvaptdzrzhtetwwzmzedrwuvrwznprhdvnavrruvvhzuwpdtmpwmzrwvermrhdamv\nuvzhwtpuputnahwwarduzddhpnwwvettprwavdmnztdnrddmarmvuevtdezndnezvarhmppwwnmvnrtddzhhnzrwuhvpwmezuurundarwdazwptrpeurrnwautddnhdmhtwhwvvtavdzezumetzezpazndhuentmrhamutrtttpevtuutemdnvwnwnmnvmznatneweuaahdavmaddhnrdenwwztrwh",
"output": "199"
},
{
"input": "aaccddff\nabcdf",
"output": "-1"
}
] | 1,517,054,288 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 5,632,000 | n=input()
m=input()
i=0
a=0
while i<len(m):
if m[i] in n:
adet=n.count(m[i])
n=n.replace(m[i],'')+(adet-1)*m[i]
a=a+1
i=i+1
if a==0:
print(-1)
else:
print(a)
| Title: Garland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.
Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of *m* pieces of paper in the garland. Calculate what the maximum total area of the pieces of paper in the garland Vasya can get.
Input Specification:
The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.
Output Specification:
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
Demo Input:
['aaabbac\naabbccac\n', 'a\nz\n']
Demo Output:
['6\n', '-1']
Note:
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*. | ```python
n=input()
m=input()
i=0
a=0
while i<len(m):
if m[i] in n:
adet=n.count(m[i])
n=n.replace(m[i],'')+(adet-1)*m[i]
a=a+1
i=i+1
if a==0:
print(-1)
else:
print(a)
``` | 0 |
|
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections. | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*.
It is guaranteed that the total number of people in all the cities does not exceed 109. | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index. | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{
"input": "2 2\n1 2\n2 1",
"output": "1"
},
{
"input": "2 2\n2 1\n2 1",
"output": "1"
},
{
"input": "2 2\n1 2\n1 2",
"output": "2"
},
{
"input": "3 3\n0 0 0\n1 1 1\n2 2 2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9",
"output": "5"
},
{
"input": "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n0 1 1 0",
"output": "1"
},
{
"input": "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0",
"output": "1"
},
{
"input": "4 4\n1 4 1 300\n3 1 2 1\n5 0 0 2\n0 1 10 100",
"output": "1"
},
{
"input": "5 5\n15 45 15 300 10\n53 15 25 51 10\n5 50 50 2 10\n1000 1 10 100 10\n10 10 10 10 10",
"output": "1"
},
{
"input": "1 100\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\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\n1\n1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 100\n859\n441\n272\n47\n355\n345\n612\n569\n545\n599\n410\n31\n720\n303\n58\n537\n561\n730\n288\n275\n446\n955\n195\n282\n153\n455\n996\n121\n267\n702\n769\n560\n353\n89\n990\n282\n801\n335\n573\n258\n722\n768\n324\n41\n249\n125\n557\n303\n664\n945\n156\n884\n985\n816\n433\n65\n976\n963\n85\n647\n46\n877\n665\n523\n714\n182\n377\n549\n994\n385\n184\n724\n447\n99\n766\n353\n494\n747\n324\n436\n915\n472\n879\n582\n928\n84\n627\n156\n972\n651\n159\n372\n70\n903\n590\n480\n184\n540\n270\n892",
"output": "1"
},
{
"input": "100 1\n439 158 619 538 187 153 973 781 610 475 94 947 449 531 220 51 788 118 189 501 54 434 465 902 280 635 688 214 737 327 682 690 683 519 261 923 254 388 529 659 662 276 376 735 976 664 521 285 42 147 187 259 407 977 879 465 522 17 550 701 114 921 577 265 668 812 232 267 135 371 586 201 608 373 771 358 101 412 195 582 199 758 507 882 16 484 11 712 916 699 783 618 405 124 904 257 606 610 230 718",
"output": "54"
},
{
"input": "1 99\n511\n642\n251\n30\n494\n128\n189\n324\n884\n656\n120\n616\n959\n328\n411\n933\n895\n350\n1\n838\n996\n761\n619\n131\n824\n751\n707\n688\n915\n115\n244\n476\n293\n986\n29\n787\n607\n259\n756\n864\n394\n465\n303\n387\n521\n582\n485\n355\n299\n997\n683\n472\n424\n948\n339\n383\n285\n957\n591\n203\n866\n79\n835\n980\n344\n493\n361\n159\n160\n947\n46\n362\n63\n553\n793\n754\n429\n494\n523\n227\n805\n313\n409\n243\n927\n350\n479\n971\n825\n460\n544\n235\n660\n327\n216\n729\n147\n671\n738",
"output": "1"
},
{
"input": "99 1\n50 287 266 159 551 198 689 418 809 43 691 367 160 664 86 805 461 55 127 950 576 351 721 493 972 560 934 885 492 92 321 759 767 989 883 7 127 413 404 604 80 645 666 874 371 718 893 158 722 198 563 293 134 255 742 913 252 378 859 721 502 251 839 284 133 209 962 514 773 124 205 903 785 859 911 93 861 786 747 213 690 69 942 697 211 203 284 961 351 137 962 952 408 249 238 850 944 40 346",
"output": "34"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2",
"output": "100"
},
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 1\n0 0",
"output": "1"
},
{
"input": "2 2\n0 0\n0 0",
"output": "1"
},
{
"input": "2 2\n1 2\n0 0",
"output": "1"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 0",
"output": "1"
},
{
"input": "2 3\n0 0\n0 0\n0 1",
"output": "1"
},
{
"input": "3 2\n1 1 3\n0 0 0",
"output": "1"
},
{
"input": "3 4\n1 10 3\n0 0 0\n0 0 0\n0 0 0",
"output": "1"
},
{
"input": "2 4\n2 1\n1 2\n0 0\n1 2",
"output": "1"
},
{
"input": "2 2\n0 1\n0 1",
"output": "2"
},
{
"input": "2 3\n1 2\n0 0\n2 1",
"output": "1"
},
{
"input": "2 2\n0 0\n4 5",
"output": "1"
},
{
"input": "3 2\n10 15 20\n0 0 0",
"output": "1"
},
{
"input": "3 4\n0 0 0\n0 0 0\n0 0 0\n1 2 3",
"output": "1"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 1",
"output": "1"
},
{
"input": "3 3\n0 0 0\n1 2 3\n1 3 2",
"output": "1"
},
{
"input": "3 1\n0 0 0",
"output": "1"
},
{
"input": "3 3\n0 0 1\n0 0 0\n0 0 0",
"output": "1"
}
] | 1,535,869,090 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
#define nl printf("\n");
#define pp pair<ll,ll>
#define mem(a, s) memset(a, s, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define sf(n) scanf("%d", &n)
#define sfs(s) scanf("%s", s)
#define sff(n, m) scanf("%d %d",&n,&m)
#define sfl(n) scanf("%lld", &n)
#define sfu(n) scanf("%llu", &n)
#define sffl(n, m) scanf("%lld %lld",&n,&m)
#define pt(n) printf("%d", n)
#define pf(n) printf("%d ", n)
#define pff(n) printf("%d %d\n", m, n)
#define pfl(n) printf("%lld ", n)
#define pfu(n) printf("%llu\n", n)
#define pfs(s) printf("%s", s)
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const int N = 101000;
ll ar[101][101], ar2[101];
int main()
{
int t = 1;
while(t--)
{
ll n, m;
cin >> n >> m;
ll p = 0;
for(int i = 0; i < m; i++)
{
ll mx = 0;
for(int j = 0; j < n; j++)
{
cin >> ar[i][j];
if(mx < ar[i][j])
{
mx = ar[i][j];
p = j;
}
}
ar2[p]++;
}
ll mx = 0, ans = 0, i;
for(i = 0; i < n; i++)
{
if(mx < ar2[i])
{
mx = ar2[i];
ans = i;
}
}
cout << ans + 1 << endl;
}
return 0;
}
| Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input Specification:
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output Specification:
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Demo Input:
['3 3\n1 2 3\n2 3 1\n1 2 1\n', '3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n']
Demo Output:
['2', '1']
Note:
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index. | ```python
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
#define nl printf("\n");
#define pp pair<ll,ll>
#define mem(a, s) memset(a, s, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define sf(n) scanf("%d", &n)
#define sfs(s) scanf("%s", s)
#define sff(n, m) scanf("%d %d",&n,&m)
#define sfl(n) scanf("%lld", &n)
#define sfu(n) scanf("%llu", &n)
#define sffl(n, m) scanf("%lld %lld",&n,&m)
#define pt(n) printf("%d", n)
#define pf(n) printf("%d ", n)
#define pff(n) printf("%d %d\n", m, n)
#define pfl(n) printf("%lld ", n)
#define pfu(n) printf("%llu\n", n)
#define pfs(s) printf("%s", s)
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const int N = 101000;
ll ar[101][101], ar2[101];
int main()
{
int t = 1;
while(t--)
{
ll n, m;
cin >> n >> m;
ll p = 0;
for(int i = 0; i < m; i++)
{
ll mx = 0;
for(int j = 0; j < n; j++)
{
cin >> ar[i][j];
if(mx < ar[i][j])
{
mx = ar[i][j];
p = j;
}
}
ar2[p]++;
}
ll mx = 0, ans = 0, i;
for(i = 0; i < n; i++)
{
if(mx < ar2[i])
{
mx = ar2[i];
ans = i;
}
}
cout << ans + 1 << endl;
}
return 0;
}
``` | -1 |
|
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},
{
"input": "123456789123456789\n276193619183618162",
"output": "276193618987554432"
},
{
"input": "1000000000000000000\n1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "1\n1000000000000000000",
"output": "1"
},
{
"input": "999999999999999999\n1000000000000000000",
"output": "999999999999999999"
},
{
"input": "2475345634895\n3455834583479",
"output": "3455834579642"
},
{
"input": "15778899\n98715689",
"output": "98598771"
},
{
"input": "4555\n5454",
"output": "4555"
},
{
"input": "122112\n221112",
"output": "221112"
},
{
"input": "199999999999991\n191000000000000",
"output": "119999999999999"
},
{
"input": "13\n31",
"output": "31"
},
{
"input": "212\n211",
"output": "122"
},
{
"input": "222234\n322223",
"output": "243222"
},
{
"input": "123456789\n987654311",
"output": "987654231"
},
{
"input": "20123\n21022",
"output": "20321"
},
{
"input": "10101\n11000",
"output": "10110"
},
{
"input": "592\n924",
"output": "592"
},
{
"input": "5654456\n5634565",
"output": "5566544"
},
{
"input": "655432\n421631",
"output": "365542"
},
{
"input": "200\n200",
"output": "200"
},
{
"input": "123456789987654321\n121111111111111111",
"output": "119988776655443322"
},
{
"input": "12345\n21344",
"output": "15432"
},
{
"input": "120\n200",
"output": "120"
},
{
"input": "123\n212",
"output": "132"
},
{
"input": "2184645\n5213118",
"output": "5186442"
},
{
"input": "9912346\n9912345",
"output": "9694321"
},
{
"input": "5003\n5000",
"output": "3500"
},
{
"input": "12345\n31234",
"output": "25431"
},
{
"input": "5001\n5000",
"output": "1500"
},
{
"input": "53436\n53425",
"output": "53364"
},
{
"input": "9329\n3268",
"output": "2993"
},
{
"input": "1234567890\n9000000001",
"output": "8976543210"
},
{
"input": "321\n212",
"output": "132"
},
{
"input": "109823464\n901234467",
"output": "896443210"
},
{
"input": "6543\n6542",
"output": "6534"
},
{
"input": "555441\n555100",
"output": "554541"
},
{
"input": "472389479\n327489423",
"output": "327487994"
},
{
"input": "45645643756464352\n53465475637456247",
"output": "53465475636654442"
},
{
"input": "254\n599",
"output": "542"
},
{
"input": "5232222345652321\n5000000000000000",
"output": "4655533322222221"
},
{
"input": "201\n200",
"output": "120"
},
{
"input": "14362799391220361\n45160821596433661",
"output": "43999766332221110"
},
{
"input": "3453\n5304",
"output": "4533"
},
{
"input": "989\n998",
"output": "998"
},
{
"input": "5200000000234\n5200000000311",
"output": "5200000000243"
},
{
"input": "5555132\n1325442",
"output": "1255553"
},
{
"input": "123\n211",
"output": "132"
},
{
"input": "65689\n66123",
"output": "65986"
},
{
"input": "123451234567890\n123456789012345",
"output": "123456789012345"
},
{
"input": "22115\n22015",
"output": "21521"
},
{
"input": "123\n311",
"output": "231"
},
{
"input": "12222\n21111",
"output": "12222"
},
{
"input": "765\n567",
"output": "567"
},
{
"input": "9087645\n9087640",
"output": "9087564"
},
{
"input": "1111111122222333\n2220000000000000",
"output": "2213332221111111"
},
{
"input": "7901\n7108",
"output": "7091"
},
{
"input": "215489\n215488",
"output": "214985"
},
{
"input": "102\n200",
"output": "120"
},
{
"input": "19260817\n20011213",
"output": "19876210"
},
{
"input": "12345\n53200",
"output": "53142"
},
{
"input": "1040003001\n1040003000",
"output": "1040001300"
},
{
"input": "295\n924",
"output": "592"
},
{
"input": "20000000000000001\n20000000000000000",
"output": "12000000000000000"
},
{
"input": "99988877\n99887766",
"output": "99879887"
},
{
"input": "12\n12",
"output": "12"
},
{
"input": "199999999999999999\n900000000000000000",
"output": "199999999999999999"
},
{
"input": "1234\n4310",
"output": "4231"
},
{
"input": "100011\n100100",
"output": "100011"
},
{
"input": "328899\n328811",
"output": "299883"
},
{
"input": "646722972346\n397619201220",
"output": "397476664222"
},
{
"input": "1203\n1200",
"output": "1032"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1112\n2110",
"output": "1211"
},
{
"input": "4545\n5540",
"output": "5454"
},
{
"input": "3053\n5004",
"output": "3530"
},
{
"input": "3503\n5004",
"output": "3530"
},
{
"input": "351731653766064847\n501550303749042658",
"output": "501548777666643331"
},
{
"input": "10123456789013451\n26666666666666666",
"output": "26598754433111100"
},
{
"input": "1110111\n1100000",
"output": "1011111"
},
{
"input": "30478\n32265",
"output": "30874"
},
{
"input": "456546546549874615\n441554543131214545",
"output": "441554498766665554"
},
{
"input": "214\n213",
"output": "142"
},
{
"input": "415335582799619283\n133117803602859310",
"output": "132999887655543321"
},
{
"input": "787\n887",
"output": "877"
},
{
"input": "3333222288889999\n3333222288881111",
"output": "3332999988883222"
},
{
"input": "495779862481416791\n836241745208800994",
"output": "829998777665444111"
},
{
"input": "139\n193",
"output": "193"
},
{
"input": "9568\n6500",
"output": "5986"
},
{
"input": "3208899\n3228811",
"output": "3209988"
},
{
"input": "27778\n28710",
"output": "27877"
},
{
"input": "62345\n46415",
"output": "46352"
},
{
"input": "405739873179209\n596793907108871",
"output": "594998777332100"
},
{
"input": "365\n690",
"output": "653"
},
{
"input": "8388731334391\n4710766672578",
"output": "4398887333311"
},
{
"input": "1230\n1200",
"output": "1032"
},
{
"input": "1025\n5000",
"output": "2510"
},
{
"input": "4207799\n4027711",
"output": "2997740"
},
{
"input": "4444222277779999\n4444222277771111",
"output": "4442999977774222"
},
{
"input": "7430\n3047",
"output": "3047"
},
{
"input": "649675735\n540577056",
"output": "539776654"
},
{
"input": "26\n82",
"output": "62"
},
{
"input": "241285\n207420",
"output": "185422"
},
{
"input": "3\n3",
"output": "3"
},
{
"input": "12\n21",
"output": "21"
},
{
"input": "481287\n826607",
"output": "824871"
},
{
"input": "40572351\n59676984",
"output": "57543210"
},
{
"input": "268135787269\n561193454469",
"output": "539887766221"
},
{
"input": "4\n9",
"output": "4"
},
{
"input": "5\n6",
"output": "5"
},
{
"input": "60579839\n33370073",
"output": "30998765"
},
{
"input": "49939\n39200",
"output": "34999"
},
{
"input": "2224\n4220",
"output": "2422"
},
{
"input": "427799\n427711",
"output": "299774"
},
{
"input": "49\n90",
"output": "49"
},
{
"input": "93875\n82210",
"output": "79853"
},
{
"input": "78831\n7319682",
"output": "88731"
},
{
"input": "937177\n7143444",
"output": "977731"
},
{
"input": "499380628\n391990337",
"output": "390988642"
},
{
"input": "2090909\n2900000",
"output": "2099900"
},
{
"input": "112233445566778890\n987654321987654320",
"output": "987654321876543210"
},
{
"input": "48257086\n80903384",
"output": "80876542"
},
{
"input": "112233445566778890\n900654321987654320",
"output": "898776655443322110"
},
{
"input": "112233445566778890\n123456789123456788",
"output": "123456789123456780"
},
{
"input": "5207799\n5027711",
"output": "2997750"
},
{
"input": "200000000000000001\n200000000000000000",
"output": "120000000000000000"
},
{
"input": "597402457\n797455420",
"output": "797455420"
},
{
"input": "90\n94",
"output": "90"
},
{
"input": "86888\n88683",
"output": "86888"
},
{
"input": "419155888\n588151913",
"output": "588151894"
},
{
"input": "408919130\n191830070",
"output": "191830049"
},
{
"input": "524975\n554924",
"output": "554792"
},
{
"input": "53029\n30524",
"output": "30295"
},
{
"input": "5549\n5542",
"output": "5495"
},
{
"input": "6\n9",
"output": "6"
},
{
"input": "87\n810",
"output": "87"
},
{
"input": "920491855\n281495062",
"output": "281495059"
},
{
"input": "6691\n6910",
"output": "6691"
},
{
"input": "533\n335",
"output": "335"
},
{
"input": "999999999999999998\n999999999999999997",
"output": "999999999999999989"
},
{
"input": "21111111111111111\n21111111111111110",
"output": "12111111111111111"
},
{
"input": "2\n12",
"output": "2"
},
{
"input": "76544\n45744",
"output": "45674"
},
{
"input": "2000000000000001\n2000000000000000",
"output": "1200000000000000"
},
{
"input": "740867\n467701",
"output": "467087"
},
{
"input": "2\n6",
"output": "2"
},
{
"input": "103\n130",
"output": "130"
},
{
"input": "2423712\n8466235",
"output": "7432221"
},
{
"input": "84\n48",
"output": "48"
},
{
"input": "1210\n12113",
"output": "2110"
},
{
"input": "2430\n20786",
"output": "4320"
},
{
"input": "100\n999",
"output": "100"
},
{
"input": "19325\n21903",
"output": "21593"
},
{
"input": "1969\n23251",
"output": "9961"
}
] | 1,516,403,464 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 5,632,000 | def swap_n_sort(X, i, j):
X = X[0:i] + X[j] + X[i+1:j] + X[i] + X[j+1:]
X = X[:i+1] + ''.join(reversed(sorted(X[i+1:])))
return X
X = ''.join(reversed(sorted(input())))
Y = input()
if len(X) < len(Y):
print(X)
else:
eq = True
i = 0
while i < len(X):
print(i, " ", X)
x = int(X[i])
y = int(Y[i])
if x < y:
break
if x == y and eq == True:
i += 1
if x > y or (x == y and eq == False):
nx = -1
nj = -1
for j in range(i+1, len(X)):
xx = int(X[j])
if ((xx <= y and eq == True) or (xx < y and eq == False)) and xx > nx:
nj = j
nx = int(X[j])
if nx > -1:
X = swap_n_sort(X, i, nj)
i += 1
else:
i -= 1
eq = False
print(X) | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is.
Input Specification:
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output Specification:
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
Demo Input:
['123\n222\n', '3921\n10000\n', '4940\n5000\n']
Demo Output:
['213\n', '9321\n', '4940\n']
Note:
none | ```python
def swap_n_sort(X, i, j):
X = X[0:i] + X[j] + X[i+1:j] + X[i] + X[j+1:]
X = X[:i+1] + ''.join(reversed(sorted(X[i+1:])))
return X
X = ''.join(reversed(sorted(input())))
Y = input()
if len(X) < len(Y):
print(X)
else:
eq = True
i = 0
while i < len(X):
print(i, " ", X)
x = int(X[i])
y = int(Y[i])
if x < y:
break
if x == y and eq == True:
i += 1
if x > y or (x == y and eq == False):
nx = -1
nj = -1
for j in range(i+1, len(X)):
xx = int(X[j])
if ((xx <= y and eq == True) or (xx < y and eq == False)) and xx > nx:
nj = j
nx = int(X[j])
if nx > -1:
X = swap_n_sort(X, i, nj)
i += 1
else:
i -= 1
eq = False
print(X)
``` | 0 |
|
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",
"output": "NO"
},
{
"input": "190492",
"output": "YES"
},
{
"input": "5722367",
"output": "NO"
},
{
"input": "816761542",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "NO"
},
{
"input": "9",
"output": "YES"
},
{
"input": "10",
"output": "NO"
},
{
"input": "12",
"output": "YES"
},
{
"input": "13",
"output": "YES"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "16",
"output": "YES"
},
{
"input": "17",
"output": "NO"
},
{
"input": "18",
"output": "YES"
},
{
"input": "19",
"output": "NO"
},
{
"input": "20",
"output": "YES"
},
{
"input": "41",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "69",
"output": "YES"
},
{
"input": "82",
"output": "NO"
},
{
"input": "85",
"output": "NO"
},
{
"input": "736",
"output": "NO"
},
{
"input": "895",
"output": "YES"
},
{
"input": "934",
"output": "YES"
},
{
"input": "6213",
"output": "YES"
},
{
"input": "7405",
"output": "NO"
},
{
"input": "9919",
"output": "NO"
},
{
"input": "40942",
"output": "YES"
},
{
"input": "41992",
"output": "NO"
},
{
"input": "68535",
"output": "NO"
},
{
"input": "405718",
"output": "NO"
},
{
"input": "1046146",
"output": "YES"
},
{
"input": "3761248",
"output": "YES"
},
{
"input": "6195181",
"output": "YES"
},
{
"input": "35354345",
"output": "NO"
},
{
"input": "81282830",
"output": "NO"
},
{
"input": "187719774",
"output": "NO"
},
{
"input": "296798673",
"output": "NO"
},
{
"input": "938938476",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "999887464",
"output": "YES"
},
{
"input": "999111944",
"output": "NO"
},
{
"input": "999966520",
"output": "YES"
},
{
"input": "999912080",
"output": "NO"
},
{
"input": "999992017",
"output": "YES"
},
{
"input": "999990474",
"output": "NO"
},
{
"input": "999999190",
"output": "YES"
},
{
"input": "999999125",
"output": "NO"
},
{
"input": "999999940",
"output": "YES"
},
{
"input": "999999995",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "83495494",
"output": "NO"
},
{
"input": "968022000",
"output": "YES"
},
{
"input": "399980000",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
}
] | 1,591,083,777 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 342 | 1,433,600 | import math
n = int(input())
a = 1
b = 1
c = -(2*n)
d = (b**2) - (4*a*c)
flag = 0
sol = (-b+math.sqrt(d))//(2*a)
ma = int(sol)
temp = 0
for i in range(1,ma+1):
temp += i
c = -(2*(n-temp))
d = (b**2) - (4*a*c)
sol = (-b + math.sqrt(d)) // (2 * a)
if (sol*(sol+1))//2 + temp == n and sol > 0:
flag = 1
print("YES")
break
if flag == 0:
print("NO")
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input Specification:
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Demo Input:
['256\n', '512\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | ```python
import math
n = int(input())
a = 1
b = 1
c = -(2*n)
d = (b**2) - (4*a*c)
flag = 0
sol = (-b+math.sqrt(d))//(2*a)
ma = int(sol)
temp = 0
for i in range(1,ma+1):
temp += i
c = -(2*(n-temp))
d = (b**2) - (4*a*c)
sol = (-b + math.sqrt(d)) // (2 * a)
if (sol*(sol+1))//2 + temp == n and sol > 0:
flag = 1
print("YES")
break
if flag == 0:
print("NO")
``` | 3 |
|
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes). | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,672,842,957 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | d = set()
for _ in range(int(input())):
s = input()
print("YES" if s not in d else "NO")
d.add(s) | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | ```python
d = set()
for _ in range(int(input())):
s = input()
print("YES" if s not in d else "NO")
d.add(s)
``` | 0 |
|
868 | B | Race Against Time | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face. | Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand. | Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"12 30 45 3 11\n",
"12 0 1 12 1\n",
"3 47 0 4 9\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | 500 | [
{
"input": "12 30 45 3 11",
"output": "NO"
},
{
"input": "12 0 1 12 1",
"output": "YES"
},
{
"input": "3 47 0 4 9",
"output": "YES"
},
{
"input": "10 22 59 6 10",
"output": "YES"
},
{
"input": "3 1 13 12 3",
"output": "NO"
},
{
"input": "11 19 28 9 10",
"output": "YES"
},
{
"input": "9 38 22 6 1",
"output": "NO"
},
{
"input": "5 41 11 5 8",
"output": "NO"
},
{
"input": "11 2 53 10 4",
"output": "YES"
},
{
"input": "9 41 17 10 1",
"output": "YES"
},
{
"input": "6 54 48 12 6",
"output": "YES"
},
{
"input": "12 55 9 5 1",
"output": "NO"
},
{
"input": "8 55 35 9 3",
"output": "NO"
},
{
"input": "3 21 34 3 10",
"output": "YES"
},
{
"input": "2 52 1 12 3",
"output": "NO"
},
{
"input": "7 17 11 1 7",
"output": "NO"
},
{
"input": "11 6 37 6 4",
"output": "YES"
},
{
"input": "9 6 22 8 1",
"output": "NO"
},
{
"input": "3 10 5 5 9",
"output": "YES"
},
{
"input": "7 12 22 11 2",
"output": "YES"
},
{
"input": "7 19 4 7 3",
"output": "NO"
},
{
"input": "11 36 21 4 6",
"output": "NO"
},
{
"input": "10 32 49 1 3",
"output": "YES"
},
{
"input": "1 9 43 11 3",
"output": "NO"
},
{
"input": "1 8 33 4 8",
"output": "NO"
},
{
"input": "3 0 33 9 4",
"output": "NO"
},
{
"input": "7 15 9 10 3",
"output": "NO"
},
{
"input": "8 3 57 11 1",
"output": "NO"
},
{
"input": "1 33 49 5 9",
"output": "NO"
},
{
"input": "3 40 0 5 7",
"output": "YES"
},
{
"input": "5 50 9 2 7",
"output": "NO"
},
{
"input": "10 0 52 6 1",
"output": "YES"
},
{
"input": "3 10 4 1 11",
"output": "NO"
},
{
"input": "2 41 53 4 6",
"output": "YES"
},
{
"input": "10 29 30 4 7",
"output": "NO"
},
{
"input": "5 13 54 9 11",
"output": "NO"
},
{
"input": "1 0 23 3 9",
"output": "NO"
},
{
"input": "1 0 41 12 1",
"output": "NO"
},
{
"input": "6 30 30 3 9",
"output": "YES"
},
{
"input": "3 7 32 11 10",
"output": "YES"
},
{
"input": "1 0 25 12 4",
"output": "NO"
},
{
"input": "12 0 0 5 6",
"output": "YES"
},
{
"input": "1 5 4 3 2",
"output": "YES"
},
{
"input": "6 30 30 9 10",
"output": "YES"
},
{
"input": "6 0 0 2 8",
"output": "NO"
},
{
"input": "10 50 59 9 10",
"output": "YES"
},
{
"input": "12 59 59 12 6",
"output": "NO"
},
{
"input": "3 0 30 3 4",
"output": "NO"
},
{
"input": "2 10 10 1 11",
"output": "YES"
},
{
"input": "10 5 30 1 12",
"output": "YES"
},
{
"input": "5 29 31 5 10",
"output": "YES"
},
{
"input": "5 2 2 11 2",
"output": "NO"
},
{
"input": "5 15 46 3 10",
"output": "YES"
},
{
"input": "1 30 50 1 2",
"output": "NO"
},
{
"input": "5 26 14 1 12",
"output": "YES"
},
{
"input": "1 58 43 12 1",
"output": "YES"
},
{
"input": "12 0 12 11 1",
"output": "NO"
},
{
"input": "6 52 41 6 5",
"output": "YES"
},
{
"input": "5 8 2 1 3",
"output": "NO"
},
{
"input": "2 0 0 1 3",
"output": "NO"
},
{
"input": "1 5 6 2 1",
"output": "YES"
},
{
"input": "9 5 5 11 12",
"output": "YES"
},
{
"input": "12 5 19 3 4",
"output": "NO"
},
{
"input": "6 14 59 1 3",
"output": "NO"
},
{
"input": "10 38 34 4 12",
"output": "YES"
},
{
"input": "2 54 14 2 12",
"output": "YES"
},
{
"input": "5 31 0 6 7",
"output": "NO"
},
{
"input": "6 15 30 3 9",
"output": "YES"
},
{
"input": "3 54 41 8 10",
"output": "NO"
},
{
"input": "3 39 10 10 12",
"output": "YES"
},
{
"input": "1 11 50 1 2",
"output": "NO"
},
{
"input": "5 40 24 8 1",
"output": "NO"
},
{
"input": "9 5 59 1 3",
"output": "NO"
},
{
"input": "5 0 0 6 7",
"output": "YES"
},
{
"input": "4 40 59 6 8",
"output": "YES"
},
{
"input": "10 13 55 12 1",
"output": "YES"
},
{
"input": "6 50 0 5 6",
"output": "YES"
},
{
"input": "7 59 3 7 4",
"output": "YES"
},
{
"input": "6 0 1 6 7",
"output": "NO"
},
{
"input": "6 15 55 3 5",
"output": "NO"
},
{
"input": "12 9 55 10 2",
"output": "YES"
},
{
"input": "2 0 1 11 2",
"output": "NO"
},
{
"input": "8 45 17 12 9",
"output": "NO"
},
{
"input": "5 30 31 11 3",
"output": "YES"
},
{
"input": "6 43 0 10 6",
"output": "NO"
},
{
"input": "6 30 30 1 11",
"output": "YES"
},
{
"input": "11 59 59 11 12",
"output": "YES"
},
{
"input": "5 45 35 9 5",
"output": "NO"
},
{
"input": "2 43 4 9 7",
"output": "NO"
},
{
"input": "12 30 50 6 9",
"output": "NO"
},
{
"input": "1 10 1 2 3",
"output": "NO"
},
{
"input": "10 5 55 9 1",
"output": "NO"
},
{
"input": "1 59 59 2 3",
"output": "YES"
},
{
"input": "1 49 14 10 3",
"output": "NO"
},
{
"input": "3 15 15 2 4",
"output": "YES"
},
{
"input": "10 5 55 1 5",
"output": "NO"
},
{
"input": "6 33 45 12 6",
"output": "YES"
},
{
"input": "1 20 20 11 1",
"output": "YES"
},
{
"input": "2 30 45 1 11",
"output": "YES"
},
{
"input": "1 55 1 11 10",
"output": "YES"
},
{
"input": "3 0 1 11 1",
"output": "NO"
},
{
"input": "1 5 6 1 12",
"output": "YES"
},
{
"input": "12 10 5 11 4",
"output": "YES"
},
{
"input": "6 5 59 12 1",
"output": "YES"
},
{
"input": "12 0 20 11 12",
"output": "YES"
},
{
"input": "3 25 30 4 5",
"output": "YES"
},
{
"input": "2 15 18 11 1",
"output": "YES"
},
{
"input": "12 5 48 11 9",
"output": "NO"
},
{
"input": "6 30 30 10 2",
"output": "YES"
},
{
"input": "1 0 11 1 2",
"output": "NO"
},
{
"input": "10 0 1 10 11",
"output": "NO"
},
{
"input": "3 30 45 10 1",
"output": "YES"
},
{
"input": "11 21 56 3 12",
"output": "YES"
},
{
"input": "3 16 16 3 4",
"output": "YES"
},
{
"input": "11 55 55 1 12",
"output": "YES"
},
{
"input": "12 12 12 11 12",
"output": "YES"
},
{
"input": "3 5 1 1 2",
"output": "NO"
},
{
"input": "3 30 45 10 11",
"output": "YES"
},
{
"input": "10 0 1 9 10",
"output": "YES"
},
{
"input": "3 0 5 3 6",
"output": "NO"
},
{
"input": "1 1 49 1 10",
"output": "NO"
},
{
"input": "9 45 15 11 12",
"output": "YES"
},
{
"input": "12 15 59 3 8",
"output": "NO"
},
{
"input": "5 0 5 3 6",
"output": "NO"
},
{
"input": "3 30 45 1 2",
"output": "YES"
},
{
"input": "2 10 11 2 4",
"output": "YES"
},
{
"input": "2 10 10 4 3",
"output": "YES"
},
{
"input": "3 30 59 1 2",
"output": "YES"
},
{
"input": "11 59 59 12 11",
"output": "YES"
},
{
"input": "10 25 50 5 6",
"output": "NO"
},
{
"input": "6 30 30 9 3",
"output": "YES"
},
{
"input": "8 14 40 12 3",
"output": "NO"
},
{
"input": "2 10 10 1 6",
"output": "YES"
}
] | 1,507,312,570 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | h,m,s,t1,t2=map(int,input().split())
if h==12:
h=0
if t1==12:
t1=0
if t2==12:
t2=0
m=int((m/60)*12)
s=int((s/60)*12)
l=[]
l.append(h)
l.append(m)
l.append(s)
l.sort()
#print (l)
p=[]
p.append(t1)
p.append(t2)
p.sort()
#print (p)
if l[0]==l[1]==l[2]:
print ("Yes")
else:
if t1>=l[0] and t2<=l[1]:
print ("Yes")
elif t1>=l[1] and t2<=l[2]:
print ("Yes")
elif t1>=l[2] and t2<=l[0]:
print ("Yes")
else:
print ("No") | Title: Race Against Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Input Specification:
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand.
Output Specification:
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['12 30 45 3 11\n', '12 0 1 12 1\n', '3 47 0 4 9\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | ```python
h,m,s,t1,t2=map(int,input().split())
if h==12:
h=0
if t1==12:
t1=0
if t2==12:
t2=0
m=int((m/60)*12)
s=int((s/60)*12)
l=[]
l.append(h)
l.append(m)
l.append(s)
l.sort()
#print (l)
p=[]
p.append(t1)
p.append(t2)
p.sort()
#print (p)
if l[0]==l[1]==l[2]:
print ("Yes")
else:
if t1>=l[0] and t2<=l[1]:
print ("Yes")
elif t1>=l[1] and t2<=l[2]:
print ("Yes")
elif t1>=l[2] and t2<=l[0]:
print ("Yes")
else:
print ("No")
``` | 0 |
|
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
"output": "50"
},
{
"input": "101",
"output": "-51"
},
{
"input": "102",
"output": "51"
},
{
"input": "103",
"output": "-52"
},
{
"input": "104",
"output": "52"
},
{
"input": "105",
"output": "-53"
},
{
"input": "106",
"output": "53"
},
{
"input": "107",
"output": "-54"
},
{
"input": "108",
"output": "54"
},
{
"input": "109",
"output": "-55"
},
{
"input": "208170109961052",
"output": "104085054980526"
},
{
"input": "46017661651072",
"output": "23008830825536"
},
{
"input": "4018154546667",
"output": "-2009077273334"
},
{
"input": "288565475053",
"output": "-144282737527"
},
{
"input": "3052460231",
"output": "-1526230116"
},
{
"input": "29906716",
"output": "14953358"
},
{
"input": "87897701693326",
"output": "43948850846663"
},
{
"input": "8240",
"output": "4120"
},
{
"input": "577935",
"output": "-288968"
},
{
"input": "62",
"output": "31"
},
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "1"
},
{
"input": "9999999999999",
"output": "-5000000000000"
},
{
"input": "1000000000000",
"output": "500000000000"
},
{
"input": "99999999999999",
"output": "-50000000000000"
},
{
"input": "999999999999999",
"output": "-500000000000000"
},
{
"input": "42191359342",
"output": "21095679671"
},
{
"input": "100000000000000",
"output": "50000000000000"
},
{
"input": "145645214654154",
"output": "72822607327077"
},
{
"input": "4294967296",
"output": "2147483648"
},
{
"input": "3037000499",
"output": "-1518500250"
},
{
"input": "10000000000001",
"output": "-5000000000001"
},
{
"input": "100000017040846",
"output": "50000008520423"
},
{
"input": "98979894985999",
"output": "-49489947493000"
}
] | 1,693,220,510 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 93 | 0 | y = int(input())
print(y//2-y * (y%2)) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Output Specification:
Print *f*(*n*) in a single line.
Demo Input:
['4\n', '5\n']
Demo Output:
['2\n', '-3\n']
Note:
*f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | ```python
y = int(input())
print(y//2-y * (y%2))
``` | 3 |
|
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence.
The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1. | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "4 3\n1 2 3 4",
"output": "-1"
},
{
"input": "5 3\n2 1 1 1 1",
"output": "1"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "0"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10 1\n1 2 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "10 1\n2 1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "10 2\n2 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 2\n1 2 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "10 3\n3 2 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "-1"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10",
"output": "19"
}
] | 1,630,465,600 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 186 | 14,438,400 | n, k = map(int, input().split())
if n == 1:
arr = [int(input())]
else:
arr = list(map(int, input().split()))
fromK = set(arr[k-1:])
if len(fromK)>1:
print(-1)
else:
i=k-1
while i>=0 and arr[i]==arr[k-1]:
i-=1
print(i+1)
| Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence.
The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
Input Specification:
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Output Specification:
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
Demo Input:
['3 2\n3 1 1\n', '3 1\n3 1 1\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1. | ```python
n, k = map(int, input().split())
if n == 1:
arr = [int(input())]
else:
arr = list(map(int, input().split()))
fromK = set(arr[k-1:])
if len(fromK)>1:
print(-1)
else:
i=k-1
while i>=0 and arr[i]==arr[k-1]:
i-=1
print(i+1)
``` | 3 |
|
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,695,217,879 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | t=int(input())
if(t%4==0):
print("YES")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
t=int(input())
if(t%4==0):
print("YES")
else:
print("NO")
``` | 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,616,482,458 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 1,331,200 | x,y,n=[int(a) for a in input().split()]
r=0
for i in range(n):
if(x%y==0):
x=x*10
else:
x=x*10+9
d=x%y
if(d>10):
r=1
break
else:
x=x-d
if(r):
print(-1)
else:
print(x)
| 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
x,y,n=[int(a) for a in input().split()]
r=0
for i in range(n):
if(x%y==0):
x=x*10
else:
x=x*10+9
d=x%y
if(d>10):
r=1
break
else:
x=x-d
if(r):
print(-1)
else:
print(x)
``` | 0 |
|
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest".
A palindrome is a string that reads the same forward or backward.
The length of string *B* should be at most 104. It is guaranteed that there always exists such string.
You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpa",
"output": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpaapkxovfyaifzjikpcxhemrcpwhypaabnoeifgfygtiqvuoihntvuvbrlnkywutodwrmvgrumdjzqhfoenxphzrdgtwmljdm..."
},
{
"input": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadco",
"output": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadcoocdafcilhkrgpvtsyrmzilywzgrtebnaldqqcmrfvsfehjkbetprwlvyscuxef..."
},
{
"input": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxar",
"output": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxarraxluhthchsyjjpegbmmzflbvzbunpfhzruoghtlgtearurzueovxcivvfbqlssonqkjiybmbjbzpffixfcdwbrpwyhvzbdjmchzjfnrjdoupimgkyyhfgppveltacqczktdxkawpzdmkmyikyjtqznvjdnkkmikemtyjsgdlheyjltiwcxpfvxqtxwwvgkjcrzbkxkandsekqwxpequ..."
},
{
"input": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjg",
"output": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjggjferujlznjmyalmuspib..."
},
{
"input": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgm",
"output": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgmmgszzmttxopywvrbvmgavsgwqergikztssmlnktgpolmcbrropknnkeiytztyrlqthshvbosemmjbzpsvcytuzynrqygcfoqsywdkrvjftdagjdgjyynfkcdkmwaqhzfewry..."
},
{
"input": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyj",
"output": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyjjycqccvmgjgqjfbxjzrdgbsqyseehcjsyxlbrettpfcjdvjerwvaixetfjxjxkdwcwlmwqkrgrhwzopjnilmonwtxsdonvyuazaqghlplvlisqdqbpvxkjpovqohbarttqoqm..."
},
{
"input": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgd",
"output": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgddgmsixjxsmwpfzyxrnkjqrbrfyprvlvbegdmgsidepusixegsdukxmudmjuqqzkefrzymgkluqqrigtpmznhvswwhqbiiizogjofdvfqdrfabswiclfpkiermnozbdmxieoxornesifoiuxgffjelsvcoofviyorrpwkffvvfjaubzeuzqbdhfjgujqoejsktzfzaypaxipweiawzojidcustlgyfhkbfgwshbdkzneilwwqemqblw..."
},
{
"input": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohlig",
"output": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohliggilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlw..."
},
{
"input": "abcab",
"output": "abcabbacba"
},
{
"input": "baaaaaaa",
"output": "baaaaaaaaaaaaaab"
},
{
"input": "baaaaaa",
"output": "baaaaaaaaaaaab"
},
{
"input": "baaaaaaaaa",
"output": "baaaaaaaaaaaaaaaaaab"
},
{
"input": "baaaaaaaa",
"output": "baaaaaaaaaaaaaaaab"
}
] | 1,518,706,430 | 1,130 | Python 3 | OK | TESTS | 48 | 77 | 5,632,000 | a=input()
a1,c=a[::-1],-1
if a==a1:
print(a)
quit()
for i in range(len(a)):
if a[i:]==a1[:-i]:
c=i
break
if c==-1:
print(a+a1)
quit()
print(a+a[:c][::-1])
| Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest".
A palindrome is a string that reads the same forward or backward.
The length of string *B* should be at most 104. It is guaranteed that there always exists such string.
You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104.
Input Specification:
First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*.
Output Specification:
Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them.
Demo Input:
['aba\n', 'ab\n']
Demo Output:
['aba', 'aabaa']
Note:
In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | ```python
a=input()
a1,c=a[::-1],-1
if a==a1:
print(a)
quit()
for i in range(len(a)):
if a[i:]==a1[:-i]:
c=i
break
if c==-1:
print(a+a1)
quit()
print(a+a[:c][::-1])
``` | 3 |
|
670 | B | Game of Robots | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the *n*-th robot says his identifier.
Your task is to determine the *k*-th identifier to be pronounced. | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(2·109,<=*n*·(*n*<=+<=1)<=/<=2).
The second line contains the sequence *id*1,<=*id*2,<=...,<=*id**n* (1<=≤<=*id**i*<=≤<=109) — identifiers of roborts. It is guaranteed that all identifiers are different. | Print the *k*-th pronounced identifier (assume that the numeration starts from 1). | [
"2 2\n1 2\n",
"4 5\n10 4 18 3\n"
] | [
"1\n",
"4\n"
] | In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As *k* = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As *k* = 5, the answer equals to 4. | 750 | [
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "4 5\n10 4 18 3",
"output": "4"
},
{
"input": "1 1\n4",
"output": "4"
},
{
"input": "2 1\n5 1",
"output": "5"
},
{
"input": "2 2\n1 4",
"output": "1"
},
{
"input": "2 3\n6 7",
"output": "7"
},
{
"input": "3 1\n4 5 6",
"output": "4"
},
{
"input": "3 2\n4 5 6",
"output": "4"
},
{
"input": "3 3\n4 5 6",
"output": "5"
},
{
"input": "3 4\n4 5 6",
"output": "4"
},
{
"input": "3 5\n4 5 6",
"output": "5"
},
{
"input": "3 6\n4 5 6",
"output": "6"
},
{
"input": "4 1\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 2\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 3\n5 1000000000 999999999 12",
"output": "1000000000"
},
{
"input": "4 4\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 5\n5 1000000000 999999999 12",
"output": "1000000000"
},
{
"input": "4 6\n5 1000000000 999999999 12",
"output": "999999999"
},
{
"input": "4 7\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 8\n5 1000000000 999999999 12",
"output": "1000000000"
},
{
"input": "4 9\n5 1000000000 999999999 12",
"output": "999999999"
},
{
"input": "4 10\n5 1000000000 999999999 12",
"output": "12"
}
] | 1,638,496,652 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 12 | 1,013 | 268,390,400 | n,k = input().split(" ")
n = int(n)
k = int(k)
l = input().split(" ")
t = []
for i in range(len(l)):
t.extend(l[:i+1])
print(t[k-1])
| Title: Game of Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the *n*-th robot says his identifier.
Your task is to determine the *k*-th identifier to be pronounced.
Input Specification:
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(2·109,<=*n*·(*n*<=+<=1)<=/<=2).
The second line contains the sequence *id*1,<=*id*2,<=...,<=*id**n* (1<=≤<=*id**i*<=≤<=109) — identifiers of roborts. It is guaranteed that all identifiers are different.
Output Specification:
Print the *k*-th pronounced identifier (assume that the numeration starts from 1).
Demo Input:
['2 2\n1 2\n', '4 5\n10 4 18 3\n']
Demo Output:
['1\n', '4\n']
Note:
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As *k* = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As *k* = 5, the answer equals to 4. | ```python
n,k = input().split(" ")
n = int(n)
k = int(k)
l = input().split(" ")
t = []
for i in range(len(l)):
t.extend(l[:i+1])
print(t[k-1])
``` | 0 |
|
519 | A | A and B and Chess | PROGRAMMING | 900 | [
"implementation"
] | null | null | A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
- the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight. | The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on. | Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. | [
"...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n",
"rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n",
"rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n"
] | [
"White\n",
"Draw\n",
"Black\n"
] | In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | 500 | [
{
"input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR",
"output": "Draw"
},
{
"input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..",
"output": "White"
},
{
"input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\n..K..rNn\nP.....p.\n...Q..B.",
"output": "White"
},
{
"input": "...Nn...\n........\n........\n........\n.R....b.\n........\n........\n......p.",
"output": "White"
},
{
"input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq",
"output": "Black"
},
{
"input": "QQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ",
"output": "White"
},
{
"input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ",
"output": "Draw"
},
{
"input": "QQQQQQQQ\nQQQQQQQQ\n........\n........\n........\n........\nrrrrrr..\nrrrrrrrr",
"output": "White"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\n.......n",
"output": "Black"
},
{
"input": "........\n...b....\n........\n........\n........\n........\n........\n.......K",
"output": "Black"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\n......Kp",
"output": "Black"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\n.......Q",
"output": "White"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\n......Bp",
"output": "White"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\nkkkkkB..",
"output": "White"
},
{
"input": "QqPQNN.Q\n.qBbr.qB\np.RKBpNK\nPknBr.nq\nKqKRNKKk\n.BqPqkb.\nPBNPr.rk\nBpBKrPRR",
"output": "Black"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\n.......K",
"output": "Draw"
}
] | 1,700,035,396 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 92 | 0 | power = {
'q' : 9,
'r' : 5,
'b' : 3,
'n' : 3,
'p' : 1,
'k' : 0}
sw = 0
sb = 0
for i in range(8):
l = input()
for w in l:
if w == '.':
continue
if w.islower():
sb += power[w]
else:
sw += power[w.lower()]
if sw > sb:
print('White')
elif sw == sb:
print('Draw')
else:
print('Black')
| Title: A and B and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
- the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input Specification:
The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Output Specification:
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Demo Input:
['...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n', 'rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n', 'rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n']
Demo Output:
['White\n', 'Draw\n', 'Black\n']
Note:
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16. | ```python
power = {
'q' : 9,
'r' : 5,
'b' : 3,
'n' : 3,
'p' : 1,
'k' : 0}
sw = 0
sb = 0
for i in range(8):
l = input()
for w in l:
if w == '.':
continue
if w.islower():
sb += power[w]
else:
sw += power[w.lower()]
if sw > sb:
print('White')
elif sw == sb:
print('Draw')
else:
print('Black')
``` | 3 |
|
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51",
"output": "6"
},
{
"input": "2 400 23 57",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10000 10000 3 2",
"output": "16670000"
},
{
"input": "1 2 1 2",
"output": "1"
},
{
"input": "1 1 2 2",
"output": "1"
},
{
"input": "1 1 10 10",
"output": "1"
},
{
"input": "5324 5439 32 13",
"output": "69622"
},
{
"input": "9000 1 2432 1",
"output": "9000"
},
{
"input": "230 1234 9124 23",
"output": "10"
},
{
"input": "11 1 1 1",
"output": "11"
},
{
"input": "6246 8489 1227 9",
"output": "4858"
},
{
"input": "9 20 5 7",
"output": "6"
}
] | 1,609,438,547 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 93 | 0 | # A. Paper Airplanes
k, n, s, p = map(int, input().split())
sheets = (n + s - 1) // s
print((sheets * k + p - 1) // p)
| Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
Input Specification:
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output Specification:
Print a single integer — the minimum number of packs they should buy.
Demo Input:
['5 3 2 3\n', '5 3 100 1\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | ```python
# A. Paper Airplanes
k, n, s, p = map(int, input().split())
sheets = (n + s - 1) // s
print((sheets * k + p - 1) // p)
``` | 3 |
|
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output": "I hate that I love that I hate that I love that I hate it"
},
{
"input": "10",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "18",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "19",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "76",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "77",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "81",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "82",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "85",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "86",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "99",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "98",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "33",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "34",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "57",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
}
] | 1,685,783,843 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n=int(input())
ans="I hate "
for i in range (1,n):
if i % 2 == 0:
ans+="that I love "
else :
ans+="that I hate "
ans+="it"
print(ans)
| Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
n=int(input())
ans="I hate "
for i in range (1,n):
if i % 2 == 0:
ans+="that I love "
else :
ans+="that I hate "
ans+="it"
print(ans)
``` | 0 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,670,330,472 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 0 | n=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr2=[]
dict={}
for i in range(n[0]):
if(arr[i]%n[1]==0):
arr2.append(arr[i]/n[1])
else:
arr2.append(int(arr[i]/n[1])+1)
x=max(arr2)
for i in range(len(arr2)):
if(arr2[i]==x):
dict[i]=x
print(list(dict.keys())[-1]+1)
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
n=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr2=[]
dict={}
for i in range(n[0]):
if(arr[i]%n[1]==0):
arr2.append(arr[i]/n[1])
else:
arr2.append(int(arr[i]/n[1])+1)
x=max(arr2)
for i in range(len(arr2)):
if(arr2[i]==x):
dict[i]=x
print(list(dict.keys())[-1]+1)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.