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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.
More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.
Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "80"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1",
"output": "53"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "3\n1 0 0",
"output": "2"
},
{
"input": "10\n1 1 0 0 0 1 1 0 0 0",
"output": "6"
},
{
"input": "90\n1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0",
"output": "52"
},
{
"input": "78\n0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0",
"output": "42"
},
{
"input": "4\n1 0 0 1",
"output": "3"
},
{
"input": "2\n0 1",
"output": "2"
},
{
"input": "5\n0 1 0 0 1",
"output": "4"
},
{
"input": "3\n1 0 1",
"output": "2"
},
{
"input": "3\n1 1 0",
"output": "2"
},
{
"input": "16\n1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1",
"output": "9"
}
] | 1,634,028,303 | 903 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 77 | 20,172,800 | n = int(input())
S = list(map(int, input().split()))
ans = 0
c0 = 0
c1 = 0
for c in S:
if c == 0:
c0 += 1
else:
c1 += 1
ans = max(c0, c1)
C0 = [0]*(n+1)
C1 = [0]*(n+1)
for i, c in enumerate(S):
if c == 0:
C0[i+1] += 1
else:
C1[i+1] += 1
from itertools import accumulate
C0 = list(accumulate(C0))
C1 = list(accumulate(C1))
for l in range(n):
if S[l] == 0:
continue
for r in range(l, n):
if C1[r+1]-C1[l] != r-l+1:
break
ans = max(C1[r+1]-C1[l]+C0[l], ans)
print(ans)
| Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.
More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.
Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one.
Output Specification:
Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
Demo Input:
['4\n1 1 0 1\n', '6\n0 1 0 0 1 0\n', '1\n0\n']
Demo Output:
['3\n', '4\n', '1\n']
Note:
none | ```python
n = int(input())
S = list(map(int, input().split()))
ans = 0
c0 = 0
c1 = 0
for c in S:
if c == 0:
c0 += 1
else:
c1 += 1
ans = max(c0, c1)
C0 = [0]*(n+1)
C1 = [0]*(n+1)
for i, c in enumerate(S):
if c == 0:
C0[i+1] += 1
else:
C1[i+1] += 1
from itertools import accumulate
C0 = list(accumulate(C0))
C1 = list(accumulate(C1))
for l in range(n):
if S[l] == 0:
continue
for r in range(l, n):
if C1[r+1]-C1[l] != r-l+1:
break
ans = max(C1[r+1]-C1[l]+C0[l], ans)
print(ans)
``` | 0 |
|
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique. | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-2000000000 0 0 -2000000000"
},
{
"input": "1000000000 1000000000",
"output": "0 2000000000 2000000000 0"
},
{
"input": "-123131 3123141",
"output": "-3246272 0 0 3246272"
},
{
"input": "-23423 -243242423",
"output": "-243265846 0 0 -243265846"
},
{
"input": "123112 4560954",
"output": "0 4684066 4684066 0"
},
{
"input": "1321 -23131",
"output": "0 -24452 24452 0"
},
{
"input": "1000000000 999999999",
"output": "0 1999999999 1999999999 0"
},
{
"input": "54543 432423",
"output": "0 486966 486966 0"
},
{
"input": "1 1",
"output": "0 2 2 0"
},
{
"input": "-1 -1",
"output": "-2 0 0 -2"
},
{
"input": "-1 1",
"output": "-2 0 0 2"
},
{
"input": "1 -1",
"output": "0 -2 2 0"
},
{
"input": "42 -2",
"output": "0 -44 44 0"
},
{
"input": "2 -435",
"output": "0 -437 437 0"
},
{
"input": "76 -76",
"output": "0 -152 152 0"
},
{
"input": "1000000000 1",
"output": "0 1000000001 1000000001 0"
},
{
"input": "1000000000 -1",
"output": "0 -1000000001 1000000001 0"
},
{
"input": "-1000000000 1",
"output": "-1000000001 0 0 1000000001"
},
{
"input": "-1000000000 -1",
"output": "-1000000001 0 0 -1000000001"
},
{
"input": "1000000000 -999999999",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-1000000000 999999999",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "-1000000000 -999999999",
"output": "-1999999999 0 0 -1999999999"
},
{
"input": "999999999 1000000000",
"output": "0 1999999999 1999999999 0"
},
{
"input": "-999999999 1000000000",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "999999999 -1000000000",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-999999999 -1000000000",
"output": "-1999999999 0 0 -1999999999"
}
] | 1,592,671,189 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 307,200 | x,y=[int(x) for x in input().split(" ")]
if(x>=0 and y>=0):
s=x+y
print(0,s,s,0)
if(x<0 and y>=0):
d=x*-1
s=d+y
print(-s,0,0,s)
if(x>=0 and y<0):
d=y*-1
s=d+x
print(0,-s,s,0)
if(x<0 and y<0):
d=x*-1
e=y*-1
s=d+e
print(-s,0,0,-s) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique.
Input Specification:
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Output Specification:
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
Demo Input:
['10 5\n', '-10 5\n']
Demo Output:
['0 15 15 0\n', '-15 0 0 15\n']
Note:
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | ```python
x,y=[int(x) for x in input().split(" ")]
if(x>=0 and y>=0):
s=x+y
print(0,s,s,0)
if(x<0 and y>=0):
d=x*-1
s=d+y
print(-s,0,0,s)
if(x>=0 and y<0):
d=y*-1
s=d+x
print(0,-s,s,0)
if(x<0 and y<0):
d=x*-1
e=y*-1
s=d+e
print(-s,0,0,-s)
``` | 3 |
|
538 | A | Cutting Banner | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES. | The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. | Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). | [
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "NQTSMZEBLY",
"output": "NO"
},
{
"input": "CODEFZORCES",
"output": "YES"
},
{
"input": "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF",
"output": "NO"
},
{
"input": "OCECFDSRDE",
"output": "NO"
},
{
"input": "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEWFS",
"output": "NO"
},
{
"input": "CODEFYTORCHES",
"output": "NO"
},
{
"input": "BCODEFORCES",
"output": "YES"
},
{
"input": "CVODEFORCES",
"output": "YES"
},
{
"input": "COAKDEFORCES",
"output": "YES"
},
{
"input": "CODFMWEFORCES",
"output": "YES"
},
{
"input": "CODEVCSYRFORCES",
"output": "YES"
},
{
"input": "CODEFXHHPWCVQORCES",
"output": "YES"
},
{
"input": "CODEFORQWUFJLOFFXTXRCES",
"output": "YES"
},
{
"input": "CODEFORBWFURYIDURNRKRDLHCLXZCES",
"output": "YES"
},
{
"input": "CODEFORCQSYSLYKCDFFUPSAZCJIAENCKZUFJZEINQIES",
"output": "YES"
},
{
"input": "CODEFORCEVENMDBQLSVPQIIBGSHBVOPYZXNWVSTVWDRONUREYJJIJIPMEBPQDCPFS",
"output": "YES"
},
{
"input": "CODEFORCESCFNNPAHNHDIPPBAUSPKJYAQDBVZNLSTSDCREZACVLMRFGVKGVHHZLXOHCTJDBQKIDWBUXDUJARLWGFGFCTTXUCAZB",
"output": "YES"
},
{
"input": "CODJRDPDEFOROES",
"output": "NO"
},
{
"input": "CODEFOGSIUZMZCMWAVQHNYFEKIEZQMAZOVEMDRMOEDBHAXPLBLDYYXCVTOOSJZVSQAKFXTBTZFWAYRZEMDEMVDJTDRXXAQBURCES",
"output": "YES"
},
{
"input": "CODEMKUYHAZSGJBQLXTHUCZZRJJJXUSEBOCNZASOKDZHMSGWZSDFBGHXFLABVPDQBJYXSHHAZAKHSTRGOKJYHRVSSUGDCMFOGCES",
"output": "NO"
},
{
"input": "CODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCES",
"output": "YES"
},
{
"input": "CCODEFORCESODECODEFORCCODEFORCESODCODEFORCESEFCODEFORCESORCODEFORCESCESCESFORCODEFORCESCES",
"output": "NO"
},
{
"input": "CCODEFORCESC",
"output": "NO"
},
{
"input": "CODEAFORBCES",
"output": "NO"
},
{
"input": "CODERRRRRFORCRRRRES",
"output": "NO"
},
{
"input": "CODELFORCELS",
"output": "NO"
},
{
"input": "CPOPDPEPFPOPRPCPEPS",
"output": "NO"
},
{
"input": "COXDEXFORXCEXS",
"output": "NO"
},
{
"input": "CODAAAAAFORCES",
"output": "NO"
},
{
"input": "CAOADEFORCES",
"output": "NO"
},
{
"input": "FORCESXCODE",
"output": "NO"
},
{
"input": "FORCESACODE",
"output": "NO"
},
{
"input": "ACAOADAEFORCES",
"output": "NO"
},
{
"input": "CCODEFORCESS",
"output": "NO"
},
{
"input": "ZCODEFORCEZ",
"output": "NO"
},
{
"input": "CODXEFORXCES",
"output": "NO"
},
{
"input": "CODEFORCEZ",
"output": "NO"
},
{
"input": "CODEFORCEST",
"output": "YES"
},
{
"input": "AXODEFORCES",
"output": "NO"
},
{
"input": "RCODEFORCESR",
"output": "NO"
},
{
"input": "CODECODEFORCESFORCES",
"output": "YES"
},
{
"input": "TTTWWWCODEFORCES",
"output": "YES"
},
{
"input": "CODEFORRCEST",
"output": "NO"
},
{
"input": "UJYTYUCODEFORCES",
"output": "YES"
},
{
"input": "CODEXXXXXXXXXXXXXXXXXXCODEFORCESXXXXXXXXXXXXXXXXXXXXXFORCES",
"output": "YES"
},
{
"input": "COXEDYFORCES",
"output": "NO"
},
{
"input": "UJYTYCODEFORCES",
"output": "YES"
},
{
"input": "UJYTCODEFORCES",
"output": "YES"
}
] | 1,534,428,305 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 28 | 140 | 0 | x=input()
a='CODEFORCES'
for i in range(len(a)):
if(''.join(a[:i+1]) in x and ''.join(a[i+1:]) in x):
print('YES')
exit()
print('NO') | Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
Input Specification:
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Output Specification:
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
Demo Input:
['CODEWAITFORITFORCES\n', 'BOTTOMCODER\n', 'DECODEFORCES\n', 'DOGEFORCES\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
x=input()
a='CODEFORCES'
for i in range(len(a)):
if(''.join(a[:i+1]) in x and ''.join(a[i+1:]) in x):
print('YES')
exit()
print('NO')
``` | 0 |
|
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions).
Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 1 100000 100001",
"output": "NO"
},
{
"input": "25 10000 200 10000 5",
"output": "YES"
},
{
"input": "1 100000 10 100000 50000",
"output": "NO"
},
{
"input": "91939 94921 10197 89487 1",
"output": "NO"
},
{
"input": "30518 58228 74071 77671 1",
"output": "NO"
},
{
"input": "46646 79126 78816 91164 5",
"output": "NO"
},
{
"input": "30070 83417 92074 99337 2",
"output": "NO"
},
{
"input": "13494 17544 96820 99660 6",
"output": "NO"
},
{
"input": "96918 97018 10077 86510 9",
"output": "YES"
},
{
"input": "13046 45594 14823 52475 1",
"output": "YES"
},
{
"input": "29174 40572 95377 97669 4",
"output": "NO"
},
{
"input": "79894 92433 8634 86398 4",
"output": "YES"
},
{
"input": "96022 98362 13380 94100 6",
"output": "YES"
},
{
"input": "79446 95675 93934 96272 3",
"output": "NO"
},
{
"input": "5440 46549 61481 99500 10",
"output": "NO"
},
{
"input": "21569 53580 74739 87749 3",
"output": "NO"
},
{
"input": "72289 78297 79484 98991 7",
"output": "NO"
},
{
"input": "88417 96645 92742 98450 5",
"output": "NO"
},
{
"input": "71841 96625 73295 77648 8",
"output": "NO"
},
{
"input": "87969 99230 78041 94736 4",
"output": "NO"
},
{
"input": "4 4 1 2 3",
"output": "NO"
},
{
"input": "150 150 1 2 100",
"output": "NO"
},
{
"input": "99 100 1 100 50",
"output": "YES"
},
{
"input": "7 7 3 6 2",
"output": "NO"
},
{
"input": "10 10 1 10 1",
"output": "YES"
},
{
"input": "36 36 5 7 6",
"output": "YES"
},
{
"input": "73 96 1 51 51",
"output": "NO"
},
{
"input": "3 3 1 3 2",
"output": "NO"
},
{
"input": "10000000 10000000 1 100000 10000000",
"output": "YES"
},
{
"input": "9222174 9829060 9418763 9955619 9092468",
"output": "NO"
},
{
"input": "70 70 1 2 50",
"output": "NO"
},
{
"input": "100 200 1 20 5",
"output": "YES"
},
{
"input": "1 200000 65536 65536 65537",
"output": "NO"
},
{
"input": "15 15 1 100 1",
"output": "YES"
},
{
"input": "10000000 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "10 10 2 5 4",
"output": "NO"
},
{
"input": "67 69 7 7 9",
"output": "NO"
},
{
"input": "100000 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "9 12 1 2 7",
"output": "NO"
},
{
"input": "5426234 6375745 2636512 8492816 4409404",
"output": "NO"
},
{
"input": "6134912 6134912 10000000 10000000 999869",
"output": "NO"
},
{
"input": "3 3 1 100 1",
"output": "YES"
},
{
"input": "10000000 10000000 10 10000000 100000",
"output": "YES"
},
{
"input": "4 4 1 100 2",
"output": "YES"
},
{
"input": "8 13 1 4 7",
"output": "NO"
},
{
"input": "10 10 100000 10000000 10000000",
"output": "NO"
},
{
"input": "5 6 1 4 2",
"output": "YES"
},
{
"input": "1002 1003 1 2 1000",
"output": "NO"
},
{
"input": "4 5 1 2 2",
"output": "YES"
},
{
"input": "5 6 1 5 1",
"output": "YES"
},
{
"input": "15 21 2 4 7",
"output": "YES"
},
{
"input": "4 5 3 7 1",
"output": "YES"
},
{
"input": "15 15 3 4 4",
"output": "NO"
},
{
"input": "3 6 1 2 2",
"output": "YES"
},
{
"input": "2 10 3 6 3",
"output": "YES"
},
{
"input": "1 10000000 1 10000000 100000",
"output": "YES"
},
{
"input": "8 13 1 2 7",
"output": "NO"
},
{
"input": "98112 98112 100000 100000 128850",
"output": "NO"
},
{
"input": "2 2 1 2 1",
"output": "YES"
},
{
"input": "8 8 3 4 2",
"output": "YES"
},
{
"input": "60 60 2 3 25",
"output": "NO"
},
{
"input": "16 17 2 5 5",
"output": "NO"
},
{
"input": "2 4 1 3 1",
"output": "YES"
},
{
"input": "4 5 1 2 3",
"output": "NO"
},
{
"input": "10 10 3 4 3",
"output": "NO"
},
{
"input": "10 10000000 999999 10000000 300",
"output": "NO"
},
{
"input": "100 120 9 11 10",
"output": "YES"
},
{
"input": "8 20 1 3 4",
"output": "YES"
},
{
"input": "10 14 2 3 4",
"output": "YES"
},
{
"input": "2000 2001 1 3 1000",
"output": "YES"
},
{
"input": "12 13 2 3 5",
"output": "NO"
},
{
"input": "7 7 2 3 3",
"output": "NO"
},
{
"input": "5 8 1 10000000 4",
"output": "YES"
},
{
"input": "5 5 1 1 4",
"output": "NO"
},
{
"input": "5 5 1 6 2",
"output": "NO"
},
{
"input": "200 300 4000381 4000382 4000381",
"output": "NO"
},
{
"input": "11 17 2 5 2",
"output": "NO"
},
{
"input": "9999999 10000000 1 10000000 999997",
"output": "NO"
},
{
"input": "7 8 2 3 3",
"output": "NO"
},
{
"input": "7 7 3 3 2",
"output": "NO"
},
{
"input": "15 15 2 3 7",
"output": "NO"
},
{
"input": "65408 65408 859 859 10000000",
"output": "NO"
},
{
"input": "1000000 10000000 1 100000 1",
"output": "NO"
},
{
"input": "6 12 2 3 2",
"output": "YES"
},
{
"input": "7 8 1 3 3",
"output": "NO"
},
{
"input": "4 4 1 2 2",
"output": "YES"
},
{
"input": "2 3 1 2 2",
"output": "YES"
},
{
"input": "11 14 2 3 5",
"output": "NO"
},
{
"input": "7 7 1 10 3",
"output": "NO"
},
{
"input": "49 50 1 2 27",
"output": "NO"
},
{
"input": "1 10000000 1 10000000 123456",
"output": "YES"
},
{
"input": "100000 10000000 100 10000000 100000",
"output": "YES"
},
{
"input": "17 19 2 3 8",
"output": "NO"
},
{
"input": "4 6 3 9 1",
"output": "YES"
},
{
"input": "19 20 6 7 3",
"output": "NO"
},
{
"input": "5000000 10000000 1 4999999 1",
"output": "NO"
}
] | 1,510,091,602 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 50 | 2,000 | 0 | '''input
1 100000 1 100000 100000
'''
l, r, x, y, k = map(int, input().split())
if (r-l) > (x-y):
for b in range(x, y+1):
if l <= k*b <= r:
print("YES")
quit()
else:
for a in range(l, r+1):
if x <= k*a <= y:
print("YES")
quit()
print("NO")
| Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions).
Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
Input Specification:
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Output Specification:
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register.
Demo Input:
['1 10 1 10 1\n', '1 5 6 10 1\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
'''input
1 100000 1 100000 100000
'''
l, r, x, y, k = map(int, input().split())
if (r-l) > (x-y):
for b in range(x, y+1):
if l <= k*b <= r:
print("YES")
quit()
else:
for a in range(l, r+1):
if x <= k*a <= y:
print("YES")
quit()
print("NO")
``` | 0 |
|
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); - or the girl in the dancing pair must dance for the first time.
Help Fox Ciel to make a schedule that they can dance as many songs as possible. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
},
{
"input": "1 12",
"output": "12\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12"
},
{
"input": "12 1",
"output": "12\n1 1\n12 1\n11 1\n10 1\n9 1\n8 1\n7 1\n6 1\n5 1\n4 1\n3 1\n2 1"
},
{
"input": "100 100",
"output": "199\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "24 6",
"output": "29\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n24 6\n23 6\n22 6\n21 6\n20 6\n19 6\n18 6\n17 6\n16 6\n15 6\n14 6\n13 6\n12 6\n11 6\n10 6\n9 6\n8 6\n7 6\n6 6\n5 6\n4 6\n3 6\n2 6"
},
{
"input": "7 59",
"output": "65\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n7 59\n6 59\n5 59\n4 59\n3 59\n2 59"
},
{
"input": "26 75",
"output": "100\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n26 75\n25 75\n24 75\n23 75\n22 75\n21 75\n20 75\n19 75\n18 75\n17..."
},
{
"input": "32 87",
"output": "118\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "42 51",
"output": "92\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n42 51\n41 51\n40 51\n39 51\n38 51\n37 51\n36 51\n35 51\n34 51\n33 51\n32 51\n31 51\n30 51\n29 51\n28 51\n27 51\n26 51\n25 51\n24 51\n23 51\n22 51\n21 51\n20 51\n19 51\n18 51\n17 51\n16 51\n15 51\n14 51\n13 51\n..."
},
{
"input": "4 63",
"output": "66\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n4 63\n3 63\n2 63"
},
{
"input": "10 79",
"output": "88\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n10 79\n9 79\n8 79\n7 79\n6 79\n5 79\n4 79\n..."
},
{
"input": "20 95",
"output": "114\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "35 55",
"output": "89\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n35 55\n34 55\n33 55\n32 55\n31 55\n30 55\n29 55\n28 55\n27 55\n26 55\n25 55\n24 55\n23 55\n22 55\n21 55\n20 55\n19 55\n18 55\n17 55\n16 55\n15 55\n14 55\n13 55\n12 55\n11 55\n10 55\n9 55..."
},
{
"input": "45 71",
"output": "115\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n45 71\n44 71\n43 71\n42 71\n41 71\n40 71\n39 71\n38 71\n37 71\n36 71\n35 71\n34 71\n33 71..."
},
{
"input": "7 83",
"output": "89\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n7 83\n6 83\n5 83\n..."
},
{
"input": "32 100",
"output": "131\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "42 17",
"output": "58\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n42 17\n41 17\n40 17\n39 17\n38 17\n37 17\n36 17\n35 17\n34 17\n33 17\n32 17\n31 17\n30 17\n29 17\n28 17\n27 17\n26 17\n25 17\n24 17\n23 17\n22 17\n21 17\n20 17\n19 17\n18 17\n17 17\n16 17\n15 17\n14 17\n13 17\n12 17\n11 17\n10 17\n9 17\n8 17\n7 17\n6 17\n5 17\n4 17\n3 17\n2 17"
},
{
"input": "1 77",
"output": "77\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77"
},
{
"input": "19 93",
"output": "111\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "25 5",
"output": "29\n1 1\n1 2\n1 3\n1 4\n1 5\n25 5\n24 5\n23 5\n22 5\n21 5\n20 5\n19 5\n18 5\n17 5\n16 5\n15 5\n14 5\n13 5\n12 5\n11 5\n10 5\n9 5\n8 5\n7 5\n6 5\n5 5\n4 5\n3 5\n2 5"
},
{
"input": "35 21",
"output": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n35 21\n34 21\n33 21\n32 21\n31 21\n30 21\n29 21\n28 21\n27 21\n26 21\n25 21\n24 21\n23 21\n22 21\n21 21\n20 21\n19 21\n18 21\n17 21\n16 21\n15 21\n14 21\n13 21\n12 21\n11 21\n10 21\n9 21\n8 21\n7 21\n6 21\n5 21\n4 21\n3 21\n2 21"
},
{
"input": "99 99",
"output": "197\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "99 100",
"output": "198\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
},
{
"input": "100 99",
"output": "198\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..."
}
] | 1,642,605,298 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 216 | 512,000 | m, n = map(int, input().split())
ls = []
for i in range(m):
ls1 = (str(i + 1), '1')
ls.append(ls1)
for j in range(1, n):
ls1 = ('1', str(j + 1))
ls.append(ls1)
print(len(ls))
for i in ls:
print(' '.join(i)) | Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); - or the girl in the dancing pair must dance for the first time.
Help Fox Ciel to make a schedule that they can dance as many songs as possible.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room.
Output Specification:
In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*.
Demo Input:
['2 1\n', '2 2\n']
Demo Output:
['2\n1 1\n2 1\n', '3\n1 1\n1 2\n2 2\n']
Note:
In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | ```python
m, n = map(int, input().split())
ls = []
for i in range(m):
ls1 = (str(i + 1), '1')
ls.append(ls1)
for j in range(1, n):
ls1 = ('1', str(j + 1))
ls.append(ls1)
print(len(ls))
for i in ls:
print(' '.join(i))
``` | 3 |
|
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 1,496,469,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 122 | 0 | if __name__ == '__main__':
n, m = map(int, input().split())
flag = True
refer = list()
for _ in range(n):
candi = set(list(str(input())))
if len(candi) > 1:
flag = False
break
else:
refer.append(candi.pop())
if len(set(refer)) < m:
flag = False
print('YES') if flag else print('NO')
| Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input Specification:
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output Specification:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Demo Input:
['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
if __name__ == '__main__':
n, m = map(int, input().split())
flag = True
refer = list()
for _ in range(n):
candi = set(list(str(input())))
if len(candi) > 1:
flag = False
break
else:
refer.append(candi.pop())
if len(set(refer)) < m:
flag = False
print('YES') if flag else print('NO')
``` | 0 |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894",
"output": "894"
},
{
"input": "6058 8581",
"output": "8581"
},
{
"input": "97259 41764",
"output": "125292"
},
{
"input": "453145 333625",
"output": "667250"
},
{
"input": "2233224 4394826",
"output": "4394826"
},
{
"input": "76770926 13350712",
"output": "80104272"
},
{
"input": "687355301 142098087",
"output": "710490435"
},
{
"input": "1000000000 999999999",
"output": "1999999998"
},
{
"input": "1000000000 1000000000",
"output": "2000000000"
},
{
"input": "999999999 1000000000",
"output": "1000000000"
},
{
"input": "1000000000 1",
"output": "1000000001"
},
{
"input": "1000000000 2",
"output": "1000000002"
},
{
"input": "999999999 1",
"output": "1000000000"
},
{
"input": "100000000 1",
"output": "100000001"
},
{
"input": "999999999 500000000",
"output": "1000000000"
},
{
"input": "999999990 10",
"output": "1000000000"
},
{
"input": "1000000000 999999997",
"output": "1999999994"
},
{
"input": "999999999 2",
"output": "1000000000"
},
{
"input": "999999984 1",
"output": "999999985"
},
{
"input": "999999983 1",
"output": "999999984"
},
{
"input": "666666666 1",
"output": "666666667"
},
{
"input": "1000000000 990000000",
"output": "1980000000"
},
{
"input": "41 48",
"output": "48"
},
{
"input": "123456 2",
"output": "123458"
},
{
"input": "111 111",
"output": "222"
},
{
"input": "878787 1",
"output": "878788"
},
{
"input": "121 1",
"output": "122"
},
{
"input": "114514 114514",
"output": "229028"
},
{
"input": "500000001 1000000000",
"output": "1000000000"
},
{
"input": "999999997 1",
"output": "999999998"
},
{
"input": "100000000 10",
"output": "100000010"
}
] | 1,590,089,042 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 155 | 0 | import sys,math
def isleap(y):
if y%400==0:
return True
elif y%4==0 and y%100!=0:
return True
else:
return False
n,k=map(int,sys.stdin.readline().split())
r=n%k
if r==0:
r+=k
else:
r=k-r
print(n+r) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Output Specification:
Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*.
Demo Input:
['5 3\n', '25 13\n', '26 13\n']
Demo Output:
['6\n', '26\n', '39\n']
Note:
none | ```python
import sys,math
def isleap(y):
if y%400==0:
return True
elif y%4==0 and y%100!=0:
return True
else:
return False
n,k=map(int,sys.stdin.readline().split())
r=n%k
if r==0:
r+=k
else:
r=k-r
print(n+r)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers). | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | 0 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": "6 queries, x=3"
},
{
"input": "30 5 16\n0 1 1 1 0",
"output": "6 queries, x=16"
},
{
"input": "60 6 21\n1 0 0 1 0 1",
"output": "11 queries, x=21"
},
{
"input": "100 7 73\n0 0 0 1 0 1 1",
"output": "14 queries, x=73"
},
{
"input": "1000000000 29 958572235\n1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0",
"output": "58 queries, x=958572235"
},
{
"input": "738009704 30 116044407\n0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1",
"output": "59 queries, x=116044407"
},
{
"input": "300 8 165\n1 1 1 0 0 1 1 0",
"output": "16 queries, x=165"
},
{
"input": "600 9 150\n0 0 1 0 1 0 1 0 1",
"output": "19 queries, x=150"
},
{
"input": "1000 10 140\n0 0 0 0 1 0 0 0 0 0",
"output": "20 queries, x=140"
},
{
"input": "3000 11 1896\n1 0 1 1 0 0 0 0 1 1 1",
"output": "21 queries, x=1896"
},
{
"input": "6000 12 4679\n1 0 1 1 1 1 1 0 0 0 0 1",
"output": "23 queries, x=4679"
},
{
"input": "10000 13 4977\n1 0 1 1 0 0 0 1 0 0 1 1 0",
"output": "26 queries, x=4977"
},
{
"input": "30000 14 60\n1 1 1 0 0 1 0 1 0 0 1 0 0 0",
"output": "28 queries, x=60"
},
{
"input": "60000 15 58813\n0 1 1 0 1 1 0 0 0 1 1 1 1 0 1",
"output": "27 queries, x=58813"
},
{
"input": "100000 16 79154\n1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 1",
"output": "32 queries, x=79154"
},
{
"input": "300000 17 11107\n1 0 0 0 1 0 0 0 1 1 1 0 0 1 1 1 0",
"output": "34 queries, x=11107"
},
{
"input": "600000 18 146716\n0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1",
"output": "37 queries, x=146716"
},
{
"input": "1000000 19 418016\n1 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0",
"output": "38 queries, x=418016"
},
{
"input": "3000000 20 642518\n1 0 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1",
"output": "41 queries, x=642518"
},
{
"input": "6000000 21 3516807\n0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0",
"output": "43 queries, x=3516807"
},
{
"input": "10000000 22 8115129\n1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1",
"output": "42 queries, x=8115129"
},
{
"input": "30000000 23 10362635\n0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0",
"output": "48 queries, x=10362635"
},
{
"input": "60000000 24 52208533\n1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 0",
"output": "46 queries, x=52208533"
},
{
"input": "100000000 25 51744320\n0 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1",
"output": "50 queries, x=51744320"
},
{
"input": "300000000 26 264009490\n1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1",
"output": "54 queries, x=264009490"
},
{
"input": "600000000 27 415720732\n1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 1 0",
"output": "56 queries, x=415720732"
},
{
"input": "1000000000 28 946835863\n0 0 1 0 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0",
"output": "58 queries, x=946835863"
},
{
"input": "1000000000 29 124919287\n0 0 1 0 0 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 0",
"output": "59 queries, x=124919287"
},
{
"input": "1000000000 30 202669473\n1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 0",
"output": "58 queries, x=202669473"
},
{
"input": "1000000000 13 532121080\n1 1 1 0 1 1 0 0 0 0 1 0 1",
"output": "42 queries, x=532121080"
},
{
"input": "1000000000 27 105669924\n0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 1 1 1",
"output": "57 queries, x=105669924"
},
{
"input": "1000000000 11 533994576\n0 0 1 0 1 1 1 1 0 1 0",
"output": "38 queries, x=533994576"
},
{
"input": "1000000000 9 107543421\n1 0 0 1 1 1 1 1 1",
"output": "39 queries, x=107543421"
},
{
"input": "1000000000 23 976059561\n1 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1",
"output": "53 queries, x=976059561"
},
{
"input": "1000000000 7 549608406\n1 1 1 0 1 1 1",
"output": "36 queries, x=549608406"
},
{
"input": "1000000000 21 123157250\n0 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1",
"output": "49 queries, x=123157250"
},
{
"input": "1000000000 19 696706094\n0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0",
"output": "47 queries, x=696706094"
},
{
"input": "1000000000 3 125030747\n0 0 0",
"output": "33 queries, x=125030747"
},
{
"input": "1000000000 17 993546887\n1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1",
"output": "46 queries, x=993546887"
},
{
"input": "1000000000 15 567095731\n1 1 1 0 0 1 1 1 0 1 0 0 1 0 0",
"output": "45 queries, x=567095731"
},
{
"input": "1000000000 29 140644576\n1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0",
"output": "58 queries, x=140644576"
},
{
"input": "1000000000 13 714193420\n0 1 0 0 0 1 0 0 0 0 1 1 1",
"output": "43 queries, x=714193420"
},
{
"input": "1000000000 27 142518072\n0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 0",
"output": "52 queries, x=142518072"
},
{
"input": "1000000000 25 11034213\n0 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0",
"output": "54 queries, x=11034213"
},
{
"input": "1000000000 9 584583057\n1 1 1 0 0 1 0 0 0",
"output": "35 queries, x=584583057"
},
{
"input": "1000000000 23 863164606\n1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 0 1 1",
"output": "53 queries, x=863164606"
},
{
"input": "1000000000 21 731680746\n1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1",
"output": "51 queries, x=731680746"
},
{
"input": "1000000000 5 305229590\n0 0 1 1 0",
"output": "35 queries, x=305229590"
},
{
"input": "1000000000 3 28521539\n0 0 1",
"output": "31 queries, x=28521539"
},
{
"input": "1000000000 3 602070383\n0 1 1",
"output": "32 queries, x=602070383"
},
{
"input": "1000000000 2 880651931\n1 1",
"output": "30 queries, x=880651931"
},
{
"input": "1000000000 16 749168072\n1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0",
"output": "46 queries, x=749168072"
},
{
"input": "1000000000 30 322716916\n1 0 1 1 1 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0",
"output": "58 queries, x=322716916"
},
{
"input": "1000000000 14 191233057\n0 0 1 0 0 1 1 1 1 0 0 0 1 1",
"output": "43 queries, x=191233057"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1 30 1\n1 1 1 0 1 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "2 1 2\n1",
"output": "2 queries, x=2"
},
{
"input": "1000000000 1 1000000000\n1",
"output": "31 queries, x=1000000000"
},
{
"input": "10000 1 10000\n1",
"output": "15 queries, x=10000"
},
{
"input": "1000000000 1 999999999\n1",
"output": "30 queries, x=999999999"
},
{
"input": "100000 2 15\n1 0",
"output": "19 queries, x=15"
},
{
"input": "200000 1 110000\n1",
"output": "17 queries, x=110000"
},
{
"input": "123456789 1 42\n1",
"output": "27 queries, x=42"
},
{
"input": "1000000000 1 9\n1",
"output": "30 queries, x=9"
},
{
"input": "200000 2 100002\n1 0",
"output": "19 queries, x=100002"
},
{
"input": "1000000000 3 234567890\n0 1 0",
"output": "31 queries, x=234567890"
},
{
"input": "1000000000 5 321732193\n1 1 0 1 0",
"output": "35 queries, x=321732193"
},
{
"input": "1000000000 1 804289384\n1",
"output": "27 queries, x=804289384"
},
{
"input": "1000000000 2 999999998\n1 0",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 5 384618761\n0 1 1 0 1",
"output": "33 queries, x=384618761"
},
{
"input": "100000000 1 100\n0",
"output": "28 queries, x=100"
},
{
"input": "1000000000 1 804289384\n0",
"output": "27 queries, x=804289384"
},
{
"input": "100000000 1 100000000\n1",
"output": "28 queries, x=100000000"
},
{
"input": "40 1 4\n0",
"output": "6 queries, x=4"
},
{
"input": "1000000000 2 999999998\n0 1",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 1 1000000000\n0",
"output": "31 queries, x=1000000000"
},
{
"input": "1000000000 2 255555555\n1 0",
"output": "31 queries, x=255555555"
},
{
"input": "1000000000 2 1000000000\n0 1",
"output": "32 queries, x=1000000000"
},
{
"input": "1000000000 1 999999999\n0",
"output": "30 queries, x=999999999"
},
{
"input": "1000000000 2 888888888\n0 1",
"output": "31 queries, x=888888888"
},
{
"input": "1000000000 1 77000000\n1",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 123456789\n1",
"output": "27 queries, x=123456789"
},
{
"input": "10000 1 228\n0",
"output": "14 queries, x=228"
},
{
"input": "1000000000 1 12345\n1",
"output": "31 queries, x=12345"
},
{
"input": "1000000000 1 77000000\n0",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 23333\n0",
"output": "31 queries, x=23333"
},
{
"input": "1000000000 4 100\n0 1 0 1",
"output": "34 queries, x=100"
},
{
"input": "100000000 1 200\n1",
"output": "27 queries, x=200"
},
{
"input": "1000000000 3 5\n0 1 0",
"output": "33 queries, x=5"
},
{
"input": "1000000000 12 2\n1 1 1 1 1 1 0 0 1 1 1 1",
"output": "41 queries, x=2"
},
{
"input": "1000000000 1 5\n0",
"output": "31 queries, x=5"
},
{
"input": "100000 2 99999\n0 0",
"output": "18 queries, x=99999"
},
{
"input": "100000 2 2\n0 1",
"output": "18 queries, x=2"
},
{
"input": "1000000 1 91923\n0",
"output": "21 queries, x=91923"
},
{
"input": "1000000 2 1235\n0 1",
"output": "22 queries, x=1235"
},
{
"input": "1000000000 1 5\n1",
"output": "31 queries, x=5"
},
{
"input": "100000000 2 1234567\n0 1",
"output": "28 queries, x=1234567"
},
{
"input": "1000000000 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 4 999999999\n1 0 0 1",
"output": "33 queries, x=999999999"
},
{
"input": "1000000000 4 1000000000\n1 0 1 0",
"output": "34 queries, x=1000000000"
},
{
"input": "1000000000 4 1\n1 0 1 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 5 500\n1 1 0 0 1",
"output": "34 queries, x=500"
},
{
"input": "1000 1 13\n1",
"output": "11 queries, x=13"
},
{
"input": "999999999 2 123456789\n1 0",
"output": "31 queries, x=123456789"
},
{
"input": "1000000000 5 1000000000\n1 1 1 1 1",
"output": "35 queries, x=1000000000"
},
{
"input": "1000000000 3 123456789\n1 0 1",
"output": "29 queries, x=123456789"
},
{
"input": "1000000000 1 123\n1",
"output": "29 queries, x=123"
},
{
"input": "10 1 9\n1",
"output": "4 queries, x=9"
},
{
"input": "1000000000 1 1\n0",
"output": "1 queries, x=1"
},
{
"input": "100000000 2 12345678\n0 1",
"output": "28 queries, x=12345678"
},
{
"input": "1000000000 30 1000000000\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",
"output": "60 queries, x=1000000000"
},
{
"input": "805306369 30 805306369\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",
"output": "60 queries, x=805306369"
},
{
"input": "1000000000 2 123\n0 1",
"output": "30 queries, x=123"
},
{
"input": "1000000000 1 9\n0",
"output": "30 queries, x=9"
},
{
"input": "100000 2 90000\n1 0",
"output": "18 queries, x=90000"
},
{
"input": "1000000000 2 123456789\n1 0",
"output": "28 queries, x=123456789"
},
{
"input": "1000000000 2 804289384\n1 0",
"output": "28 queries, x=804289384"
},
{
"input": "1000000000 30 999999970\n1 0 0 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1",
"output": "60 queries, x=999999970"
}
] | 1,599,511,052 | 2,147,483,647 | PyPy 3 | OK | TESTS | 135 | 171 | 102,400 | from __future__ import print_function
from sys import stdin, stdout
rints = lambda: [int(x) for x in stdin.readline().split()]
m, n = rints()
ans = []
for i in range(1, min(n, m) + 1):
print(i, flush=True)
ans.append(int(input()))
if ans[-1] == 0:
exit()
be, en, ix = 1, m, 0
while be <= en:
mid = (be + en) >> 1
print(mid, flush=True)
val = int(input())
if val == 0:
exit()
else:
if ans[ix] == -1:
val = -val
if val == -1:
en = mid - 1
else:
be = mid + 1
ix = (ix + 1) % n
print(ans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).
Input Specification:
The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.
Output Specification:
none
Demo Input:
['5 2\n1\n-1\n-1\n1\n0\n']
Demo Output:
['1\n2\n4\n5\n3\n']
Note:
In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | ```python
from __future__ import print_function
from sys import stdin, stdout
rints = lambda: [int(x) for x in stdin.readline().split()]
m, n = rints()
ans = []
for i in range(1, min(n, m) + 1):
print(i, flush=True)
ans.append(int(input()))
if ans[-1] == 0:
exit()
be, en, ix = 1, m, 0
while be <= en:
mid = (be + en) >> 1
print(mid, flush=True)
val = int(input())
if val == 0:
exit()
else:
if ans[ix] == -1:
val = -val
if val == -1:
en = mid - 1
else:
be = mid + 1
ix = (ix + 1) % n
print(ans)
``` | 3 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,665,463,997 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 374 | 9,011,200 | # direct access array
n = int(input())
A = tuple(map(int,input().split()))
m = int(input())
B = tuple(map(int,input().split()))
D_array = [None] * 100001
for i in range(0, n):
D_array[A[i]] = i + 1
V, P = 0, 0
for i in B:
V += D_array[i]
P += n + 1 - D_array[i]
print(V, P) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
# direct access array
n = int(input())
A = tuple(map(int,input().split()))
m = int(input())
B = tuple(map(int,input().split()))
D_array = [None] * 100001
for i in range(0, n):
D_array[A[i]] = i + 1
V, P = 0, 0
for i in B:
V += D_array[i]
P += n + 1 - D_array[i]
print(V, P)
``` | 3 |
|
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely. | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once. | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n1000000000",
"output": "1000000000"
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "2 0\n1000000000 0",
"output": "1000000000"
},
{
"input": "2 0\n0 1000000000",
"output": "1000000000"
},
{
"input": "2 0\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 1\n0 0\n1 2",
"output": "0"
}
] | 1,672,230,798 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 10,956,800 |
from queue import Queue
n,m=map(int, input().split())
l=list(map(int,input().split()))
friends={}
for i in range(m):
a=list(map(int,input().split()))
friends[a[0]]=a[1]
# print(n,m)
# print(l)
# print(friends)
visited=set()
exp=Queue()
cost=0
for i in range(1,n+1):
# print(i)
if i in friends and i not in visited:
cost+=l[i-1]
# print(i,cost)
exp.put(i)
visited.add(i)
# print(exp.qsize())
while not exp.empty():
c=exp.get()
if friends.get(c,-1)!=-1:
exp.put(friends[c])
visited.add(friends[c])
elif i not in visited:
cost+=l[i-1]
print(cost)
| Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Output Specification:
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
Demo Input:
['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n']
Demo Output:
['10\n', '55\n', '15\n']
Note:
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | ```python
from queue import Queue
n,m=map(int, input().split())
l=list(map(int,input().split()))
friends={}
for i in range(m):
a=list(map(int,input().split()))
friends[a[0]]=a[1]
# print(n,m)
# print(l)
# print(friends)
visited=set()
exp=Queue()
cost=0
for i in range(1,n+1):
# print(i)
if i in friends and i not in visited:
cost+=l[i-1]
# print(i,cost)
exp.put(i)
visited.add(i)
# print(exp.qsize())
while not exp.empty():
c=exp.get()
if friends.get(c,-1)!=-1:
exp.put(friends[c])
visited.add(friends[c])
elif i not in visited:
cost+=l[i-1]
print(cost)
``` | 0 |
|
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*. | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*. | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1 5 6 2 9 4 3",
"output": "-1"
},
{
"input": "10 3 6\n5 6 7 3 8 4 2 1 10 9",
"output": "3"
},
{
"input": "10 10 4\n4 2 6 9 5 3 8 1 10 7",
"output": "4"
},
{
"input": "100 90 57\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "-1"
},
{
"input": "100 11 20\n80 25 49 55 22 98 35 59 88 14 91 20 68 66 53 50 77 45 82 63 96 93 85 46 37 74 84 9 7 95 41 86 23 36 33 27 81 39 18 13 12 92 24 71 3 48 83 61 31 87 28 79 75 38 11 21 29 69 44 100 72 62 32 43 30 16 47 56 89 60 42 17 26 70 94 99 4 6 2 73 8 52 65 1 15 90 67 51 78 10 5 76 57 54 34 58 19 64 40 97",
"output": "26"
},
{
"input": "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23 66 76 59 79 40 86 63 44 82 32 48 16 50 100 28 96 46 12 27 13 24 9 19 84 73 69 71 42 56 33 34 95",
"output": "71"
},
{
"input": "100 6 93\n74 62 67 81 40 85 35 42 59 72 80 28 79 41 16 19 33 63 13 10 69 76 70 93 49 84 89 94 8 37 11 90 26 52 47 7 36 95 86 75 56 15 61 99 88 12 83 21 20 3 100 17 32 82 6 5 43 25 66 68 73 78 18 77 92 27 23 2 4 39 60 48 22 24 14 97 29 34 54 64 71 57 87 38 9 50 30 53 51 45 44 31 58 91 98 65 55 1 46 96",
"output": "-1"
},
{
"input": "100 27 56\n58 18 50 41 33 37 14 87 77 73 61 53 15 8 70 68 45 96 54 78 39 67 51 60 80 12 93 99 20 92 17 79 4 13 62 91 69 29 49 36 98 34 90 35 84 64 38 83 28 89 97 94 9 16 26 48 10 57 23 75 27 88 44 21 72 76 30 43 32 2 71 24 100 1 31 81 42 40 47 55 86 85 66 5 52 22 95 74 11 19 7 82 6 25 56 63 65 59 46 3",
"output": "20"
},
{
"input": "87 42 49\n45 55 24 44 56 72 74 23 4 7 37 67 22 6 58 76 40 36 3 20 26 87 64 75 49 70 62 42 31 1 80 33 25 59 78 27 32 2 41 61 66 28 19 85 15 69 52 77 50 14 16 34 18 43 73 83 11 39 29 9 35 13 81 54 79 21 60 46 71 57 12 17 5 47 38 30 10 84 53 63 68 8 51 65 48 86 82",
"output": "-1"
},
{
"input": "2 1 2\n1 2",
"output": "-1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
},
{
"input": "2 2 2\n1 2",
"output": "0"
},
{
"input": "2 2 2\n2 1",
"output": "0"
},
{
"input": "2 1 1\n2 1",
"output": "0"
}
] | 1,596,633,154 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 434 | 14,028,800 | enter = input().split()
n = int(enter[0]) - 1
s = int(enter[1]) - 1
t = int(enter[2]) - 1
fix = s
arr_b = [int(i) - 1 for i in input().split()]
arr_a = [i for i in range(1,n+2)]
target = arr_a[s]
flag = 0
#print(arr_a)
#print(arr_b)
i = 0
while (arr_a[t] != target):
correct_pos = arr_b[s]
arr_a[correct_pos],arr_a[s] = arr_a[s],arr_a[correct_pos]
s = correct_pos
i = i + 1
if (target == arr_a[fix]):
flag = 1
break
#print(arr_a)
if (flag==0):
print(i)
else:
print(-1) | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*.
Input Specification:
The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*.
Output Specification:
If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.
Demo Input:
['4 2 1\n2 3 4 1\n', '4 3 3\n4 1 3 2\n', '4 3 4\n1 2 3 4\n', '3 1 3\n2 1 3\n']
Demo Output:
['3\n', '0\n', '-1\n', '-1\n']
Note:
none | ```python
enter = input().split()
n = int(enter[0]) - 1
s = int(enter[1]) - 1
t = int(enter[2]) - 1
fix = s
arr_b = [int(i) - 1 for i in input().split()]
arr_a = [i for i in range(1,n+2)]
target = arr_a[s]
flag = 0
#print(arr_a)
#print(arr_b)
i = 0
while (arr_a[t] != target):
correct_pos = arr_b[s]
arr_a[correct_pos],arr_a[s] = arr_a[s],arr_a[correct_pos]
s = correct_pos
i = i + 1
if (target == arr_a[fix]):
flag = 1
break
#print(arr_a)
if (flag==0):
print(i)
else:
print(-1)
``` | 3 |
|
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer *n*. Help Anton to determine the exchange rate of currency you all know for tomorrow! | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
{
"input": "11",
"output": "-1"
},
{
"input": "1435678543",
"output": "1435678534"
},
{
"input": "4250769",
"output": "9250764"
},
{
"input": "4052769",
"output": "9052764"
},
{
"input": "5685341",
"output": "5685314"
},
{
"input": "1111111111111111231",
"output": "1111111111111111132"
},
{
"input": "333333332379",
"output": "333333339372"
},
{
"input": "85",
"output": "58"
},
{
"input": "7700016673",
"output": "7730016670"
},
{
"input": "35451519805848712272404365322858764249299938505103",
"output": "35451519835848712272404365322858764249299938505100"
},
{
"input": "4314752277691991627730686134692292422155753465948025897701703862445837045929984759093775762579123919",
"output": "9314752277691991627730686134692292422155753465948025897701703862445837045929984759093775762579123914"
},
{
"input": "21",
"output": "12"
},
{
"input": "101",
"output": "110"
},
{
"input": "503147",
"output": "573140"
},
{
"input": "333333333333333333333",
"output": "-1"
},
{
"input": "55555555555555555555555",
"output": "-1"
},
{
"input": "99",
"output": "-1"
},
{
"input": "23759",
"output": "93752"
},
{
"input": "235749",
"output": "935742"
},
{
"input": "435729",
"output": "935724"
},
{
"input": "8623",
"output": "8632"
},
{
"input": "109",
"output": "190"
},
{
"input": "20000000000000000000001",
"output": "21000000000000000000000"
},
{
"input": "1001",
"output": "1100"
}
] | 1,664,047,796 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 78 | 0 | t = int(input())
lst=[]
d = 0
while(t!=0):
d = t%10
t = t//10
lst.append(d)
lst.reverse()
for i in range(0,len(lst)):
if (lst[i]%2==0):
if (lst[i]<lst[len(lst)-1]):
t = lst[i]
lst[i] = lst[len(lst)-1]
lst[len(lst)-1] = t
if (lst[len(lst)-1]%2==0):
t=0
for i in lst:
t=t*10+i
print(t)
quit()
for i in range(len(lst)-2,-1,-1):
if (lst[i]%2==0):
if (lst[i]>lst[len(lst)-1]):
t = lst[i]
lst[i] = lst[len(lst)-1]
lst[len(lst)-1] = t
if (lst[len(lst)-1]%2==0):
t=0
for i in lst:
t=t*10+i
print(t)
quit()
else:
print(-1)
| Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer *n*. Help Anton to determine the exchange rate of currency you all know for tomorrow!
Input Specification:
The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes.
Output Specification:
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
Demo Input:
['527\n', '4573\n', '1357997531\n']
Demo Output:
['572\n', '3574\n', '-1\n']
Note:
none | ```python
t = int(input())
lst=[]
d = 0
while(t!=0):
d = t%10
t = t//10
lst.append(d)
lst.reverse()
for i in range(0,len(lst)):
if (lst[i]%2==0):
if (lst[i]<lst[len(lst)-1]):
t = lst[i]
lst[i] = lst[len(lst)-1]
lst[len(lst)-1] = t
if (lst[len(lst)-1]%2==0):
t=0
for i in lst:
t=t*10+i
print(t)
quit()
for i in range(len(lst)-2,-1,-1):
if (lst[i]%2==0):
if (lst[i]>lst[len(lst)-1]):
t = lst[i]
lst[i] = lst[len(lst)-1]
lst[len(lst)-1] = t
if (lst[len(lst)-1]%2==0):
t=0
for i in lst:
t=t*10+i
print(t)
quit()
else:
print(-1)
``` | 0 |
|
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,602,772,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 140 | 819,200 | import math
import os
import random
import re
import sys
def solve(n, matrix):
aisle = '|'
buddy_seats = 'OO'
result = 'NO'
for row_index, row in enumerate(matrix):
for col_index, col in enumerate(row):
pair = col.split(aisle)
for seat_index, seat in enumerate(pair):
if seat == buddy_seats:
matrix[row_index][col_index] = matrix[row_index][col_index].replace(
"OO", "++"
)
result = 'YES'
return result
return result
def print_seating_chart(matrix):
"""matrix is always 5 columns by `n` rows"""
for row in matrix:
for col in row:
print(col)
if __name__ == '__main__':
n = int(input())
matrix = []
for index in range(n):
matrix.append(list(map(str, input().split())))
result = solve(n, matrix)
print(result)
if result == 'YES':
print_seating_chart(matrix)
| Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | ```python
import math
import os
import random
import re
import sys
def solve(n, matrix):
aisle = '|'
buddy_seats = 'OO'
result = 'NO'
for row_index, row in enumerate(matrix):
for col_index, col in enumerate(row):
pair = col.split(aisle)
for seat_index, seat in enumerate(pair):
if seat == buddy_seats:
matrix[row_index][col_index] = matrix[row_index][col_index].replace(
"OO", "++"
)
result = 'YES'
return result
return result
def print_seating_chart(matrix):
"""matrix is always 5 columns by `n` rows"""
for row in matrix:
for col in row:
print(col)
if __name__ == '__main__':
n = int(input())
matrix = []
for index in range(n):
matrix.append(list(map(str, input().split())))
result = solve(n, matrix)
print(result)
if result == 'YES':
print_seating_chart(matrix)
``` | 0 |
|
876 | B | Divisiblity of Differences | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. | First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset. | If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them. | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | 1,000 | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 "
},
{
"input": "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455",
"output": "Yes\n216175135 15241965 987180005 533996295 875331635 46172555 604086315 350146655 "
},
{
"input": "2 2 100000\n0 1",
"output": "No"
},
{
"input": "101 25 64\n451 230 14 53 7 520 709 102 678 358 166 870 807 230 230 279 166 230 765 176 742 358 924 976 647 806 870 473 976 994 750 146 802 224 503 801 105 614 882 203 390 338 29 587 214 213 405 806 102 102 621 358 521 742 678 205 309 871 796 326 162 693 268 486 68 627 304 829 806 623 748 934 714 672 712 614 587 589 846 260 593 85 839 257 711 395 336 358 472 133 324 527 599 5 845 920 989 494 358 70 882",
"output": "Yes\n230 102 678 358 166 870 230 230 166 230 742 358 806 870 614 806 102 102 358 742 678 486 806 934 614 "
},
{
"input": "108 29 72\n738 619 711 235 288 288 679 36 785 233 706 71 216 144 216 781 338 583 495 648 144 432 72 720 541 288 158 328 154 202 10 533 635 176 707 216 314 397 440 142 326 458 568 701 745 144 61 634 520 720 744 144 409 127 526 476 101 469 72 432 738 432 235 641 695 276 144 144 231 555 630 9 109 319 437 288 288 317 453 432 601 0 449 576 743 352 333 504 504 369 228 288 381 142 500 72 297 359 230 773 216 576 144 244 437 772 483 51",
"output": "Yes\n288 288 216 144 216 648 144 432 72 720 288 216 144 720 144 72 432 432 144 144 288 288 432 0 576 504 504 288 72 "
},
{
"input": "8 2 6\n750462183 165947982 770714338 368445737 363145692 966611485 376672869 678687947",
"output": "Yes\n165947982 363145692 "
},
{
"input": "12 2 1\n512497388 499105388 575265677 864726520 678272195 667107176 809432109 439696443 770034376 873126825 690514828 541499950",
"output": "Yes\n512497388 499105388 "
},
{
"input": "9 3 1\n506004039 471451660 614118177 518013571 43210072 454727076 285905913 543002174 298515615",
"output": "Yes\n506004039 471451660 614118177 "
},
{
"input": "8 4 6\n344417267 377591123 938158786 682031413 804153975 89006697 275945670 735510539",
"output": "No"
},
{
"input": "8 8 1\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253",
"output": "Yes\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253 "
},
{
"input": "7 7 1\n0 0 0 0 0 0 0",
"output": "Yes\n0 0 0 0 0 0 0 "
},
{
"input": "11 4 3\n0 1 0 1 1 0 0 0 0 0 0",
"output": "Yes\n0 0 0 0 "
},
{
"input": "13 4 4\n1 1 0 3 2 4 1 0 3 4 2 4 3",
"output": "Yes\n0 4 0 4 "
},
{
"input": "5 5 1\n6 4 6 0 4",
"output": "Yes\n6 4 6 0 4 "
},
{
"input": "3 2 3\n1 2 3",
"output": "No"
},
{
"input": "6 3 4\n5 9 10 6 7 8",
"output": "No"
},
{
"input": "4 4 3\n4 7 2 5",
"output": "No"
},
{
"input": "4 2 6\n5 5 5 5",
"output": "Yes\n5 5 "
},
{
"input": "4 3 3\n5 1 4 7",
"output": "Yes\n1 4 7 "
},
{
"input": "4 3 10\n0 1 11 11",
"output": "Yes\n1 11 11 "
},
{
"input": "5 2 4\n1 2 2 2 2",
"output": "Yes\n2 2 "
},
{
"input": "5 5 9\n8 17 26 35 44",
"output": "Yes\n8 17 26 35 44 "
},
{
"input": "3 2 2\n1 2 4",
"output": "Yes\n2 4 "
},
{
"input": "5 4 2\n1 3 6 10 12",
"output": "No"
},
{
"input": "3 2 4\n1 2 3",
"output": "No"
},
{
"input": "8 3 5\n1 2 3 4 1 2 3 4",
"output": "No"
},
{
"input": "5 2 9\n8 8 8 8 8",
"output": "Yes\n8 8 "
},
{
"input": "3 3 3\n1 3 6",
"output": "No"
},
{
"input": "5 2 10\n4 5 6 19 29",
"output": "Yes\n19 29 "
},
{
"input": "5 3 3\n3 6 4 7 10",
"output": "Yes\n4 7 10 "
}
] | 1,551,905,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | inp = list(map(int,input().split(' ')))
n, k, m = inp[0], inp[1], inp[2]
nums = [[] for i in range(m)]
for input in list(map(int,input().split(' '))):
nums[input%m].append(input)
for j in nums:
if len(j) >= k:
print('Yes')
print(" ".join(list(map(str,j[:k]))))
| Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input Specification:
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset.
Output Specification:
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them.
Demo Input:
['3 2 3\n1 8 4\n', '3 3 3\n1 8 4\n', '4 3 5\n2 7 7 7\n']
Demo Output:
['Yes\n1 4 ', 'No', 'Yes\n2 7 7 ']
Note:
none | ```python
inp = list(map(int,input().split(' ')))
n, k, m = inp[0], inp[1], inp[2]
nums = [[] for i in range(m)]
for input in list(map(int,input().split(' '))):
nums[input%m].append(input)
for j in nums:
if len(j) >= k:
print('Yes')
print(" ".join(list(map(str,j[:k]))))
``` | 0 |
|
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"output": "-1"
},
{
"input": "1000000000000000 1000000000",
"output": "-1"
},
{
"input": "1000000000000000 100",
"output": "1953125"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "9 3",
"output": "9"
},
{
"input": "21 3",
"output": "7"
},
{
"input": "67280421310721 1",
"output": "1"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "16 3",
"output": "4"
},
{
"input": "1 1000",
"output": "-1"
},
{
"input": "16 4",
"output": "8"
},
{
"input": "36 8",
"output": "18"
},
{
"input": "49 4",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "16 1",
"output": "1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "16 5",
"output": "16"
},
{
"input": "25 4",
"output": "-1"
},
{
"input": "4010815561 2",
"output": "63331"
},
{
"input": "49 3",
"output": "49"
},
{
"input": "36 6",
"output": "9"
},
{
"input": "36 10",
"output": "-1"
},
{
"input": "25 3",
"output": "25"
},
{
"input": "22876792454961 28",
"output": "7625597484987"
},
{
"input": "1234 2",
"output": "2"
},
{
"input": "179458711 2",
"output": "179458711"
},
{
"input": "900104343024121 100000",
"output": "-1"
},
{
"input": "8 3",
"output": "4"
},
{
"input": "100 6",
"output": "20"
},
{
"input": "15500 26",
"output": "-1"
},
{
"input": "111111 1",
"output": "1"
},
{
"input": "100000000000000 200",
"output": "160000000000"
},
{
"input": "1000000000000 100",
"output": "6400000"
},
{
"input": "100 10",
"output": "-1"
},
{
"input": "1000000000039 2",
"output": "1000000000039"
},
{
"input": "64 5",
"output": "16"
},
{
"input": "999999961946176 33",
"output": "63245552"
},
{
"input": "376219076689 3",
"output": "376219076689"
},
{
"input": "999999961946176 63",
"output": "999999961946176"
},
{
"input": "1048576 12",
"output": "2048"
},
{
"input": "745 21",
"output": "-1"
},
{
"input": "748 6",
"output": "22"
},
{
"input": "999999961946176 50",
"output": "161082468097"
},
{
"input": "10 3",
"output": "5"
},
{
"input": "1099511627776 22",
"output": "2097152"
},
{
"input": "1000000007 100010",
"output": "-1"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "100 8",
"output": "50"
},
{
"input": "100 7",
"output": "25"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "999999961946176 64",
"output": "-1"
},
{
"input": "20 5",
"output": "10"
},
{
"input": "999999999999989 2",
"output": "999999999999989"
},
{
"input": "100000000000000 114",
"output": "10240000"
},
{
"input": "99999640000243 3",
"output": "9999991"
},
{
"input": "999998000001 566",
"output": "333332666667"
},
{
"input": "99999820000081 2",
"output": "9999991"
},
{
"input": "49000042000009 3",
"output": "49000042000009"
},
{
"input": "151491429961 4",
"output": "-1"
},
{
"input": "32416190071 2",
"output": "32416190071"
},
{
"input": "1000 8",
"output": "25"
},
{
"input": "1999967841 15",
"output": "1999967841"
},
{
"input": "26880 26880",
"output": "-1"
},
{
"input": "151491429961 3",
"output": "151491429961"
},
{
"input": "90000000000 300",
"output": "100000000"
},
{
"input": "98765004361 10",
"output": "-1"
},
{
"input": "15 2",
"output": "3"
},
{
"input": "16 2",
"output": "2"
},
{
"input": "1996 2",
"output": "2"
},
{
"input": "1997 2",
"output": "1997"
},
{
"input": "1999 2",
"output": "1999"
},
{
"input": "1998 2",
"output": "2"
},
{
"input": "1998 1",
"output": "1"
},
{
"input": "1998 7",
"output": "27"
},
{
"input": "1998 8",
"output": "37"
},
{
"input": "100000380000361 2",
"output": "10000019"
},
{
"input": "15 1",
"output": "1"
},
{
"input": "100000000000000 226",
"output": "-1"
},
{
"input": "844030857550613 517",
"output": "-1"
},
{
"input": "4567890 14",
"output": "430"
},
{
"input": "123123123 123123123",
"output": "-1"
},
{
"input": "24 4",
"output": "4"
},
{
"input": "999999993568952 17",
"output": "31622777"
},
{
"input": "99999999994190 9",
"output": "241656799"
},
{
"input": "999997874844049 4",
"output": "-1"
},
{
"input": "99999999999931 2",
"output": "99999999999931"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "67280421310721 2",
"output": "67280421310721"
}
] | 1,560,752,929 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 34 | 2,000 | 2,252,800 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def divisions(n):
sq = int(math.sqrt(n)+1)
d = collections.defaultdict(int)
while n % 2 == 0:
n //= 2
d[2] += 1
i = 3
while n > 1 and sq >= i:
if n % i == 0:
n //= i
d[i] += 1
else:
i += 2
if n > 1:
d[n] += 1
r = [1]
for k, v in d.items():
for c in r[:]:
for i in range(1,v+1):
r.append(c*(k**i))
return sorted(r)
def main():
n,k = LI()
d = sorted(divisions(n))
if len(d) < k:
return -1
return d[k-1]
print(main())
| Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
Output Specification:
If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*.
Demo Input:
['4 2\n', '5 3\n', '12 5\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def divisions(n):
sq = int(math.sqrt(n)+1)
d = collections.defaultdict(int)
while n % 2 == 0:
n //= 2
d[2] += 1
i = 3
while n > 1 and sq >= i:
if n % i == 0:
n //= i
d[i] += 1
else:
i += 2
if n > 1:
d[n] += 1
r = [1]
for k, v in d.items():
for c in r[:]:
for i in range(1,v+1):
r.append(c*(k**i))
return sorted(r)
def main():
n,k = LI()
d = sorted(divisions(n))
if len(d) < k:
return -1
return d[k-1]
print(main())
``` | 0 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\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\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,688,647,650 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | h=[]
g=[]
n=int(input())
for i in range(n):
hi,gi=map(int,input().split())
h.append(hi)
g.append(gi)
d=dict.fromkeys(g,0)
for i in range(n):
for j in range(n):
if g[i]==h[j]:
d[g[i]]+=1
l=list(d.values())
print(sum(l)) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
h=[]
g=[]
n=int(input())
for i in range(n):
hi,gi=map(int,input().split())
h.append(hi)
g.append(gi)
d=dict.fromkeys(g,0)
for i in range(n):
for j in range(n):
if g[i]==h[j]:
d[g[i]]+=1
l=list(d.values())
print(sum(l))
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values *n*, *d* and *h*:
- The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex.
The distance between two vertices of the tree is the number of edges on the simple path between them.
Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1". | The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively. | If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).
Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order. | [
"5 3 2\n",
"8 5 2\n",
"8 4 2\n"
] | [
"1 2\n1 3\n3 4\n3 5",
"-1\n",
"4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n"
] | Below you can see trees printed to the output in the first sample and the third sample. | 0 | [
{
"input": "5 3 2",
"output": "1 2\n2 3\n1 4\n5 1"
},
{
"input": "8 5 2",
"output": "-1"
},
{
"input": "8 4 2",
"output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5"
},
{
"input": "2 1 1",
"output": "1 2"
},
{
"input": "10 3 3",
"output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2"
},
{
"input": "15 6 4",
"output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1"
},
{
"input": "16 15 14",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n1 16"
},
{
"input": "1000 51 25",
"output": "-1"
},
{
"input": "100000 10 7",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n1 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..."
},
{
"input": "3 1 1",
"output": "-1"
},
{
"input": "3 2 1",
"output": "1 2\n1 3"
},
{
"input": "3 2 2",
"output": "1 2\n2 3"
},
{
"input": "4 1 1",
"output": "-1"
},
{
"input": "4 2 1",
"output": "1 2\n1 3\n4 1"
},
{
"input": "4 2 2",
"output": "1 2\n2 3\n4 2"
},
{
"input": "4 3 1",
"output": "-1"
},
{
"input": "4 3 2",
"output": "1 2\n2 3\n1 4"
},
{
"input": "4 3 3",
"output": "1 2\n2 3\n3 4"
},
{
"input": "8 5 3",
"output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1"
},
{
"input": "20 19 19",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20"
},
{
"input": "30 14 14",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2"
},
{
"input": "33 5 3",
"output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1"
},
{
"input": "5432 200 100",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "5433 200 99",
"output": "-1"
},
{
"input": "99999 1 1",
"output": "-1"
},
{
"input": "99999 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "99999 7 4",
"output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n7 8\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "9999 7 3",
"output": "-1"
},
{
"input": "100000 1 1",
"output": "-1"
},
{
"input": "100000 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "100000 2 2",
"output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88 ..."
},
{
"input": "100000 3 1",
"output": "-1"
},
{
"input": "100000 10 5",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n1 7\n7 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..."
},
{
"input": "100000 10 6",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..."
},
{
"input": "100000 10 9",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n1 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "100000 10 10",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88..."
},
{
"input": "100000 99900 78900",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 1",
"output": "-1"
},
{
"input": "100000 99998 49999",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 50000",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 69001",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 99055",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 99998",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 1",
"output": "-1"
},
{
"input": "100000 99999 49999",
"output": "-1"
},
{
"input": "100000 99999 50000",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 50001",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 77777",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 99998",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 99999",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "3 1 1",
"output": "-1"
},
{
"input": "5 1 1",
"output": "-1"
},
{
"input": "10 1 1",
"output": "-1"
},
{
"input": "3 2 1",
"output": "1 2\n1 3"
},
{
"input": "8 1 1",
"output": "-1"
},
{
"input": "4 1 1",
"output": "-1"
},
{
"input": "6 1 1",
"output": "-1"
},
{
"input": "20 1 1",
"output": "-1"
},
{
"input": "5 2 1",
"output": "1 2\n1 3\n4 1\n5 1"
},
{
"input": "100 1 1",
"output": "-1"
},
{
"input": "10 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1"
},
{
"input": "100 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "47 1 1",
"output": "-1"
},
{
"input": "7 1 1",
"output": "-1"
},
{
"input": "4 2 1",
"output": "1 2\n1 3\n4 1"
},
{
"input": "5 2 2",
"output": "1 2\n2 3\n4 2\n5 2"
},
{
"input": "8 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1"
},
{
"input": "1000 1 1",
"output": "-1"
},
{
"input": "11 1 1",
"output": "-1"
},
{
"input": "15 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1"
},
{
"input": "3 2 2",
"output": "1 2\n2 3"
},
{
"input": "8 2 2",
"output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2"
}
] | 1,459,184,282 | 1,382 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 61 | 4,608,000 | n,d,h = map(int, input().split())
if d > 2*h or h > d:
print(-1)
else:
for i in range(h):
print(str(i+1)+" "+str(i+2))
if d > h:
print("1 "+str(h+2))
for i in range(d-h-1):
print(str(h+2+i)+" "+str(h+3+i))
for i in range(d+2,n+1):
print("1 "+str(i)) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values *n*, *d* and *h*:
- The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex.
The distance between two vertices of the tree is the number of edges on the simple path between them.
Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".
Input Specification:
The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.
Output Specification:
If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).
Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.
Demo Input:
['5 3 2\n', '8 5 2\n', '8 4 2\n']
Demo Output:
['1 2\n1 3\n3 4\n3 5', '-1\n', '4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n']
Note:
Below you can see trees printed to the output in the first sample and the third sample. | ```python
n,d,h = map(int, input().split())
if d > 2*h or h > d:
print(-1)
else:
for i in range(h):
print(str(i+1)+" "+str(i+2))
if d > h:
print("1 "+str(h+2))
for i in range(d-h-1):
print(str(h+2+i)+" "+str(h+3+i))
for i in range(d+2,n+1):
print("1 "+str(i))
``` | 0 |
|
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans. | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 94 8 16 73 85",
"output": "YES"
},
{
"input": "4\n25 35 7 31\n70 37 43 35",
"output": "YES"
},
{
"input": "10\n15 26 15 14 14 39 40 4 25 39\n27 72 16 44 69 48 53 17 63 42",
"output": "NO"
},
{
"input": "5\n22 5 19 16 32\n26 10 43 38 37",
"output": "NO"
},
{
"input": "5\n32 4 22 40 26\n39 20 36 98 44",
"output": "YES"
},
{
"input": "6\n18 25 3 10 13 37\n38 73 19 35 24 37",
"output": "YES"
},
{
"input": "2\n2 2\n2 2",
"output": "YES"
},
{
"input": "2\n2 5\n2 5",
"output": "YES"
},
{
"input": "2\n1000 1008\n10000 2352",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5\n1 2 3 4 11",
"output": "YES"
},
{
"input": "4\n1 0 0 0\n2 0 0 0",
"output": "YES"
},
{
"input": "2\n0 0\n1 2",
"output": "YES"
},
{
"input": "3\n9 13 4\n10 14 5",
"output": "NO"
},
{
"input": "2\n0 0\n1 1",
"output": "YES"
},
{
"input": "5\n1 1 2 3 1\n1 1 2 3 4",
"output": "NO"
},
{
"input": "2\n0 0\n0 0",
"output": "YES"
},
{
"input": "3\n5 1 1\n5 5 5",
"output": "YES"
}
] | 1,510,992,282 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 37 | 156 | 11,366,400 | number = int(input())
numerator = 0
denominator = 0
lst = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
if len(lst) == 2 and len(lst2) == 2:
num = 0
den = 0
for item in lst:
num = num + item
for item in lst2:
den = den + item
if num/den<=1:
print("YES")
else:
print("NO")
else:
numerator = 0
for item in lst:
numerator = numerator + item
second = lst2[0]
for i in range(2):
for item in lst2:
if item > second:
second = item
denominator = denominator + second
lst2.remove(second)
second = lst2[0]
if numerator/denominator<=1:
print("YES")
else:
print("NO")
| Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input Specification:
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans.
Output Specification:
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Demo Input:
['2\n3 5\n3 6\n', '3\n6 8 9\n6 10 12\n', '5\n0 0 5 0 0\n1 1 8 10 5\n', '4\n4 1 0 3\n5 2 2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'YES\n']
Note:
In the first sample, there are already 2 cans, so the answer is "YES". | ```python
number = int(input())
numerator = 0
denominator = 0
lst = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
if len(lst) == 2 and len(lst2) == 2:
num = 0
den = 0
for item in lst:
num = num + item
for item in lst2:
den = den + item
if num/den<=1:
print("YES")
else:
print("NO")
else:
numerator = 0
for item in lst:
numerator = numerator + item
second = lst2[0]
for i in range(2):
for item in lst2:
if item > second:
second = item
denominator = denominator + second
lst2.remove(second)
second = lst2[0]
if numerator/denominator<=1:
print("YES")
else:
print("NO")
``` | -1 |
|
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,639,768,640 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 61 | 0 | no_of_employees=int(input())
i=1
ways=0
while(i<=no_of_employees/2):
if(no_of_employees%i==0):
ways+=1
i+=1
print(ways) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | ```python
no_of_employees=int(input())
i=1
ways=0
while(i<=no_of_employees/2):
if(no_of_employees%i==0):
ways+=1
i+=1
print(ways)
``` | 3 |
|
359 | C | Prime Number | PROGRAMMING | 1,900 | [
"math",
"number theory"
] | null | null | Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...<=+<=*a**n*. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers *s* and *t*. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109<=+<=7). | The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109). | Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\n2 2\n",
"3 3\n1 2 3\n",
"2 2\n29 29\n",
"4 5\n0 0 0 0\n"
] | [
"8\n",
"27\n",
"73741817\n",
"1\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/acb3d7990f024100be499bcb59828fa6e23a867d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to the problem is 1073741824 *mod* 1000000007 = 73741817.
In the fourth sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/05a5fca3fb4690369838ff6dfeda521c959aa937.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 1. | 1,500 | [
{
"input": "2 2\n2 2",
"output": "8"
},
{
"input": "3 3\n1 2 3",
"output": "27"
},
{
"input": "2 2\n29 29",
"output": "73741817"
},
{
"input": "4 5\n0 0 0 0",
"output": "1"
},
{
"input": "1 2\n1000000000",
"output": "1"
},
{
"input": "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2",
"output": "8"
},
{
"input": "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2",
"output": "49"
},
{
"input": "3 2\n0 1 1",
"output": "4"
},
{
"input": "1 127\n1000000000",
"output": "1"
},
{
"input": "1 800000011\n800000011",
"output": "1"
},
{
"input": "1 800000011\n999999999",
"output": "1"
},
{
"input": "3 3\n1 1 1",
"output": "27"
}
] | 1,656,084,041 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 4,096,000 | print("12345678 " * (10**5))
| Title: Prime Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...<=+<=*a**n*. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers *s* and *t*. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109<=+<=7).
Input Specification:
The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109).
Output Specification:
Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7).
Demo Input:
['2 2\n2 2\n', '3 3\n1 2 3\n', '2 2\n29 29\n', '4 5\n0 0 0 0\n']
Demo Output:
['8\n', '27\n', '73741817\n', '1\n']
Note:
In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/acb3d7990f024100be499bcb59828fa6e23a867d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to the problem is 1073741824 *mod* 1000000007 = 73741817.
In the fourth sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/05a5fca3fb4690369838ff6dfeda521c959aa937.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 1. | ```python
print("12345678 " * (10**5))
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,609,772,487 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | s = input()
uppercase = 0
lowercase = 0
if s.islower() == True or s.isupper() == True:
print(s)
else:
for i in range(len(s)):
if s[i].isupper() == True:
uppercase += 1
else:
lowercase += 1
if lowercase >= uppercase:
print(s.lower())
else:
print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s = input()
uppercase = 0
lowercase = 0
if s.islower() == True or s.isupper() == True:
print(s)
else:
for i in range(len(s)):
if s[i].isupper() == True:
uppercase += 1
else:
lowercase += 1
if lowercase >= uppercase:
print(s.lower())
else:
print(s.upper())
``` | 0 |
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,578,862,036 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 217 | 8,499,200 | def isOdd (x):
return x%2==1
def isEven (x):
return x%2==0
input()
arr = [int(z) for z in input().split()]
oddA = list(filter(isOdd,arr))
oddA.sort()
evenSum = sum(filter(isEven,arr))
if(isOdd(len(oddA))):
print(evenSum+sum(oddA[1:]))
else:
print(evenSum+sum(oddA))
| 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
def isOdd (x):
return x%2==1
def isEven (x):
return x%2==0
input()
arr = [int(z) for z in input().split()]
oddA = list(filter(isOdd,arr))
oddA.sort()
evenSum = sum(filter(isEven,arr))
if(isOdd(len(oddA))):
print(evenSum+sum(oddA[1:]))
else:
print(evenSum+sum(oddA))
``` | 3 |
|
472 | B | Design Tutorial: Learn from Life | PROGRAMMING | 1,300 | [] | null | null | One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have *n* people standing on the first floor, the *i*-th person wants to go to the *f**i*-th floor. Unfortunately, there is only one elevator and its capacity equal to *k* (that is at most *k* people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs |*a*<=-<=*b*| seconds to move from the *a*-th floor to the *b*-th floor (we don't count the time the people need to get on and off the elevator).
What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor? | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2000) — the number of people and the maximal capacity of the elevator.
The next line contains *n* integers: *f*1,<=*f*2,<=...,<=*f**n* (2<=≤<=*f**i*<=≤<=2000), where *f**i* denotes the target floor of the *i*-th person. | Output a single integer — the minimal time needed to achieve the goal. | [
"3 2\n2 3 4\n",
"4 2\n50 100 50 100\n",
"10 3\n2 2 2 2 2 2 2 2 2 2\n"
] | [
"8\n",
"296\n",
"8\n"
] | In first sample, an optimal solution is:
1. The elevator takes up person #1 and person #2. 1. It goes to the 2nd floor. 1. Both people go out of the elevator. 1. The elevator goes back to the 1st floor. 1. Then the elevator takes up person #3. 1. And it goes to the 2nd floor. 1. It picks up person #2. 1. Then it goes to the 3rd floor. 1. Person #2 goes out. 1. Then it goes to the 4th floor, where person #3 goes out. 1. The elevator goes back to the 1st floor. | 1,000 | [
{
"input": "3 2\n2 3 4",
"output": "8"
},
{
"input": "4 2\n50 100 50 100",
"output": "296"
},
{
"input": "10 3\n2 2 2 2 2 2 2 2 2 2",
"output": "8"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "2 1\n2 2",
"output": "4"
},
{
"input": "2 2\n2 2",
"output": "2"
},
{
"input": "11 4\n2 3 4 5 6 7 8 9 10 11 12",
"output": "42"
},
{
"input": "70 1311\n1146 769 1530 1132 877 1352 1295 1282 1086 914 852 1351 1432 847 1105 776 1278 716 1435 749 1320 869 812 1179 1239 1426 1403 1296 1489 1018 848 1215 1278 1203 1386 1113 812 896 1287 733 1328 1517 964 1317 1487 1322 1281 843 863 1220 790 1121 1442 726 957 1465 974 1314 993 1286 1163 938 902 1197 859 807 718 916 783 1450",
"output": "3058"
},
{
"input": "22 1481\n1555 1499 1615 535 399 795 432 1830 1645 452 278 1173 1501 1779 317 796 1855 1631 651 495 236 1122",
"output": "3708"
},
{
"input": "100 1\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "19800"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "198"
},
{
"input": "2 1\n2000 2000",
"output": "7996"
},
{
"input": "5 3\n2000 2000 2000 2000 1999",
"output": "7996"
}
] | 1,679,909,382 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | people, capacity = map(int, input().split())
lst = sorted(list(map(int, input().split())))
tempTime = 0
while(len(lst) > 0):
tempArr = []
for i in range(capacity):
if(len(lst) > 0):
tempArr.append(lst.pop())
tempArr = sorted(tempArr)
if(len(tempArr) < 0):
break
tempTime += abs(tempArr[0] - 1)
for i in range(len(tempArr) - 1):
first = tempArr[i]
second = tempArr[i + 1]
tempTime += abs(second - first)
tempTime += abs(tempArr[len(tempArr) - 1] - 1)
print(tempTime) | Title: Design Tutorial: Learn from Life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have *n* people standing on the first floor, the *i*-th person wants to go to the *f**i*-th floor. Unfortunately, there is only one elevator and its capacity equal to *k* (that is at most *k* people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs |*a*<=-<=*b*| seconds to move from the *a*-th floor to the *b*-th floor (we don't count the time the people need to get on and off the elevator).
What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2000) — the number of people and the maximal capacity of the elevator.
The next line contains *n* integers: *f*1,<=*f*2,<=...,<=*f**n* (2<=≤<=*f**i*<=≤<=2000), where *f**i* denotes the target floor of the *i*-th person.
Output Specification:
Output a single integer — the minimal time needed to achieve the goal.
Demo Input:
['3 2\n2 3 4\n', '4 2\n50 100 50 100\n', '10 3\n2 2 2 2 2 2 2 2 2 2\n']
Demo Output:
['8\n', '296\n', '8\n']
Note:
In first sample, an optimal solution is:
1. The elevator takes up person #1 and person #2. 1. It goes to the 2nd floor. 1. Both people go out of the elevator. 1. The elevator goes back to the 1st floor. 1. Then the elevator takes up person #3. 1. And it goes to the 2nd floor. 1. It picks up person #2. 1. Then it goes to the 3rd floor. 1. Person #2 goes out. 1. Then it goes to the 4th floor, where person #3 goes out. 1. The elevator goes back to the 1st floor. | ```python
people, capacity = map(int, input().split())
lst = sorted(list(map(int, input().split())))
tempTime = 0
while(len(lst) > 0):
tempArr = []
for i in range(capacity):
if(len(lst) > 0):
tempArr.append(lst.pop())
tempArr = sorted(tempArr)
if(len(tempArr) < 0):
break
tempTime += abs(tempArr[0] - 1)
for i in range(len(tempArr) - 1):
first = tempArr[i]
second = tempArr[i + 1]
tempTime += abs(second - first)
tempTime += abs(tempArr[len(tempArr) - 1] - 1)
print(tempTime)
``` | 3 |
|
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"output": "99"
},
{
"input": "gngvi",
"output": "44"
},
{
"input": "aaaaa",
"output": "0"
},
{
"input": "a",
"output": "0"
},
{
"input": "z",
"output": "1"
},
{
"input": "vyadeehhikklnoqrs",
"output": "28"
},
{
"input": "jjiihhhhgggfedcccbazyxx",
"output": "21"
},
{
"input": "fyyptqqxuciqvwdewyppjdzur",
"output": "117"
},
{
"input": "fqcnzmzmbobmancqcoalzmanaobpdse",
"output": "368"
},
{
"input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza",
"output": "8"
},
{
"input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy",
"output": "644"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
"output": "8"
},
{
"input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl",
"output": "421"
},
{
"input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa",
"output": "84"
},
{
"input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco",
"output": "666"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww",
"output": "22"
},
{
"input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh",
"output": "643"
},
{
"input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib",
"output": "245"
},
{
"input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro",
"output": "468"
},
{
"input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned",
"output": "523"
},
{
"input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna",
"output": "130"
},
{
"input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh",
"output": "163"
},
{
"input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb",
"output": "155"
},
{
"input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp",
"output": "57"
},
{
"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs",
"output": "1236"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx",
"output": "49"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt",
"output": "331"
},
{
"input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte",
"output": "692"
},
{
"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh",
"output": "1293"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "16"
},
{
"input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple",
"output": "616"
},
{
"input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl",
"output": "605"
},
{
"input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud",
"output": "549"
},
{
"input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore",
"output": "688"
},
{
"input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc",
"output": "604"
},
{
"input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa",
"output": "572"
},
{
"input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp",
"output": "609"
},
{
"input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl",
"output": "223"
},
{
"input": "aa",
"output": "0"
}
] | 1,662,295,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | world = input()
a =ord("a") ; z = ord("z")
now = a ;
counter = 0
for i in range(0 , len(world)):
main = ord(world[i].lower())
if (main != now) :
ahead = abs(main - now) ;
back = (now - a ) + (z - main) + 1 if main > now else (z - now) + (main - a)+1
print(ahead , back , main ,z ,a , now)
if (ahead > back ):
counter += back;
now = main
else :
counter += ahead
now = main
print(world) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input Specification:
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Output Specification:
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
Demo Input:
['zeus\n', 'map\n', 'ares\n']
Demo Output:
['18\n', '35\n', '34\n']
Note:
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | ```python
world = input()
a =ord("a") ; z = ord("z")
now = a ;
counter = 0
for i in range(0 , len(world)):
main = ord(world[i].lower())
if (main != now) :
ahead = abs(main - now) ;
back = (now - a ) + (z - main) + 1 if main > now else (z - now) + (main - a)+1
print(ahead , back , main ,z ,a , now)
if (ahead > back ):
counter += back;
now = main
else :
counter += ahead
now = main
print(world)
``` | 0 |
|
748 | B | Santa Claus and Keyboard Check | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once. | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes. | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 1,000 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "bbbbbabbab\naaaaabaaba",
"output": "1\nb a"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx",
"output": "-1"
},
{
"input": "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc",
"output": "1\nd b"
},
{
"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd",
"output": "0"
},
{
"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak",
"output": "5\ng f\nn i\nd h\ne o\nb k"
},
{
"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc",
"output": "0"
},
{
"input": "ab\naa",
"output": "-1"
},
{
"input": "a\nz",
"output": "1\na z"
},
{
"input": "zz\nzy",
"output": "-1"
},
{
"input": "as\ndf",
"output": "2\na d\ns f"
},
{
"input": "abc\nbca",
"output": "-1"
},
{
"input": "rtfg\nrftg",
"output": "1\nt f"
},
{
"input": "y\ny",
"output": "0"
},
{
"input": "qwertyuiopasdfghjklzx\nzzzzzzzzzzzzzzzzzzzzz",
"output": "-1"
},
{
"input": "qazwsxedcrfvtgbyhnujmik\nqwertyuiasdfghjkzxcvbnm",
"output": "-1"
},
{
"input": "aaaaaa\nabcdef",
"output": "-1"
},
{
"input": "qwerty\nffffff",
"output": "-1"
},
{
"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh",
"output": "0"
},
{
"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe",
"output": "-1"
},
{
"input": "bacccbbacabbcaacbbba\nbacccbbacabbcaacbbba",
"output": "0"
},
{
"input": "dbadbddddb\nacbacaaaac",
"output": "-1"
},
{
"input": "dacbdbbbdd\nadbdadddaa",
"output": "-1"
},
{
"input": "bbbbcbcbbc\ndaddbabddb",
"output": "-1"
},
{
"input": "dddddbcdbd\nbcbbbdacdb",
"output": "-1"
},
{
"input": "cbadcbcdaa\nabbbababbb",
"output": "-1"
},
{
"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk",
"output": "-1"
},
{
"input": "acbbccabaa\nabbbbbabaa",
"output": "-1"
},
{
"input": "ccccaccccc\naaaabaaaac",
"output": "-1"
},
{
"input": "acbacacbbb\nacbacacbbb",
"output": "0"
},
{
"input": "abbababbcc\nccccccccbb",
"output": "-1"
},
{
"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh",
"output": "-1"
},
{
"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage",
"output": "-1"
},
{
"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai",
"output": "-1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "a\nz",
"output": "1\na z"
},
{
"input": "z\na",
"output": "1\nz a"
},
{
"input": "aa\nzz",
"output": "1\na z"
},
{
"input": "az\nza",
"output": "1\na z"
},
{
"input": "aa\nza",
"output": "-1"
},
{
"input": "za\nzz",
"output": "-1"
},
{
"input": "aa\nab",
"output": "-1"
},
{
"input": "hehe\nheeh",
"output": "-1"
},
{
"input": "bd\ncc",
"output": "-1"
},
{
"input": "he\nhh",
"output": "-1"
},
{
"input": "hee\nheh",
"output": "-1"
},
{
"input": "aa\nac",
"output": "-1"
},
{
"input": "ab\naa",
"output": "-1"
},
{
"input": "hello\nehlol",
"output": "-1"
},
{
"input": "ac\naa",
"output": "-1"
},
{
"input": "aaabbb\nbbbaab",
"output": "-1"
},
{
"input": "aa\nfa",
"output": "-1"
},
{
"input": "hg\nee",
"output": "-1"
},
{
"input": "helloworld\nehoolwlrow",
"output": "-1"
},
{
"input": "abb\nbab",
"output": "-1"
},
{
"input": "aaa\naae",
"output": "-1"
},
{
"input": "aba\nbaa",
"output": "-1"
},
{
"input": "aa\nba",
"output": "-1"
},
{
"input": "da\naa",
"output": "-1"
},
{
"input": "aaa\naab",
"output": "-1"
},
{
"input": "xy\nzz",
"output": "-1"
}
] | 1,567,793,582 | 2,147,483,647 | Python 3 | OK | TESTS | 86 | 124 | 0 | s = input()
t = input()
w1, w2 = set(), set()
for i in range(len(s)):
l1, l2 = min(s[i], t[i]), max(s[i], t[i])
if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1:
print(-1)
exit()
else:
w2.add(s[i])
w2.add(t[i])
w1.add((l1, l2))
result = [elem for elem in w1 if elem[0] != elem[1]]
print(len(result))
for elem in result:
print(*elem)
| Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
Input Specification:
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
Output Specification:
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
Demo Input:
['helloworld\nehoolwlroz\n', 'hastalavistababy\nhastalavistababy\n', 'merrychristmas\nchristmasmerry\n']
Demo Output:
['3\nh e\nl o\nd z\n', '0\n', '-1\n']
Note:
none | ```python
s = input()
t = input()
w1, w2 = set(), set()
for i in range(len(s)):
l1, l2 = min(s[i], t[i]), max(s[i], t[i])
if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1:
print(-1)
exit()
else:
w2.add(s[i])
w2.add(t[i])
w1.add((l1, l2))
result = [elem for elem in w1 if elem[0] != elem[1]]
print(len(result))
for elem in result:
print(*elem)
``` | 3 |
|
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU",
"output": "80"
},
{
"input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR",
"output": "84"
},
{
"input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD",
"output": "76"
},
{
"input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR",
"output": "86"
},
{
"input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR",
"output": "84"
},
{
"input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL",
"output": "86"
},
{
"input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU",
"output": "86"
},
{
"input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL",
"output": "84"
},
{
"input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR",
"output": "82"
},
{
"input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD",
"output": "92"
},
{
"input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD",
"output": "86"
},
{
"input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL",
"output": "88"
},
{
"input": "1\nU",
"output": "0"
},
{
"input": "5\nUUULD",
"output": "2"
},
{
"input": "1\nD",
"output": "0"
},
{
"input": "5\nURLUL",
"output": "2"
},
{
"input": "5\nDDDRU",
"output": "2"
},
{
"input": "2\nLR",
"output": "2"
},
{
"input": "8\nDDRDLDUR",
"output": "4"
},
{
"input": "6\nLLLLUD",
"output": "2"
},
{
"input": "13\nRRRLLLLLLLLLL",
"output": "6"
}
] | 1,564,857,637 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | input()
k=input()
print((min(k.count("R"),k.count("L"))+min(k.count("D"),k.count("U")))*2)
| Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
Input Specification:
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Output Specification:
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
Demo Input:
['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n']
Demo Output:
['4\n', '0\n', '4\n']
Note:
none | ```python
input()
k=input()
print((min(k.count("R"),k.count("L"))+min(k.count("D"),k.count("U")))*2)
``` | 3 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,551,321,368 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | a=str(input())
s="hello"
j=0
c=0
for i in range(0,len(a)):
if a[i]==s[j]:
i+=1
j+=1
c+=1
if c==5:
break
if c==5:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
a=str(input())
s="hello"
j=0
c=0
for i in range(0,len(a)):
if a[i]==s[j]:
i+=1
j+=1
c+=1
if c==5:
break
if c==5:
print("YES")
else:
print("NO")
``` | 3.9455 |
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,632,832,107 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 6,963,200 | t = int(input())
n = input().split(" ")
num = [int(i) for i in n]
even = 0;lastev = 0;lastodd = 0
for i in range(1,t+1):
if (num[i-1]%2==0):
even+=1
lastev = i
else:
even-=1
lastodd = i
if even > 0: print(lastodd)
else:print(lastev) | 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
t = int(input())
n = input().split(" ")
num = [int(i) for i in n]
even = 0;lastev = 0;lastodd = 0
for i in range(1,t+1):
if (num[i-1]%2==0):
even+=1
lastev = i
else:
even-=1
lastodd = i
if even > 0: print(lastodd)
else:print(lastev)
``` | 3.95603 |
105 | C | Item World | PROGRAMMING | 2,200 | [
"brute force",
"implementation",
"sortings"
] | C. Item World | 2 | 256 | Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
Each item belongs to one class. In this problem we will only consider three of such classes: weapon, armor, orb.
Besides, there's a whole new world hidden inside each item. We can increase an item's level travelling to its world. We can also capture the so-called residents in the Item World
Residents are the creatures that live inside items. Each resident gives some bonus to the item in which it is currently located. We will only consider residents of types: gladiator (who improves the item's atk), sentry (who improves def) and physician (who improves res).
Each item has the size parameter. The parameter limits the maximum number of residents that can live inside an item. We can move residents between items. Within one moment of time we can take some resident from an item and move it to some other item if it has a free place for a new resident. We cannot remove a resident from the items and leave outside — any of them should be inside of some item at any moment of time.
Laharl has a certain number of items. He wants to move the residents between items so as to equip himself with weapon, armor and a defensive orb. The weapon's atk should be largest possible in the end. Among all equipping patterns containing weapon's maximum atk parameter we should choose the ones where the armor’s def parameter is the largest possible. Among all such equipment patterns we should choose the one where the defensive orb would have the largest possible res parameter. Values of the parameters def and res of weapon, atk and res of armor and atk and def of orb are indifferent for Laharl.
Find the optimal equipment pattern Laharl can get. | The first line contains number *n* (3<=≤<=*n*<=≤<=100) — representing how many items Laharl has.
Then follow *n* lines. Each line contains description of an item. The description has the following form: "*name* *class* *atk* *def* *res* *size*" — the item's name, class, basic attack, defense and resistance parameters and its size correspondingly.
- *name* and *class* are strings and *atk*, *def*, *res* and *size* are integers. - *name* consists of lowercase Latin letters and its length can range from 1 to 10, inclusive. - *class* can be "weapon", "armor" or "orb". - 0<=≤<=*atk*,<=*def*,<=*res*<=≤<=1000. - 1<=≤<=*size*<=≤<=10.
It is guaranteed that Laharl has at least one item of each class.
The next line contains an integer *k* (1<=≤<=*k*<=≤<=1000) — the number of residents.
Then *k* lines follow. Each of them describes a resident. A resident description looks like: "*name* *type* *bonus* *home*" — the resident's name, his type, the number of points the resident adds to the item's corresponding parameter and the name of the item which currently contains the resident.
- *name*, *type* and *home* are strings and *bonus* is an integer. - *name* consists of lowercase Latin letters and its length can range from 1 to 10, inclusive. - *type* may be "gladiator", "sentry" or "physician". - 1<=≤<=*bonus*<=≤<=100.
It is guaranteed that the number of residents in each item does not exceed the item's size.
The names of all items and residents are pairwise different.
All words and numbers in the input are separated by single spaces. | Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names.
Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain.
Use single spaces for separation.
If there are several possible solutions, print any of them. | [
"4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n5\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\n",
"4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n"
] | [
"sword 2 petr mike \npagstarmor 1 blackjack \niceorb 2 teddy bobby \n",
"longbow 1 mike \npagstarmor 1 bobby \niceorb 2 petr joe \n"
] | In the second sample we have no free space inside the items, therefore we cannot move the residents between them. | 1,500 | [
{
"input": "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n5\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword",
"output": "sword 2 petr mike \npagstarmor 1 blackjack \niceorb 2 teddy bobby "
},
{
"input": "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb",
"output": "longbow 1 mike \npagstarmor 1 bobby \niceorb 2 petr joe "
},
{
"input": "3\nweapon weapon 10 5 2 4\narmor armor 0 20 0 6\norb orb 3 4 25 3\n3\nx gladiator 12 armor\ny sentry 13 orb\nz physician 5 weapon",
"output": "weapon 1 x \narmor 1 y \norb 1 z "
},
{
"input": "6\nc armor 0 13 0 3\na weapon 23 0 0 3\nb weapon 20 0 0 4\ne orb 0 0 13 3\nd armor 0 15 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 a\nh gladiator 3 f\ng gladiator 4 e\ni gladiator 7 a\nk gladiator 1 b",
"output": "a 3 i j g \nd 2 h k \nf 0 "
},
{
"input": "6\nc armor 0 13 0 3\na weapon 23 0 0 3\nb weapon 10 0 0 4\ne orb 0 0 19 3\nd armor 0 15 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 e\nh gladiator 5 f\ng gladiator 4 c\ni gladiator 7 b\nk gladiator 1 d",
"output": "a 3 i j h \nd 2 g k \ne 0 "
},
{
"input": "6\nc armor 0 14 0 3\na weapon 23 0 0 3\nb weapon 21 0 0 4\ne orb 0 0 13 3\nd armor 0 5 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 f\nh gladiator 5 a\ng gladiator 6 c\ni gladiator 7 d\nk gladiator 1 d",
"output": "b 4 i j g h \nc 1 k \nf 0 "
},
{
"input": "5\nxx weapon 15 0 0 2\nyy armor 0 14 0 2\nzz orb 0 0 16 2\npp weapon 1 0 0 5\nqq armor 0 1 0 4\n9\na gladiator 2 pp\nb gladiator 3 pp\nc gladiator 4 pp\nd sentry 1 pp\ne sentry 2 pp\nf sentry 3 qq\ng physician 2 qq\nh physician 3 qq\ni physician 3 qq",
"output": "xx 2 c b \nyy 2 f e \nzz 2 i h "
},
{
"input": "5\npixiebow weapon 10 0 7 2\nlance weapon 12 4 2 1\nbushido armor 0 14 1 4\nstarorb orb 2 3 16 3\nmoonorb orb 3 4 8 1\n8\nste gladiator 10 moonorb\nphi gladiator 8 starorb\nhjk gladiator 5 starorb\npoi gladiator 7 starorb\njor gladiator 4 lance\npui gladiator 6 bushido\nzea gladiator 1 bushido\nqwe gladiator 2 pixiebow",
"output": "pixiebow 2 ste phi \nbushido 4 poi pui hjk jor \nstarorb 2 qwe zea "
},
{
"input": "5\npixiebow weapon 10 0 7 2\nlance weapon 12 4 2 1\nbushido armor 0 14 1 4\nstarorb orb 2 3 16 3\nmoonorb orb 3 4 8 1\n11\nste gladiator 10 moonorb\nphi gladiator 8 starorb\nhjk gladiator 5 starorb\npoi gladiator 7 starorb\njor gladiator 4 lance\npui gladiator 6 bushido\nzea gladiator 1 bushido\nqwe gladiator 2 pixiebow\nkkk physician 20 bushido\nlkh sentry 4 pixiebow\noop sentry 8 bushido",
"output": "lance 1 jor \nbushido 4 pui zea kkk oop \nstarorb 3 phi hjk poi "
},
{
"input": "3\nhcyc weapon 646 755 45 5\nhfh armor 556 875 434 6\njkob orb 654 0 65 7\n1\njhcytccc sentry 76 jkob",
"output": "hcyc 0 \nhfh 1 jhcytccc \njkob 0 "
},
{
"input": "5\naxgovq orb 75 830 793 3\nzeckskde weapon 316 351 917 2\nnrtbk armor 540 178 332 2\nnhjodogdd armor 880 453 186 2\ndxrgvjhvhg weapon 961 616 561 3\n7\nzvi gladiator 16 axgovq\nrq gladiator 52 axgovq\njlr physician 69 zeckskde\njackbeadx sentry 90 zeckskde\nvuhpq gladiator 23 nrtbk\nvfhyjtps physician 88 nhjodogdd\nrb gladiator 90 nhjodogdd",
"output": "dxrgvjhvhg 3 rb rq vuhpq \nnhjodogdd 2 jackbeadx zvi \naxgovq 2 vfhyjtps jlr "
},
{
"input": "5\nhs orb 830 875 879 3\nfudflb weapon 13 854 317 1\nwwvhixixe armor 500 285 382 2\nh orb 58 57 409 2\ny weapon 734 408 297 4\n12\nwvxwgjoera physician 55 hs\nusukedr sentry 41 hs\niu physician 100 hs\ngixlx gladiator 42 fudflb\nrd sentry 95 wwvhixixe\nbaff sentry 6 wwvhixixe\nwkhxoubhy sentry 73 h\niat physician 3 h\nc sentry 24 y\noveuaziss gladiator 54 y\nbyfhpjezzv sentry 18 y\njxnpuofle gladiator 65 y",
"output": "y 4 c oveuaziss byfhpjezzv jxnpuofle \nwwvhixixe 2 rd baff \nhs 3 wvxwgjoera usukedr iu "
},
{
"input": "4\nsword weapon 0 0 0 2\npagstarmor armor 0 0 0 1\niceorb orb 0 0 0 2\nlongbow weapon 0 0 0 1\n1\nteddy physician 1 iceorb",
"output": "sword 0 \npagstarmor 0 \niceorb 1 teddy "
}
] | 1,406,311,866 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 122 | 0 | def searchBest(iType, number, rType, countResidents):
global items, equipped
best = 0
ret = None
for item, params in items.items():
if params[0] == iType:
val = int(params[number])
if countResidents:
for resid in equipped[item]:
if resid[1] == rType:
val += int(resid[2])
if val > best:
best = val
ret = item
return ret
def printItem(item):
global equipped
print(item, len(equipped[item]), ' '.join([x[0] for x in equipped[item]]))
def searchFor(iType, number, might):
global items, equipped
pSum = [0]
for x in might:
pSum.append(pSum[-1] + int(x[2]))
while len(pSum) < 11:
pSum.append(pSum[-1])
bestVal = 0
for item, params in items.items():
if params[0] == iType:
val = int(params[number]) + pSum[int(params[4])]
if val > bestVal:
bestVal = val
for item, params in items.items():
if params[0] == iType:
val = int(params[number]) + pSum[int(params[4])]
if val == bestVal:
equipped[item] = might[:int(params[4])]
printItem(item)
return None
n = int(input())
items = dict()
equipped = dict()
for i in range(n):
t = tuple(input().split())
items[t[0]] = t[1:]
k = int(input())
residents = [None for i in range(k)]
glads = dict()
for i in range(k):
residents[i] = tuple(input().split())
equipped[residents[i][3]] = equipped.get(residents[i][3], []) + [residents[i]]
canSwap = False
for name, val in equipped.items():
if len(val) < int(items[name][4]):
canSwap = True
if canSwap:
glads = sorted([x for x in residents if x[1] == 'gladiator'], key = lambda x: -int(x[2]))
sentries = sorted([x for x in residents if x[1] == 'sentry'], key = lambda x: -int(x[2]))
phys = sorted([x for x in residents if x[1] == 'physician'], key = lambda x: -int(x[2]))
searchFor('weapon', 1, glads)
searchFor('armor', 2, sentries)
searchFor('orb', 3, phys)
else:
printItem(searchBest('weapon', 1, 'gladiator', True))
printItem(searchBest('armor', 2, 'sentry', True))
printItem(searchBest('orb', 3, 'physician', True))
| Title: Item World
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
Each item belongs to one class. In this problem we will only consider three of such classes: weapon, armor, orb.
Besides, there's a whole new world hidden inside each item. We can increase an item's level travelling to its world. We can also capture the so-called residents in the Item World
Residents are the creatures that live inside items. Each resident gives some bonus to the item in which it is currently located. We will only consider residents of types: gladiator (who improves the item's atk), sentry (who improves def) and physician (who improves res).
Each item has the size parameter. The parameter limits the maximum number of residents that can live inside an item. We can move residents between items. Within one moment of time we can take some resident from an item and move it to some other item if it has a free place for a new resident. We cannot remove a resident from the items and leave outside — any of them should be inside of some item at any moment of time.
Laharl has a certain number of items. He wants to move the residents between items so as to equip himself with weapon, armor and a defensive orb. The weapon's atk should be largest possible in the end. Among all equipping patterns containing weapon's maximum atk parameter we should choose the ones where the armor’s def parameter is the largest possible. Among all such equipment patterns we should choose the one where the defensive orb would have the largest possible res parameter. Values of the parameters def and res of weapon, atk and res of armor and atk and def of orb are indifferent for Laharl.
Find the optimal equipment pattern Laharl can get.
Input Specification:
The first line contains number *n* (3<=≤<=*n*<=≤<=100) — representing how many items Laharl has.
Then follow *n* lines. Each line contains description of an item. The description has the following form: "*name* *class* *atk* *def* *res* *size*" — the item's name, class, basic attack, defense and resistance parameters and its size correspondingly.
- *name* and *class* are strings and *atk*, *def*, *res* and *size* are integers. - *name* consists of lowercase Latin letters and its length can range from 1 to 10, inclusive. - *class* can be "weapon", "armor" or "orb". - 0<=≤<=*atk*,<=*def*,<=*res*<=≤<=1000. - 1<=≤<=*size*<=≤<=10.
It is guaranteed that Laharl has at least one item of each class.
The next line contains an integer *k* (1<=≤<=*k*<=≤<=1000) — the number of residents.
Then *k* lines follow. Each of them describes a resident. A resident description looks like: "*name* *type* *bonus* *home*" — the resident's name, his type, the number of points the resident adds to the item's corresponding parameter and the name of the item which currently contains the resident.
- *name*, *type* and *home* are strings and *bonus* is an integer. - *name* consists of lowercase Latin letters and its length can range from 1 to 10, inclusive. - *type* may be "gladiator", "sentry" or "physician". - 1<=≤<=*bonus*<=≤<=100.
It is guaranteed that the number of residents in each item does not exceed the item's size.
The names of all items and residents are pairwise different.
All words and numbers in the input are separated by single spaces.
Output Specification:
Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names.
Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain.
Use single spaces for separation.
If there are several possible solutions, print any of them.
Demo Input:
['4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n5\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\n', '4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n']
Demo Output:
['sword 2 petr mike \npagstarmor 1 blackjack \niceorb 2 teddy bobby \n', 'longbow 1 mike \npagstarmor 1 bobby \niceorb 2 petr joe \n']
Note:
In the second sample we have no free space inside the items, therefore we cannot move the residents between them. | ```python
def searchBest(iType, number, rType, countResidents):
global items, equipped
best = 0
ret = None
for item, params in items.items():
if params[0] == iType:
val = int(params[number])
if countResidents:
for resid in equipped[item]:
if resid[1] == rType:
val += int(resid[2])
if val > best:
best = val
ret = item
return ret
def printItem(item):
global equipped
print(item, len(equipped[item]), ' '.join([x[0] for x in equipped[item]]))
def searchFor(iType, number, might):
global items, equipped
pSum = [0]
for x in might:
pSum.append(pSum[-1] + int(x[2]))
while len(pSum) < 11:
pSum.append(pSum[-1])
bestVal = 0
for item, params in items.items():
if params[0] == iType:
val = int(params[number]) + pSum[int(params[4])]
if val > bestVal:
bestVal = val
for item, params in items.items():
if params[0] == iType:
val = int(params[number]) + pSum[int(params[4])]
if val == bestVal:
equipped[item] = might[:int(params[4])]
printItem(item)
return None
n = int(input())
items = dict()
equipped = dict()
for i in range(n):
t = tuple(input().split())
items[t[0]] = t[1:]
k = int(input())
residents = [None for i in range(k)]
glads = dict()
for i in range(k):
residents[i] = tuple(input().split())
equipped[residents[i][3]] = equipped.get(residents[i][3], []) + [residents[i]]
canSwap = False
for name, val in equipped.items():
if len(val) < int(items[name][4]):
canSwap = True
if canSwap:
glads = sorted([x for x in residents if x[1] == 'gladiator'], key = lambda x: -int(x[2]))
sentries = sorted([x for x in residents if x[1] == 'sentry'], key = lambda x: -int(x[2]))
phys = sorted([x for x in residents if x[1] == 'physician'], key = lambda x: -int(x[2]))
searchFor('weapon', 1, glads)
searchFor('armor', 2, sentries)
searchFor('orb', 3, phys)
else:
printItem(searchBest('weapon', 1, 'gladiator', True))
printItem(searchBest('armor', 2, 'sentry', True))
printItem(searchBest('orb', 3, 'physician', True))
``` | -1 |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,612,367,690 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 0 | n, m, z = [int(i) for i in input().split()]
copy_n = n
copy_m = m
x = 1
cnt = 0
while x <= z:
if n == x:
n += copy_n
if m == x:
m += copy_m
cnt += 1
x += 1
continue
if x == m:
m += copy_m
x += 1
print(cnt) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
n, m, z = [int(i) for i in input().split()]
copy_n = n
copy_m = m
x = 1
cnt = 0
while x <= z:
if n == x:
n += copy_n
if m == x:
m += copy_m
cnt += 1
x += 1
continue
if x == m:
m += copy_m
x += 1
print(cnt)
``` | 3 |
|
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85",
"output": "91"
},
{
"input": "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 825 540 435 54\n777 682 984 20 337 480 264 137 249 502\n51 467 479 228 923 752 714 436 199 973\n3 91 612 571 631 212 751 84 886 948\n252 130 583 23 194 985 234 978 709 16\n636 991 203 469 719 540 184 902 503 652\n826 680 150 284 37 987 360 183 447 51",
"output": "184"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "2 1\n999999999\n1000000000",
"output": "1000000000"
}
] | 1,605,638,007 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 108 | 512,000 | n, m = map(int, input().split())
ul = []
pr = []
for i in range(n):
pr = [int(i) for i in input().split()]
ul.append(pr)
pr = []
mini = []
maxi = []
for i in range(n):
min1 = ul[i][0]
for j in range(m):
if min1 > ul[i][j]:
min1 = ul[i][j]
mini.append(min1)
for i in range(n):
max1 = ul[i][0]
for j in range(m):
if max1 < ul[i][j]:
max1 = ul[i][j]
maxi.append(max1)
l = 0
while mini[l] != max(mini):
l += 1
print(mini[l]) | Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Output Specification:
Print the only integer *a* — the cost of the dinner for Jack and Emma.
Demo Input:
['3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n', '3 3\n1 2 3\n2 3 1\n3 1 2\n']
Demo Output:
['2\n', '1\n']
Note:
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | ```python
n, m = map(int, input().split())
ul = []
pr = []
for i in range(n):
pr = [int(i) for i in input().split()]
ul.append(pr)
pr = []
mini = []
maxi = []
for i in range(n):
min1 = ul[i][0]
for j in range(m):
if min1 > ul[i][j]:
min1 = ul[i][j]
mini.append(min1)
for i in range(n):
max1 = ul[i][0]
for j in range(m):
if max1 < ul[i][j]:
max1 = ul[i][j]
maxi.append(max1)
l = 0
while mini[l] != max(mini):
l += 1
print(mini[l])
``` | 3 |
|
1,009 | E | Intercity Travelling | PROGRAMMING | 2,000 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km.
Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on.
For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey.
Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$. | The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested. | Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$. | [
"2\n1 2\n",
"4\n1 3 3 7\n"
] | [
"5\n",
"60\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "5"
},
{
"input": "4\n1 3 3 7",
"output": "60"
},
{
"input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100",
"output": "758086002"
},
{
"input": "1\n12",
"output": "12"
}
] | 1,533,653,826 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,500 | 0 | a = int(input())
b = list(map(int,input().split()))
def totDist(k):
if k == 1:
#print('for k: 1 i: 0 remaining dist: 0')
return b[0]
else:
c = 0
for i in range(1,k):
d = totDist(k-i)
e = sum(b[:i])
c += e*(2**(k-i-1))+d
#print('for k: '+str(k)+' i: '+str(i)+ ' covered distance: '+str(e)+' remaining dist: ' + str(d))
c += sum(b[:k])
return c
print(totDist(a)%998244353) | Title: Intercity Travelling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km.
Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on.
For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey.
Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$.
Input Specification:
The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested.
Output Specification:
Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$.
Demo Input:
['2\n1 2\n', '4\n1 3 3 7\n']
Demo Output:
['5\n', '60\n']
Note:
none | ```python
a = int(input())
b = list(map(int,input().split()))
def totDist(k):
if k == 1:
#print('for k: 1 i: 0 remaining dist: 0')
return b[0]
else:
c = 0
for i in range(1,k):
d = totDist(k-i)
e = sum(b[:i])
c += e*(2**(k-i-1))+d
#print('for k: '+str(k)+' i: '+str(i)+ ' covered distance: '+str(e)+' remaining dist: ' + str(d))
c += sum(b[:k])
return c
print(totDist(a)%998244353)
``` | 0 |
|
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get. | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": "7980"
},
{
"input": "2",
"output": "2"
},
{
"input": "41",
"output": "63960"
},
{
"input": "29",
"output": "21924"
},
{
"input": "117",
"output": "1560780"
},
{
"input": "149",
"output": "3241644"
},
{
"input": "733",
"output": "392222436"
},
{
"input": "925",
"output": "788888100"
},
{
"input": "509",
"output": "131096004"
},
{
"input": "829",
"output": "567662724"
},
{
"input": "117",
"output": "1560780"
},
{
"input": "605",
"output": "220348260"
},
{
"input": "245",
"output": "14526540"
},
{
"input": "925",
"output": "788888100"
},
{
"input": "213",
"output": "9527916"
},
{
"input": "53",
"output": "140556"
},
{
"input": "341",
"output": "39303660"
},
{
"input": "21",
"output": "7980"
},
{
"input": "605",
"output": "220348260"
},
{
"input": "149",
"output": "3241644"
},
{
"input": "733",
"output": "392222436"
},
{
"input": "117",
"output": "1560780"
},
{
"input": "53",
"output": "140556"
},
{
"input": "245",
"output": "14526540"
},
{
"input": "829",
"output": "567662724"
},
{
"input": "924",
"output": "783776526"
},
{
"input": "508",
"output": "130065780"
},
{
"input": "700",
"output": "341042100"
},
{
"input": "636",
"output": "254839470"
},
{
"input": "20",
"output": "6460"
},
{
"input": "604",
"output": "218891412"
},
{
"input": "796",
"output": "501826260"
},
{
"input": "732",
"output": "389016270"
},
{
"input": "412",
"output": "69256788"
},
{
"input": "700",
"output": "341042100"
},
{
"input": "244",
"output": "14289372"
},
{
"input": "828",
"output": "563559150"
},
{
"input": "508",
"output": "130065780"
},
{
"input": "796",
"output": "501826260"
},
{
"input": "636",
"output": "254839470"
},
{
"input": "924",
"output": "783776526"
},
{
"input": "245",
"output": "14526540"
},
{
"input": "828",
"output": "563559150"
},
{
"input": "21",
"output": "7980"
},
{
"input": "605",
"output": "220348260"
},
{
"input": "636",
"output": "254839470"
},
{
"input": "924",
"output": "783776526"
},
{
"input": "116",
"output": "1507420"
},
{
"input": "700",
"output": "341042100"
},
{
"input": "732",
"output": "389016270"
},
{
"input": "20",
"output": "6460"
},
{
"input": "508",
"output": "130065780"
},
{
"input": "148",
"output": "3154620"
},
{
"input": "828",
"output": "563559150"
},
{
"input": "763116",
"output": "444394078546562430"
},
{
"input": "756604",
"output": "433115377058855412"
},
{
"input": "447244",
"output": "89460162932862372"
},
{
"input": "372636",
"output": "51742503205363470"
},
{
"input": "546924",
"output": "163597318076822526"
},
{
"input": "540412",
"output": "157823524476316788"
},
{
"input": "714700",
"output": "365063922340784100"
},
{
"input": "520731",
"output": "141201007712496270"
},
{
"input": "695019",
"output": "335728459024850814"
},
{
"input": "688507",
"output": "326379736779169710"
},
{
"input": "862795",
"output": "642275489615199390"
},
{
"input": "668827",
"output": "299184742915995150"
},
{
"input": "810411",
"output": "532248411551110590"
},
{
"input": "836603",
"output": "585540171302562606"
},
{
"input": "978187",
"output": "935975171582120670"
},
{
"input": "816923",
"output": "545182335484592526"
},
{
"input": "958507",
"output": "880611813728059710"
},
{
"input": "984699",
"output": "954792870629291694"
},
{
"input": "642635",
"output": "265393998349453470"
},
{
"input": "296604",
"output": "26092892528622606"
},
{
"input": "1000000",
"output": "999996000003000000"
},
{
"input": "8",
"output": "280"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "12"
},
{
"input": "30",
"output": "21924"
},
{
"input": "18",
"output": "4080"
},
{
"input": "12",
"output": "990"
}
] | 1,555,527,880 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 218 | 0 | import math
def main():
n = int(input())
if n <= 3:
ans = 1
for i in range(1,n+1):
ans *= i
print(ans)
return
if n%2 == 0:
#print(n,n-1,n-3)
if n%3 == 0:
print((n-3)*(n-1)*(n-2))
else:
print(n*(n-1)*(n-3))
else:
print(n*(n-1)*(n-2))
main()
| Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement.
Output Specification:
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
Demo Input:
['9\n', '7\n']
Demo Output:
['504\n', '210\n']
Note:
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get. | ```python
import math
def main():
n = int(input())
if n <= 3:
ans = 1
for i in range(1,n+1):
ans *= i
print(ans)
return
if n%2 == 0:
#print(n,n-1,n-3)
if n%3 == 0:
print((n-3)*(n-1)*(n-2))
else:
print(n*(n-1)*(n-3))
else:
print(n*(n-1)*(n-2))
main()
``` | 3 |
|
490 | B | Queue | PROGRAMMING | 1,500 | [
"dsu",
"implementation"
] | null | null | During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).
After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.
Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue. | The first line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of students in the queue.
Then *n* lines follow, *i*-th line contains the pair of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=106), where *a**i* is the ID number of a person in front of a student and *b**i* is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.
The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order. | Print a sequence of *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | [
"4\n92 31\n0 7\n31 0\n7 141\n"
] | [
"92 7 31 141 \n"
] | The picture illustrates the queue for the first sample. | 1,000 | [
{
"input": "4\n92 31\n0 7\n31 0\n7 141",
"output": "92 7 31 141 "
},
{
"input": "2\n0 1\n2 0",
"output": "2 1 "
},
{
"input": "3\n0 2\n1 3\n2 0",
"output": "1 2 3 "
},
{
"input": "4\n101 0\n0 102\n102 100\n103 101",
"output": "103 102 101 100 "
},
{
"input": "5\n0 1\n1 4\n4 0\n3 2\n5 3",
"output": "5 1 3 4 2 "
},
{
"input": "6\n10001 0\n0 10005\n10003 10001\n10002 10000\n10005 10002\n10004 10003",
"output": "10004 10005 10003 10002 10001 10000 "
},
{
"input": "3\n0 743259\n72866 70294\n743259 0",
"output": "72866 743259 70294 "
},
{
"input": "4\n263750 0\n513707 263750\n0 718595\n718595 148112",
"output": "513707 718595 263750 148112 "
},
{
"input": "5\n645873 145459\n638930 82975\n0 645873\n82975 389665\n145459 0",
"output": "638930 645873 82975 145459 389665 "
},
{
"input": "6\n341637 51795\n0 809471\n51795 0\n244669 341637\n852537 508622\n809471 852537",
"output": "244669 809471 341637 852537 51795 508622 "
},
{
"input": "7\n111283 0\n496010 510417\n423431 921854\n510417 111283\n0 496010\n758535 423431\n921854 59208",
"output": "758535 496010 423431 510417 921854 111283 59208 "
},
{
"input": "8\n611412 115521\n114290 712424\n115521 242491\n242491 0\n0 114290\n712424 282922\n282922 589147\n359823 611412",
"output": "359823 114290 611412 712424 115521 282922 242491 589147 "
},
{
"input": "9\n308992 348750\n0 6496\n487447 676506\n874677 985199\n260782 487447\n985199 260782\n348750 0\n570981 308992\n6496 570981",
"output": "874677 6496 985199 570981 260782 308992 487447 348750 676506 "
},
{
"input": "10\n419946 201769\n245945 0\n842799 113073\n836998 245945\n0 794376\n692107 836998\n113073 904403\n904403 987165\n201769 692107\n794376 842799",
"output": "419946 794376 201769 842799 692107 113073 836998 904403 245945 987165 "
},
{
"input": "10\n189071 852255\n227133 652124\n329720 4848\n652124 329720\n0 72517\n943168 0\n72517 544697\n4848 943168\n538963 189071\n544697 538963",
"output": "227133 72517 652124 544697 329720 538963 4848 189071 943168 852255 "
},
{
"input": "2\n0 300000\n1000000 0",
"output": "1000000 300000 "
}
] | 1,667,463,605 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | def get_int():
return int(input())
def main():
n = get_int()
array = [0]*n
right_hashmap = {}
left_hashmap = {}
nums = set()
for _ in range(n):
left, right = list(map(int, input().split()))
if left == 0:
array[1] = right
continue
if right == 0:
array[n - 2] = left
continue
right_hashmap[left] = right
left_hashmap[right] = left
nums.add(left)
nums.add(right)
nums = list(nums)
for index in range(len(nums)):
left = index - 2
right = index + 2
id = array[index]
if id == 0:
continue
if left >= 0 and array[left] == 0:
array[left] = left_hashmap[id]
if right < n and array[right] == 0:
array[right] = right_hashmap[id]
print(*array)
main()
| Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).
After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.
Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of students in the queue.
Then *n* lines follow, *i*-th line contains the pair of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=106), where *a**i* is the ID number of a person in front of a student and *b**i* is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.
The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.
Output Specification:
Print a sequence of *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.
Demo Input:
['4\n92 31\n0 7\n31 0\n7 141\n']
Demo Output:
['92 7 31 141 \n']
Note:
The picture illustrates the queue for the first sample. | ```python
def get_int():
return int(input())
def main():
n = get_int()
array = [0]*n
right_hashmap = {}
left_hashmap = {}
nums = set()
for _ in range(n):
left, right = list(map(int, input().split()))
if left == 0:
array[1] = right
continue
if right == 0:
array[n - 2] = left
continue
right_hashmap[left] = right
left_hashmap[right] = left
nums.add(left)
nums.add(right)
nums = list(nums)
for index in range(len(nums)):
left = index - 2
right = index + 2
id = array[index]
if id == 0:
continue
if left >= 0 and array[left] == 0:
array[left] = left_hashmap[id]
if right < n and array[right] == 0:
array[right] = right_hashmap[id]
print(*array)
main()
``` | 0 |
|
910 | C | Minimum Sum | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Petya has *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.
Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of Petya's numbers.
Each of the following lines contains non-empty string *s**i* consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters. | Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests. | [
"3\nab\nde\naj\n",
"5\nabcdef\nghij\nbdef\naccbd\ng\n",
"3\naa\njj\naa\n"
] | [
"47\n",
"136542\n",
"44\n"
] | In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.
In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3].
In the second example the numbers after the restoration can look like: [11, 22, 11]. | 1,500 | [
{
"input": "3\nab\nde\naj",
"output": "47"
},
{
"input": "5\nabcdef\nghij\nbdef\naccbd\ng",
"output": "136542"
},
{
"input": "3\naa\njj\naa",
"output": "44"
},
{
"input": "9\na\nb\nc\nd\nf\ng\nh\ni\nj",
"output": "45"
},
{
"input": "5\nbdgbh\nadi\naa\ngjh\ngh",
"output": "10824"
},
{
"input": "6\nchafj\nabhj\nfhe\nhfbd\njifgg\ng",
"output": "42773"
},
{
"input": "1\nh",
"output": "1"
},
{
"input": "7\nffh\nfhec\nfbchc\ng\ndfbhi\ncdbdi\ni",
"output": "64995"
},
{
"input": "8\ne\nbhbib\nj\ndgb\njjbgb\nei\ndggbdh\nhfbbfj",
"output": "429631"
},
{
"input": "10\ncf\ncha\nceiab\ng\naajac\ndj\nhe\ni\nhjfg\nhdcgcb",
"output": "198795"
},
{
"input": "50\ng\nha\nhd\ndi\nac\nfdhhb\ng\nhgeag\nafafb\nb\nb\najjj\ncaiadi\nhciifa\nhb\ncaih\ncdbbi\ngjff\nbfe\neddci\ndijfie\nacjj\nef\ng\njdc\nahg\ne\nhbbh\ncdc\njifdc\ne\nffaehj\nhjhi\ng\neag\nfbbc\nchg\njhahfg\nbb\njd\njchh\nbefifj\nejac\ne\nh\njfhb\nedhe\nf\nag\nca",
"output": "2673136"
},
{
"input": "31\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\nbc",
"output": "50"
},
{
"input": "9\nb\nc\nd\ne\nf\ng\nh\ni\nj",
"output": "45"
},
{
"input": "8\nb\nc\nd\nf\ng\nh\ni\nj",
"output": "36"
},
{
"input": "8\nb\nce\necc\nf\ng\nh\ni\nj",
"output": "176"
},
{
"input": "2\nababa\nbabaa",
"output": "33332"
},
{
"input": "3\nabcbbc\nababab\nbcbbaa",
"output": "443643"
},
{
"input": "3\nbb\nj\nc",
"output": "16"
},
{
"input": "3\nj\ng\ng",
"output": "4"
},
{
"input": "3\nbef\ncjff\nhi",
"output": "1332"
},
{
"input": "3\nfi\nfej\nei",
"output": "153"
},
{
"input": "4\nc\nb\nhh\ng",
"output": "20"
},
{
"input": "4\nfjj\nba\nbc\neie",
"output": "412"
},
{
"input": "4\nh\nchf\ngj\ndifd",
"output": "1334"
},
{
"input": "4\ng\njicdh\nj\nfh",
"output": "10287"
},
{
"input": "5\nfj\nbj\nja\nfd\ni",
"output": "83"
},
{
"input": "5\ngij\nf\nj\nfd\niij",
"output": "365"
},
{
"input": "5\nfhdh\ndaih\nff\nca\ncc",
"output": "3468"
},
{
"input": "5\ni\ncghf\nh\ng\nbc",
"output": "1281"
},
{
"input": "6\nb\ngc\na\nhj\nfg\nb",
"output": "80"
},
{
"input": "6\nfj\ngd\nch\ni\ng\nh",
"output": "80"
},
{
"input": "6\nedi\nfa\nad\nh\ngjf\njaa",
"output": "766"
},
{
"input": "6\njafef\nihbb\njc\njc\ng\nfihji",
"output": "37101"
},
{
"input": "7\nhg\ng\nag\nj\ng\na\nfe",
"output": "82"
},
{
"input": "7\ncb\nfi\ndia\nada\nag\ng\nba",
"output": "468"
},
{
"input": "7\nba\nac\nag\nfcj\ng\naa\ncgb",
"output": "510"
},
{
"input": "7\niaiac\nc\naicic\nhfbfc\nggje\necgg\nhd",
"output": "74622"
},
{
"input": "8\ngc\nf\nca\neh\nc\ni\nae\ng",
"output": "122"
},
{
"input": "8\nc\nc\nh\nefe\nd\ne\nhjc\ngae",
"output": "720"
},
{
"input": "8\nfhij\nbc\na\ngeh\nee\naeac\najb\njj",
"output": "4136"
},
{
"input": "8\njaei\naidd\nciai\nfefdf\ngfahh\nh\nh\njagjg",
"output": "78727"
},
{
"input": "9\ni\nh\ne\na\nb\nh\ni\nea\ni",
"output": "36"
},
{
"input": "9\nhd\nca\nc\ncii\nii\nd\ne\nf\ngde",
"output": "494"
},
{
"input": "9\njbc\nc\nfae\nce\nfgi\nigfg\nfeh\nied\nfe",
"output": "2340"
},
{
"input": "9\nehdc\ng\ngdgj\naacg\nfgg\njhb\ng\nie\ndabfa",
"output": "23429"
},
{
"input": "10\nc\naj\neh\nhc\nib\nd\nfc\nf\nfh\nc",
"output": "204"
},
{
"input": "10\nji\nid\ni\na\nhhb\ndi\njd\ngdi\na\na",
"output": "544"
},
{
"input": "10\necj\ni\nbadj\neai\naie\nfgj\nah\ngdaj\nai\nhdhd",
"output": "8803"
},
{
"input": "10\nad\ngbha\nabh\ngbgc\nfa\njfde\neb\na\nfg\ndd",
"output": "5084"
},
{
"input": "3\na\nb\nc",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\na\na",
"output": "2"
}
] | 1,514,829,312 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 5,632,000 | import sys
cases=int(input())
s=['' for i in range(6)]
heads=[]
zero=True
nums=[i for i in range(1,10)]
letters=[ 0 for i in range(10)]
words=[]
f=''
for i in range(cases):
a=(input())
f=f+a
words.append(str(a))
heads.append(a[0])
for j in range(len(a)):
s[5-j]=s[5-j]+a[len(a)-j-1]
rep=[0 for i in range(10)]
for i in range(6):
for k in range(10):
rep[k]=rep[k]+s[i].count(chr(k+97))
rep1=rep.copy()
rep1.sort()
for j in range(10):
if (rep1[9-j]>0 and rep.count(rep1[9-1])) ==1:
if chr(rep.index(rep1[9-j])+97) in heads :
letters[rep.index(rep1[9-j])]=nums[0]
nums.remove(nums[0])
elif zero==True:
letters[rep.index(rep1[9-j])]=0
zero=False
else:
letters[rep.index(rep1[9-j])]=nums[0]
nums.remove(nums[0])
f=f.replace(chr(rep.index(rep1[9-j])+97) ,'')
rep[rep.index(rep1[9-j])]=-900000
else:
break
while(len(f)>0):
if zero==False:
rep1=rep.copy()
rep1.sort()
letters[rep.index(rep1[9-j])]=nums[0]
nums.remove(nums[0])
f=f.replace(chr(rep.index(rep1[9-j])+97) ,'')
rep[rep.index(rep1[9-j])]=-900000
else:
rep1=rep.copy()
rep1.sort()
letters[rep.index(rep1[9-j])]=0
f=f.replace(chr(rep.index(rep1[9-j])+97) ,'')
rep[rep.index(rep1[9-j])]=-900000
zero=False
total=0
for i in range(cases):
for j in range(10):
words[i]=words[i].replace(chr(j+97),str(letters[j]))
total=total+int(words[i])
print(total)
| Title: Minimum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.
Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of Petya's numbers.
Each of the following lines contains non-empty string *s**i* consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.
Output Specification:
Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.
Demo Input:
['3\nab\nde\naj\n', '5\nabcdef\nghij\nbdef\naccbd\ng\n', '3\naa\njj\naa\n']
Demo Output:
['47\n', '136542\n', '44\n']
Note:
In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.
In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3].
In the second example the numbers after the restoration can look like: [11, 22, 11]. | ```python
import sys
cases=int(input())
s=['' for i in range(6)]
heads=[]
zero=True
nums=[i for i in range(1,10)]
letters=[ 0 for i in range(10)]
words=[]
f=''
for i in range(cases):
a=(input())
f=f+a
words.append(str(a))
heads.append(a[0])
for j in range(len(a)):
s[5-j]=s[5-j]+a[len(a)-j-1]
rep=[0 for i in range(10)]
for i in range(6):
for k in range(10):
rep[k]=rep[k]+s[i].count(chr(k+97))
rep1=rep.copy()
rep1.sort()
for j in range(10):
if (rep1[9-j]>0 and rep.count(rep1[9-1])) ==1:
if chr(rep.index(rep1[9-j])+97) in heads :
letters[rep.index(rep1[9-j])]=nums[0]
nums.remove(nums[0])
elif zero==True:
letters[rep.index(rep1[9-j])]=0
zero=False
else:
letters[rep.index(rep1[9-j])]=nums[0]
nums.remove(nums[0])
f=f.replace(chr(rep.index(rep1[9-j])+97) ,'')
rep[rep.index(rep1[9-j])]=-900000
else:
break
while(len(f)>0):
if zero==False:
rep1=rep.copy()
rep1.sort()
letters[rep.index(rep1[9-j])]=nums[0]
nums.remove(nums[0])
f=f.replace(chr(rep.index(rep1[9-j])+97) ,'')
rep[rep.index(rep1[9-j])]=-900000
else:
rep1=rep.copy()
rep1.sort()
letters[rep.index(rep1[9-j])]=0
f=f.replace(chr(rep.index(rep1[9-j])+97) ,'')
rep[rep.index(rep1[9-j])]=-900000
zero=False
total=0
for i in range(cases):
for j in range(10):
words[i]=words[i].replace(chr(j+97),str(letters[j]))
total=total+int(words[i])
print(total)
``` | 0 |
|
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes. | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions. | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 57 78\n66 60 45"
},
{
"input": "0 17 14\n15 0 15\n16 13 0",
"output": "14 17 14\n15 15 15\n16 13 16"
},
{
"input": "0 97 56\n69 0 71\n84 43 0",
"output": "57 97 56\n69 70 71\n84 43 83"
},
{
"input": "0 1099 1002\n1027 0 1049\n1074 977 0",
"output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063"
},
{
"input": "0 98721 99776\n99575 0 99123\n98922 99977 0",
"output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148"
},
{
"input": "0 6361 2304\n1433 0 8103\n7232 3175 0",
"output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897"
},
{
"input": "0 99626 99582\n99766 0 99258\n99442 99398 0",
"output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696"
},
{
"input": "0 99978 99920\n99950 0 99918\n99948 99890 0",
"output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964"
},
{
"input": "0 840 666\n612 0 948\n894 720 0",
"output": "834 840 666\n612 780 948\n894 720 726"
},
{
"input": "0 28 10\n12 0 24\n26 8 0",
"output": "16 28 10\n12 18 24\n26 8 20"
},
{
"input": "0 120 83\n98 0 90\n105 68 0",
"output": "79 120 83\n98 94 90\n105 68 109"
},
{
"input": "0 86900 85807\n85836 0 86842\n86871 85778 0",
"output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368"
},
{
"input": "0 74 78\n78 0 74\n74 78 0",
"output": "76 74 78\n78 76 74\n74 78 76"
},
{
"input": "0 505 681\n605 0 657\n581 757 0",
"output": "707 505 681\n605 631 657\n581 757 555"
},
{
"input": "0 662 918\n822 0 854\n758 1014 0",
"output": "934 662 918\n822 838 854\n758 1014 742"
},
{
"input": "0 93 95\n93 0 97\n95 97 0",
"output": "97 93 95\n93 95 97\n95 97 93"
},
{
"input": "0 709 712\n719 0 695\n702 705 0",
"output": "700 709 712\n719 707 695\n702 705 714"
},
{
"input": "0 7 6\n9 0 1\n4 3 0",
"output": "2 7 6\n9 5 1\n4 3 8"
},
{
"input": "0 9 2\n3 0 7\n8 1 0",
"output": "4 9 2\n3 5 7\n8 1 6"
},
{
"input": "0 1 43\n13 0 61\n31 73 0",
"output": "67 1 43\n13 37 61\n31 73 7"
},
{
"input": "0 100000 100000\n100000 0 100000\n100000 100000 0",
"output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"
}
] | 1,597,740,634 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 278 | 0 | M=[]
for i in range(3):
L=list(map(int,input().split()))
M.append(L)
x2=M[0][2]
x3=M[1][0]
x5=M[2][0]
x6=M[2][1]
M[0][0]=(x2+x5+x6-x3)//2
M[1][1]=(x2+x5)//2
M[2][2]=(x2+x5+x3-x6)//2
for i in range(3):
for j in range(3):
print(M[i][j],end=" ")
print("")
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes.
Input Specification:
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Output Specification:
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions.
Demo Input:
['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n']
Demo Output:
['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n']
Note:
none | ```python
M=[]
for i in range(3):
L=list(map(int,input().split()))
M.append(L)
x2=M[0][2]
x3=M[1][0]
x5=M[2][0]
x6=M[2][1]
M[0][0]=(x2+x5+x6-x3)//2
M[1][1]=(x2+x5)//2
M[2][2]=(x2+x5+x3-x6)//2
for i in range(3):
for j in range(3):
print(M[i][j],end=" ")
print("")
``` | 3 |
|
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B. | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "A>C\nA>B\nB<C",
"output": "BCA"
},
{
"input": "C<B\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nA>B\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nA<C",
"output": "ABC"
},
{
"input": "C<B\nB<A\nC>A",
"output": "Impossible"
},
{
"input": "B<C\nC<A\nA>B",
"output": "BCA"
},
{
"input": "A>B\nC<B\nC<A",
"output": "CBA"
},
{
"input": "B>A\nC>B\nA>C",
"output": "Impossible"
},
{
"input": "B<A\nC>B\nC>A",
"output": "BAC"
},
{
"input": "A<B\nC>B\nA<C",
"output": "ABC"
},
{
"input": "A<B\nC<A\nB<C",
"output": "Impossible"
},
{
"input": "A>C\nC<B\nB>A",
"output": "CAB"
},
{
"input": "C>A\nA<B\nB>C",
"output": "ACB"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "B>C\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA<B\nB>C",
"output": "ACB"
},
{
"input": "B>A\nA>C\nB>C",
"output": "CAB"
},
{
"input": "B<A\nA<C\nC<B",
"output": "Impossible"
},
{
"input": "A<C\nB>C\nA>B",
"output": "Impossible"
},
{
"input": "B>A\nC<A\nC>B",
"output": "Impossible"
},
{
"input": "A>C\nC>B\nB<A",
"output": "BCA"
},
{
"input": "B<C\nB<A\nA>C",
"output": "BCA"
},
{
"input": "A>B\nC>B\nA<C",
"output": "BAC"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA>B\nB>C",
"output": "Impossible"
},
{
"input": "B>A\nB>C\nA<C",
"output": "ACB"
},
{
"input": "B>C\nC<A\nB<A",
"output": "CBA"
},
{
"input": "C>A\nB>A\nB>C",
"output": "ACB"
},
{
"input": "B<A\nB>C\nA<C",
"output": "Impossible"
},
{
"input": "B<C\nA<B\nC>A",
"output": "ABC"
},
{
"input": "C<B\nB>A\nA>C",
"output": "CAB"
},
{
"input": "A>B\nC>A\nB<C",
"output": "BAC"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "B>C\nC>A\nA>B",
"output": "Impossible"
},
{
"input": "B<A\nB>C\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nC>A",
"output": "ABC"
},
{
"input": "A>C\nA>B\nB>C",
"output": "CBA"
},
{
"input": "B<C\nA>B\nA<C",
"output": "BAC"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "C>B\nA<B\nC<A",
"output": "Impossible"
},
{
"input": "A<C\nC<B\nA>B",
"output": "Impossible"
},
{
"input": "B>C\nA<B\nA<C",
"output": "ACB"
},
{
"input": "C>A\nA<B\nC>B",
"output": "ABC"
}
] | 1,623,059,768 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | from operator import itemgetter
import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (int, sys.stdin.readline ().strip ().split ()))
#code starts here
s = get_string ()
ss = get_string ()
sss = get_string ()
if s [1] == '<':
s = s [2] + '>' + s [0]
if ss [1] == '<':
ss = ss [2] + '>' + ss [0]
if sss [1] == '<':
sss = sss [2] + '>' + sss [0]
ar = [s, ss, sss]
count_A = [0, 'A']
count_B = [0, 'B']
count_C = [0, 'C']
for i in ar:
if i [0] == 'A':
count_A [0] += 1
if i [0] == 'B':
count_B [0] += 1
if i [0] == 'C':
count_C [0] += 1
ans = sorted ([count_A, count_B, count_C], key=itemgetter (0))
string = ''
for i in ans:
string += i [1]
print (string)
| Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
Input Specification:
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.
Output Specification:
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
Demo Input:
['A>B\nC<B\nA>C\n', 'A<B\nB>C\nC>A\n']
Demo Output:
['CBA', 'ACB']
Note:
none | ```python
from operator import itemgetter
import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (int, sys.stdin.readline ().strip ().split ()))
#code starts here
s = get_string ()
ss = get_string ()
sss = get_string ()
if s [1] == '<':
s = s [2] + '>' + s [0]
if ss [1] == '<':
ss = ss [2] + '>' + ss [0]
if sss [1] == '<':
sss = sss [2] + '>' + sss [0]
ar = [s, ss, sss]
count_A = [0, 'A']
count_B = [0, 'B']
count_C = [0, 'C']
for i in ar:
if i [0] == 'A':
count_A [0] += 1
if i [0] == 'B':
count_B [0] += 1
if i [0] == 'C':
count_C [0] += 1
ans = sorted ([count_A, count_B, count_C], key=itemgetter (0))
string = ''
for i in ans:
string += i [1]
print (string)
``` | 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,600,056,403 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | def reverse(s):
str1 = ""
for i in s:
str1 = i + str1
return str1
s1=str(input())
s2=str(input())
rev=""
rev=reverse(s1)
if s2==rev:
print("YES")
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
def reverse(s):
str1 = ""
for i in s:
str1 = i + str1
return str1
s1=str(input())
s2=str(input())
rev=""
rev=reverse(s1)
if s2==rev:
print("YES")
else:
print("NO")
``` | 3.9455 |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,692,374,863 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | import math
n = int(input())
print(('ROYGBIV'*math.ceil(n/2))[:n]) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
import math
n = int(input())
print(('ROYGBIV'*math.ceil(n/2))[:n])
``` | 0 |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "60000",
"output": "0\n30000 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59991",
"output": "0\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59989",
"output": "1\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "6",
"output": "1\n3 1 4 5 "
},
{
"input": "7",
"output": "0\n3\n1 6 7 "
},
{
"input": "8",
"output": "0\n4 1 4 5 8 "
},
{
"input": "9",
"output": "1\n5\n1 2 3 8 9 "
},
{
"input": "10",
"output": "1\n5 1 4 5 8 9 "
},
{
"input": "11",
"output": "0\n5\n1 2 9 10 11 "
},
{
"input": "12",
"output": "0\n6 1 4 5 8 9 12 "
},
{
"input": "13",
"output": "1\n7\n1 2 3 4 11 12 13 "
},
{
"input": "14",
"output": "1\n7 1 4 5 8 9 12 13 "
},
{
"input": "15",
"output": "0\n7\n1 2 3 12 13 14 15 "
},
{
"input": "16",
"output": "0\n8 1 4 5 8 9 12 13 16 "
},
{
"input": "17",
"output": "1\n9\n1 2 3 4 5 14 15 16 17 "
},
{
"input": "18",
"output": "1\n9 1 4 5 8 9 12 13 16 17 "
},
{
"input": "19",
"output": "0\n9\n1 2 3 4 15 16 17 18 19 "
},
{
"input": "20",
"output": "0\n10 1 4 5 8 9 12 13 16 17 20 "
},
{
"input": "21",
"output": "1\n11\n1 2 3 4 5 6 17 18 19 20 21 "
},
{
"input": "22",
"output": "1\n11 1 4 5 8 9 12 13 16 17 20 21 "
},
{
"input": "23",
"output": "0\n11\n1 2 3 4 5 18 19 20 21 22 23 "
},
{
"input": "24",
"output": "0\n12 1 4 5 8 9 12 13 16 17 20 21 24 "
},
{
"input": "59999",
"output": "0\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59997",
"output": "1\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59996",
"output": "0\n29998 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59995",
"output": "0\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59994",
"output": "1\n29997 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59993",
"output": "1\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "59992",
"output": "0\n29996 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59990",
"output": "1\n29995 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "100",
"output": "0\n50 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 "
},
{
"input": "1000",
"output": "0\n500 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..."
},
{
"input": "10001",
"output": "1\n5001\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "103",
"output": "0\n51\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 "
},
{
"input": "1002",
"output": "1\n501 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..."
},
{
"input": "31724",
"output": "0\n15862 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "2032",
"output": "0\n1016 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "42620",
"output": "0\n21310 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "18076",
"output": "0\n9038 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "53520",
"output": "0\n26760 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "37193",
"output": "1\n18597\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "12645",
"output": "1\n6323\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "53237",
"output": "1\n26619\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "28693",
"output": "1\n14347\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "4145",
"output": "1\n2073\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "36042",
"output": "1\n18021 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "16646",
"output": "1\n8323 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "57238",
"output": "1\n28619 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "27542",
"output": "1\n13771 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "8146",
"output": "1\n4073 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "46659",
"output": "0\n23329\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "27259",
"output": "0\n13629\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "2715",
"output": "0\n1357\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
},
{
"input": "38159",
"output": "0\n19079\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..."
},
{
"input": "18759",
"output": "0\n9379\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..."
}
] | 1,663,714,344 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 92 | 5,017,600 | def generate_list_124(s, n):
lst = []
for i in range(s, int(n/2) + 1, 2):
lst.append(i)
lst.append(n-i+s)
return lst
def generate_list_3(s, n):
lst = []
for i in range(s, int(n/2) - 1, 2):
lst.append(i)
lst.append(n-i+s)
lst.append(int(n/2))
return lst
n = int(input())
mod = n % 4
if(mod == 0):
print(0)
print(int(n / 2), end=' ')
print(*generate_list_124(1, n), sep=' ')
elif(mod == 1):
print(1)
print(int(n / 2), end=' ')
print(*generate_list_124(2, n), sep=' ')
elif(mod == 2):
print(1)
print(int(n / 2), end=' ')
print(*generate_list_3(1, n), sep=' ')
else:
print(0)
print(int(n / 2) + 1, end=' ')
print(*generate_list_124(1, n-1), sep=' ') | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Output Specification:
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Demo Input:
['4\n', '2\n']
Demo Output:
['0\n2 1 4 \n', '1\n1 1 \n']
Note:
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | ```python
def generate_list_124(s, n):
lst = []
for i in range(s, int(n/2) + 1, 2):
lst.append(i)
lst.append(n-i+s)
return lst
def generate_list_3(s, n):
lst = []
for i in range(s, int(n/2) - 1, 2):
lst.append(i)
lst.append(n-i+s)
lst.append(int(n/2))
return lst
n = int(input())
mod = n % 4
if(mod == 0):
print(0)
print(int(n / 2), end=' ')
print(*generate_list_124(1, n), sep=' ')
elif(mod == 1):
print(1)
print(int(n / 2), end=' ')
print(*generate_list_124(2, n), sep=' ')
elif(mod == 2):
print(1)
print(int(n / 2), end=' ')
print(*generate_list_3(1, n), sep=' ')
else:
print(0)
print(int(n / 2) + 1, end=' ')
print(*generate_list_124(1, n-1), sep=' ')
``` | 3 |
|
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard. | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard. | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB",
"output": "YES"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWWWBWBW",
"output": "NO"
},
{
"input": "BBBBBWWW\nWBBWBWWB\nWWWWWBWW\nBWBWWBWW\nBBBWWBWW\nBBBBBWBW\nWBBBWBWB\nWBWBWWWB",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBWWWWWBB\nBBWBWBWB\nWBWBWBWB\nWWBWWBWW\nBWBWBWBW\nWBWWBBBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWWBWBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW",
"output": "YES"
},
{
"input": "WWWWBWWB\nBWBWBWBW\nBWBWBWBW\nWWBWBBBB\nBBWWBBBB\nBBBWWBBW\nBWWWWWWB\nBWWBBBWW",
"output": "NO"
},
{
"input": "WBBWWBWB\nBBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBBW\nWBWBBBBW\nBWWWWBWB\nBBBBBBBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBBWWWBBB\nWBBBBBWW\nWBBBBWBB\nWBWBWBWB\nWBWWBWWB\nWBBWBBWW",
"output": "NO"
},
{
"input": "WBBBBBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBBBBBWBB\nWBBWWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBBWWBWB",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWWWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBBW",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "WWBBWWBB\nBWWBBWWB\nBWBWBWBW\nWWBBWWWB\nWBWWWWBB\nWBWWBBWB\nBWBBWBWW\nBWBWWWWW",
"output": "NO"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nWWBBWBBB\nWBWBWBWB\nWWWWBWWB\nWBBBBWWW\nBWBWWWBW\nWWWBWBBB",
"output": "NO"
},
{
"input": "WBWBWBWB\nBWWBWWWW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nWWBBBBBW\nWWWBWWBW\nWWBBBBWW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBBBWWB\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "YES"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "NO"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "NO"
},
{
"input": "BWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB\nBWBWBWBB",
"output": "NO"
},
{
"input": "WWBWWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW",
"output": "NO"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB\nWWWWWWWW\nBBBBBBBB",
"output": "NO"
},
{
"input": "BBBBBBBB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "NO"
},
{
"input": "BBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW\nBBBBBBBW",
"output": "NO"
},
{
"input": "BBBWWWWW\nWWWBBBBB\nBBBWWWWW\nWWWBBBBB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "NO"
}
] | 1,578,061,408 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 310 | 0 | ans = True
for i in range(8):
s = input()
for i in range(7):
if s[i] == s[i+1]:
ans = False
if ans:
print("YES")
else:
print("NO")
| Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input Specification:
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output Specification:
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Demo Input:
['WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n', 'WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | ```python
ans = True
for i in range(8):
s = input()
for i in range(7):
if s[i] == s[i+1]:
ans = False
if ans:
print("YES")
else:
print("NO")
``` | 3 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,526,377,887 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 156 | 7,065,600 | import sys
n = int(input())
numbers = list(map(int, input().split()))
length = len(numbers)
even = []
for number in numbers:
if(number % 2 == 0):
even.append(True)
else:
even.append(False)
mask = sum(even)
if(mask == length - 1):
answer = even.index(0)
else:
answer = even.index(1)
print(answer + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
import sys
n = int(input())
numbers = list(map(int, input().split()))
length = len(numbers)
even = []
for number in numbers:
if(number % 2 == 0):
even.append(True)
else:
even.append(False)
mask = sum(even)
if(mask == length - 1):
answer = even.index(0)
else:
answer = even.index(1)
print(answer + 1)
``` | 3.947839 |
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff. | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing. | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
"input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7",
"output": "23 8"
},
{
"input": "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22",
"output": "6 47"
},
{
"input": "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37",
"output": "23 58"
},
{
"input": "66 20\n0 16\n0 45\n0 58\n1 6\n1 19\n2 7\n2 9\n3 9\n3 25\n3 57\n4 38\n4 58\n5 21\n5 40\n6 16\n6 19\n6 58\n7 6\n7 26\n7 51\n8 13\n8 36\n8 55\n9 1\n9 15\n9 33\n10 12\n10 37\n11 15\n11 34\n12 8\n12 37\n12 55\n13 26\n14 0\n14 34\n14 36\n14 48\n15 23\n15 29\n15 43\n16 8\n16 41\n16 45\n17 5\n17 7\n17 15\n17 29\n17 46\n18 12\n18 19\n18 38\n18 57\n19 32\n19 58\n20 5\n20 40\n20 44\n20 50\n21 18\n21 49\n22 18\n22 47\n23 1\n23 38\n23 50",
"output": "1 40"
},
{
"input": "1 1\n0 0",
"output": "0 2"
},
{
"input": "10 1\n0 2\n0 4\n0 5\n0 8\n0 9\n0 11\n0 13\n0 16\n0 19\n0 21",
"output": "0 0"
},
{
"input": "10 1\n0 2\n0 5\n0 8\n0 11\n0 15\n0 17\n0 25\n0 28\n0 29\n0 32",
"output": "0 0"
},
{
"input": "15 20\n0 47\n2 24\n4 19\n4 34\n5 46\n8 15\n9 8\n10 28\n17 47\n17 52\n18 32\n19 50\n20 46\n20 50\n23 21",
"output": "0 0"
},
{
"input": "1 5\n1 0",
"output": "0 0"
},
{
"input": "24 60\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59",
"output": "25 0"
},
{
"input": "1 30\n0 29",
"output": "1 0"
},
{
"input": "1 2\n3 0",
"output": "0 0"
},
{
"input": "16 60\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "25 0"
},
{
"input": "1 5\n0 6",
"output": "0 0"
},
{
"input": "2 60\n0 59\n23 59",
"output": "2 0"
},
{
"input": "1 58\n0 1",
"output": "1 0"
},
{
"input": "25 60\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59",
"output": "25 0"
},
{
"input": "2 3\n0 3\n0 30",
"output": "0 7"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 9",
"output": "24 0"
},
{
"input": "1 60\n2 0",
"output": "0 0"
},
{
"input": "2 60\n0 0\n5 0",
"output": "1 1"
},
{
"input": "1 30\n0 31",
"output": "0 0"
},
{
"input": "2 60\n0 59\n3 1",
"output": "2 0"
},
{
"input": "2 60\n0 59\n5 0",
"output": "2 0"
},
{
"input": "1 59\n0 0",
"output": "1 0"
},
{
"input": "3 25\n0 0\n1 0\n2 0",
"output": "0 26"
},
{
"input": "1 2\n2 3",
"output": "0 0"
}
] | 1,617,343,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | I=lambda:map(int,input().split())
n,s=I()
l=[0]
for i in range(n):
q,w=I()
q=q*60+w
l+=[q]
if l[1]-l[0]>s+1:exit(print(0, 0))
for i in range(n):
if l[i+1]-l[i]>2*s+1:
l[i]+=s+1
exit(print(l[i]//60,l[i]%60))
l[-1]+=s+1
print(l[-1]//60,l[-1]%60) | Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
Input Specification:
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.
Output Specification:
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
Demo Input:
['6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n', '16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n', '3 17\n0 30\n1 0\n12 0\n']
Demo Output:
['6 1\n', '24 50\n', '0 0\n']
Note:
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing. | ```python
I=lambda:map(int,input().split())
n,s=I()
l=[0]
for i in range(n):
q,w=I()
q=q*60+w
l+=[q]
if l[1]-l[0]>s+1:exit(print(0, 0))
for i in range(n):
if l[i+1]-l[i]>2*s+1:
l[i]+=s+1
exit(print(l[i]//60,l[i]%60))
l[-1]+=s+1
print(l[-1]//60,l[-1]%60)
``` | 0 |
|
618 | D | Hamiltonian Spanning Tree | PROGRAMMING | 2,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"trees"
] | null | null | A group of *n* cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly *y* seconds to traverse any single road.
A spanning tree is a set of roads containing exactly *n*<=-<=1 roads such that it's possible to travel between any two cities using only these roads.
Some spanning tree of the initial network was chosen. For every road in this tree the time one needs to traverse this road was changed from *y* to *x* seconds. Note that it's not guaranteed that *x* is smaller than *y*.
You would like to travel through all the cities using the shortest path possible. Given *n*, *x*, *y* and a description of the spanning tree that was chosen, find the cost of the shortest path that starts in any city, ends in any city and visits all cities exactly once. | The first line of the input contains three integers *n*, *x* and *y* (2<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*x*,<=*y*<=≤<=109).
Each of the next *n*<=-<=1 lines contains a description of a road in the spanning tree. The *i*-th of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) — indices of the cities connected by the *i*-th road. It is guaranteed that these roads form a spanning tree. | Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once. | [
"5 2 3\n1 2\n1 3\n3 4\n5 3\n",
"5 3 2\n1 2\n1 3\n3 4\n5 3\n"
] | [
"9\n",
"8\n"
] | In the first sample, roads of the spanning tree have cost 2, while other roads have cost 3. One example of an optimal path is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3a11f64ac0349d4ecd3a2b4c3443aeb7ac3b28b9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample, we have the same spanning tree, but roads in the spanning tree cost 3, while other roads cost 2. One example of an optimal path is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3fdb844c44665567f5addf82820eb6f96a060920.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,750 | [
{
"input": "5 2 3\n1 2\n1 3\n3 4\n5 3",
"output": "9"
},
{
"input": "5 3 2\n1 2\n1 3\n3 4\n5 3",
"output": "8"
},
{
"input": "50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n32 3\n44 41\n50 31\n50 34\n5 14\n36 13\n22 40\n20 9\n9 43\n19 47\n48 40\n20 22\n33 45\n35 22\n33 24\n9 6\n13 1\n13 24\n49 20\n1 20\n29 38\n10 35\n25 23\n49 30\n42 8\n20 18\n32 15\n32 1\n27 10\n20 47\n41 7\n20 14\n18 26\n4 20\n20 2\n46 37\n41 16\n46 41\n12 20\n8 40\n18 37\n29 3\n32 39\n23 37",
"output": "8113631"
},
{
"input": "2 3 4\n1 2",
"output": "3"
},
{
"input": "50 491238 12059\n42 3\n5 9\n11 9\n41 15\n42 34\n11 6\n40 16\n23 8\n41 7\n22 6\n24 29\n7 17\n31 2\n17 33\n39 42\n42 6\n41 50\n21 45\n19 41\n1 21\n42 1\n2 25\n17 28\n49 42\n30 13\n4 12\n10 32\n48 35\n21 2\n14 6\n49 29\n18 20\n38 22\n19 37\n20 47\n3 36\n1 44\n20 7\n4 11\n39 26\n30 40\n6 7\n25 46\n2 27\n30 42\n10 11\n8 21\n42 43\n35 8",
"output": "590891"
},
{
"input": "2 4 1\n1 2",
"output": "4"
},
{
"input": "5 2 2\n1 2\n1 3\n1 4\n1 5",
"output": "8"
},
{
"input": "4 100 1\n1 2\n1 3\n1 4",
"output": "102"
},
{
"input": "3 2 1\n1 2\n1 3",
"output": "3"
},
{
"input": "5 6 1\n1 2\n1 3\n1 4\n1 5",
"output": "9"
},
{
"input": "3 100 1\n1 2\n2 3",
"output": "101"
},
{
"input": "2 2 1\n1 2",
"output": "2"
},
{
"input": "5 3 2\n1 2\n1 3\n1 4\n1 5",
"output": "9"
},
{
"input": "4 1000 1\n1 2\n1 3\n1 4",
"output": "1002"
},
{
"input": "4 100 1\n1 2\n2 3\n3 4",
"output": "3"
},
{
"input": "2 3 1\n1 2",
"output": "3"
},
{
"input": "5 4 3\n1 2\n1 3\n1 4\n1 5",
"output": "13"
}
] | 1,454,093,362 | 5,962 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 1,123 | 20,992,000 | n, x, y = [int(x) for x in input().split()]
if x >= y:
print(y * (n - 1))
exit()
count = n - 1
been = [0] * n
edge = []
for i in range(n - 1):
k, l = [int(x) for x in input().split()]
edge.append([k - 1, l - 1, 1])
been[k - 1] += 1
been[l - 1] += 1
for i in range(n - 1):
if been[edge[i][0]] > 2 and been[edge[i][1]] > 2:
been[edge[i][0]] -= 1
been[edge[i][1]] -= 1
count -= 1
edge[i][2] = 0
for i in range(n - 1):
if edge[i][2] == 1 and been[edge[i][0]] > 2 or been[edge[i][1]] > 2:
been[edge[i][0]] -= 1
been[edge[i][1]] -= 1
count -= 1
print(y * (n - 1 - count) + x * count)
| Title: Hamiltonian Spanning Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly *y* seconds to traverse any single road.
A spanning tree is a set of roads containing exactly *n*<=-<=1 roads such that it's possible to travel between any two cities using only these roads.
Some spanning tree of the initial network was chosen. For every road in this tree the time one needs to traverse this road was changed from *y* to *x* seconds. Note that it's not guaranteed that *x* is smaller than *y*.
You would like to travel through all the cities using the shortest path possible. Given *n*, *x*, *y* and a description of the spanning tree that was chosen, find the cost of the shortest path that starts in any city, ends in any city and visits all cities exactly once.
Input Specification:
The first line of the input contains three integers *n*, *x* and *y* (2<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*x*,<=*y*<=≤<=109).
Each of the next *n*<=-<=1 lines contains a description of a road in the spanning tree. The *i*-th of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) — indices of the cities connected by the *i*-th road. It is guaranteed that these roads form a spanning tree.
Output Specification:
Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once.
Demo Input:
['5 2 3\n1 2\n1 3\n3 4\n5 3\n', '5 3 2\n1 2\n1 3\n3 4\n5 3\n']
Demo Output:
['9\n', '8\n']
Note:
In the first sample, roads of the spanning tree have cost 2, while other roads have cost 3. One example of an optimal path is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3a11f64ac0349d4ecd3a2b4c3443aeb7ac3b28b9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample, we have the same spanning tree, but roads in the spanning tree cost 3, while other roads cost 2. One example of an optimal path is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3fdb844c44665567f5addf82820eb6f96a060920.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n, x, y = [int(x) for x in input().split()]
if x >= y:
print(y * (n - 1))
exit()
count = n - 1
been = [0] * n
edge = []
for i in range(n - 1):
k, l = [int(x) for x in input().split()]
edge.append([k - 1, l - 1, 1])
been[k - 1] += 1
been[l - 1] += 1
for i in range(n - 1):
if been[edge[i][0]] > 2 and been[edge[i][1]] > 2:
been[edge[i][0]] -= 1
been[edge[i][1]] -= 1
count -= 1
edge[i][2] = 0
for i in range(n - 1):
if edge[i][2] == 1 and been[edge[i][0]] > 2 or been[edge[i][1]] > 2:
been[edge[i][0]] -= 1
been[edge[i][1]] -= 1
count -= 1
print(y * (n - 1 - count) + x * count)
``` | 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,683,305,199 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 61 | 0 | R , G , B = map(int ,input().split())
if R+G==0 or R+B==0 or B+G==0:
print(0)
exit(0)
m = min(R,G,B)
R-=m
G-=m
B-=m
m1 = min(max(R,G) , max(G,B),max(R,B))
print(m + min(m1 , (R+G+B)//3))
| 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
R , G , B = map(int ,input().split())
if R+G==0 or R+B==0 or B+G==0:
print(0)
exit(0)
m = min(R,G,B)
R-=m
G-=m
B-=m
m1 = min(max(R,G) , max(G,B),max(R,B))
print(m + min(m1 , (R+G+B)//3))
``` | 0 |
|
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add. | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable. | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
"input": "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n19 16\n17 20\n17 23\n18 22\n18 23\n22 19\n21 20\n23 24",
"output": "215"
},
{
"input": "10 30 1\n4\n1 2\n3 1\n4 1\n1 6\n1 8\n10 1\n2 4\n2 7\n3 4\n3 5\n7 3\n3 9\n10 3\n5 4\n6 4\n7 4\n9 4\n10 4\n6 5\n5 8\n9 5\n10 5\n6 7\n9 6\n10 6\n7 8\n9 7\n10 7\n9 8\n10 8",
"output": "15"
},
{
"input": "10 13 2\n5 10\n2 1\n1 4\n2 3\n2 8\n3 4\n7 3\n4 6\n8 4\n4 9\n6 7\n6 9\n10 6\n7 8",
"output": "23"
},
{
"input": "10 10 3\n2 5 6\n1 3\n4 1\n4 3\n5 3\n3 9\n8 4\n9 4\n5 10\n8 7\n10 8",
"output": "18"
},
{
"input": "10 5 3\n1 5 9\n1 3\n1 8\n2 3\n8 4\n5 7",
"output": "17"
},
{
"input": "6 4 2\n1 4\n1 2\n2 3\n4 5\n5 6",
"output": "2"
},
{
"input": "7 8 2\n1 4\n1 2\n2 3\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7",
"output": "1"
},
{
"input": "5 2 3\n1 3 4\n1 5\n2 4",
"output": "0"
},
{
"input": "5 3 2\n1 2\n2 3\n2 4\n1 5",
"output": "1"
},
{
"input": "9 5 2\n1 5\n1 2\n2 3\n3 4\n5 6\n6 7",
"output": "13"
},
{
"input": "6 4 1\n1\n2 3\n3 4\n4 5\n5 6",
"output": "11"
},
{
"input": "6 4 2\n1 5\n1 2\n2 3\n3 4\n5 6",
"output": "3"
},
{
"input": "7 3 3\n1 5 6\n1 2\n1 3\n6 7",
"output": "4"
},
{
"input": "5 2 2\n1 2\n1 3\n2 4",
"output": "2"
},
{
"input": "11 7 2\n1 4\n1 2\n1 3\n4 5\n4 6\n5 6\n9 10\n1 11",
"output": "24"
},
{
"input": "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10",
"output": "89"
}
] | 1,643,315,471 | 791 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | import sys
input = sys.stdin.buffer.readline
def findroot(roots, x):
L = []
while roots[x] != x:
L.append(x)
x = roots[x]
for y in L:
roots[y] = x
return x
def process(n, G, C):
g = [[] for i in range(n+1)]
m = len(G)
roots = [i for i in range(n+1)]
for i in range(m):
u, v = G[i]
u1 = findroot(roots, u)
v1 = findroot(roots, v)
roots[u1] = v1
g[u].append(v)
g[v].append(u)
root_dict = {}
for i in range(1, n+1):
i1 = findroot(roots, i)
if i1 not in root_dict:
root_dict[i1] = [0, 0]
root_dict[i1][0]+=1
root_dict[i1][1]+=len(g[i])
answer = 0
my_max = 0
v0 = n
e0 = m
for c in C:
c1 = roots[c]
v1, e1 = root_dict[c1]
e1 = e1//2
# print(c1, v1, e1)
answer+=(v1*(v1-1)//2-e1)
my_max = max(my_max, v1)
v0-=v1
e0-=e1
# print(answer, my_max, v0)
answer+=(v0*my_max)
return answer
n, m, k = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
G = []
for i in range(m):
u, v = [int(x) for x in input().split()]
G.append([u, v])
print(process(n, G, C)) | Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Input Specification:
The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable.
Output Specification:
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
Demo Input:
['4 1 2\n1 3\n1 2\n', '3 3 1\n2\n1 2\n1 3\n2 3\n']
Demo Output:
['2\n', '0\n']
Note:
For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | ```python
import sys
input = sys.stdin.buffer.readline
def findroot(roots, x):
L = []
while roots[x] != x:
L.append(x)
x = roots[x]
for y in L:
roots[y] = x
return x
def process(n, G, C):
g = [[] for i in range(n+1)]
m = len(G)
roots = [i for i in range(n+1)]
for i in range(m):
u, v = G[i]
u1 = findroot(roots, u)
v1 = findroot(roots, v)
roots[u1] = v1
g[u].append(v)
g[v].append(u)
root_dict = {}
for i in range(1, n+1):
i1 = findroot(roots, i)
if i1 not in root_dict:
root_dict[i1] = [0, 0]
root_dict[i1][0]+=1
root_dict[i1][1]+=len(g[i])
answer = 0
my_max = 0
v0 = n
e0 = m
for c in C:
c1 = roots[c]
v1, e1 = root_dict[c1]
e1 = e1//2
# print(c1, v1, e1)
answer+=(v1*(v1-1)//2-e1)
my_max = max(my_max, v1)
v0-=v1
e0-=e1
# print(answer, my_max, v0)
answer+=(v0*my_max)
return answer
n, m, k = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
G = []
for i in range(m):
u, v = [int(x) for x in input().split()]
G.append([u, v])
print(process(n, G, C))
``` | 0 |
|
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978 -217138 -408658 493342 -733576 -350871 711210 884148 -426172 519986 -356885 527171 661680 977247 141654 906254 -961045 -759474 -48634 891473 -606365 -513781 -966166 27696",
"output": "yes"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "no"
},
{
"input": "11\n1 11 10 2 3 9 8 4 5 7 6",
"output": "no"
},
{
"input": "10\n3 2 4 5 1 6 9 7 8 10",
"output": "yes"
},
{
"input": "11\n3 4 2 5 1 6 11 7 10 8 9",
"output": "no"
},
{
"input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8",
"output": "no"
},
{
"input": "16\n6 7 8 9 5 10 11 12 13 14 15 4 16 2 1 3",
"output": "yes"
},
{
"input": "1\n0",
"output": "no"
},
{
"input": "4\n3 1 4 2",
"output": "yes"
},
{
"input": "5\n0 2 4 -2 5",
"output": "no"
},
{
"input": "5\n1 9 8 7 0",
"output": "yes"
},
{
"input": "3\n5 10 0",
"output": "no"
},
{
"input": "6\n1 3 -1 5 2 4",
"output": "yes"
},
{
"input": "4\n3 2 4 1",
"output": "no"
},
{
"input": "4\n10 5 15 0",
"output": "no"
},
{
"input": "2\n-5 -10",
"output": "no"
},
{
"input": "3\n1 0 3",
"output": "no"
},
{
"input": "4\n-2 -4 1 -3",
"output": "yes"
},
{
"input": "4\n3 6 0 2",
"output": "no"
},
{
"input": "4\n-9 10 -10 0",
"output": "yes"
},
{
"input": "4\n5 10 1 15",
"output": "no"
},
{
"input": "3\n1 0 2",
"output": "no"
},
{
"input": "4\n2 3 4 1",
"output": "no"
},
{
"input": "4\n7 5 9 12",
"output": "no"
}
] | 1,415,686,458 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def checkint(a,b,c,d):
check=0
if (a<c<b<d) or (c<a<d<b):
check=1
return check
n=int(input())
lis=input().split()
for i in range(n):
lis[i]=int(lis[i])
intersect=0
for i in range(n-1):
for j in range(n-1):
if checkint(lis[i],lis[i+1],lis[j],lis[j+1])==1:
intersect=1
print(i,j)
if intersect==0:
print('no')
else:
print('yes')
| Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate.
Output Specification:
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
Demo Input:
['4\n0 10 5 15\n', '4\n0 15 5 10\n']
Demo Output:
['yes\n', 'no\n']
Note:
The first test from the statement is on the picture to the left, the second test is on the picture to the right. | ```python
def checkint(a,b,c,d):
check=0
if (a<c<b<d) or (c<a<d<b):
check=1
return check
n=int(input())
lis=input().split()
for i in range(n):
lis[i]=int(lis[i])
intersect=0
for i in range(n-1):
for j in range(n-1):
if checkint(lis[i],lis[i+1],lis[j],lis[j+1])==1:
intersect=1
print(i,j)
if intersect==0:
print('no')
else:
print('yes')
``` | 0 |
|
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..."
},
{
"input": "84817 1 33457",
"output": "-1"
},
{
"input": "21 37 99",
"output": "16 53 "
},
{
"input": "78 7 15",
"output": "-1"
},
{
"input": "74 17 27",
"output": "-1"
},
{
"input": "79 23 43",
"output": "-1"
},
{
"input": "32 33 3",
"output": "-1"
},
{
"input": "55 49 44",
"output": "-1"
},
{
"input": "64 59 404",
"output": "54 113 172 231 290 "
},
{
"input": "61 69 820",
"output": "8 77 146 215 284 353 422 491 560 629 698 "
},
{
"input": "17 28 532",
"output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 "
},
{
"input": "46592 52 232",
"output": "-1"
},
{
"input": "1541 58 648",
"output": "-1"
},
{
"input": "15946 76 360",
"output": "-1"
},
{
"input": "30351 86 424",
"output": "-1"
},
{
"input": "1 2 37493",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "1 3 27764",
"output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..."
},
{
"input": "10 4 9174",
"output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..."
},
{
"input": "33 7 4971",
"output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..."
},
{
"input": "981 1 3387",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "386 1 2747",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "123 2 50000",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "3123 100 10000000",
"output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..."
},
{
"input": "2 10000 1000000000",
"output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..."
},
{
"input": "3 10000 1000000000",
"output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..."
},
{
"input": "12312223 10000 1000000000",
"output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..."
},
{
"input": "500000000 1000000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 1000000000",
"output": "999999999 "
},
{
"input": "10 6 11",
"output": "-1"
},
{
"input": "2 100 10",
"output": "-1"
},
{
"input": "1 100000007 1000000000",
"output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 "
},
{
"input": "1 999999999 1000000000",
"output": "999999998 "
},
{
"input": "100000000 1000000000 1000000000",
"output": "900000000 "
},
{
"input": "11 2 12",
"output": "1 "
},
{
"input": "31 10 39",
"output": "-1"
},
{
"input": "48 6 50",
"output": "-1"
},
{
"input": "500000000 500000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 999999999",
"output": "-1"
},
{
"input": "4 2 10",
"output": "2 4 6 "
},
{
"input": "1000000000 1 1",
"output": "-1"
},
{
"input": "1000000000 1 100000",
"output": "-1"
},
{
"input": "1000000000 1 10",
"output": "-1"
},
{
"input": "10 5 14",
"output": "-1"
},
{
"input": "500000000 499999999 1000000000",
"output": "499999998 "
},
{
"input": "1 999999997 1000000000",
"output": "999999996 "
}
] | 1,663,819,406 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 248 | 8,908,800 | y,k,n=map(int,input().split())
x=k*(1+y//k)-y
flag=0
while x+y<=n:
flag=1
print(x,end=" ")
x+=k
if flag==0:
print(-1) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
Input Specification:
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Output Specification:
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1.
Demo Input:
['10 1 10\n', '10 6 40\n']
Demo Output:
['-1\n', '2 8 14 20 26 \n']
Note:
none | ```python
y,k,n=map(int,input().split())
x=k*(1+y//k)-y
flag=0
while x+y<=n:
flag=1
print(x,end=" ")
x+=k
if flag==0:
print(-1)
``` | 3 |
|
771 | A | Bear and Friendship Condition | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. | The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | [
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | 250 | [
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
"input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8",
"output": "YES"
},
{
"input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11",
"output": "NO"
},
{
"input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69",
"output": "NO"
},
{
"input": "3 1\n1 2",
"output": "YES"
},
{
"input": "3 2\n3 2\n1 3",
"output": "NO"
},
{
"input": "3 3\n2 3\n1 2\n1 3",
"output": "YES"
},
{
"input": "4 2\n4 1\n2 1",
"output": "NO"
},
{
"input": "4 3\n3 1\n2 1\n3 2",
"output": "YES"
},
{
"input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2",
"output": "NO"
},
{
"input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6",
"output": "NO"
},
{
"input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8",
"output": "NO"
},
{
"input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3",
"output": "NO"
},
{
"input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762",
"output": "YES"
},
{
"input": "150000 0",
"output": "YES"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n1 4",
"output": "NO"
},
{
"input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7",
"output": "NO"
},
{
"input": "5 4\n1 2\n2 5\n3 4\n4 5",
"output": "NO"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n1 3",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n2 4\n3 4",
"output": "NO"
},
{
"input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n3 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n2 4",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "NO"
},
{
"input": "150000 3\n150000 149999\n149998 149999\n149998 150000",
"output": "YES"
},
{
"input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10",
"output": "NO"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "NO"
},
{
"input": "5 4\n1 2\n1 3\n1 4\n1 5",
"output": "NO"
},
{
"input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n4 2\n4 3",
"output": "NO"
},
{
"input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "NO"
},
{
"input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6",
"output": "NO"
},
{
"input": "1000 4\n100 132\n100 164\n196 132\n196 164",
"output": "NO"
}
] | 1,587,536,058 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define li(n) for(int i=0; i<n; i++)
class DSU {
public:
int size;
int components;
vector<int> component_size;
vector<int> id;
DSU(int size) {
this->size = size;
this->components = size;
this->component_size.resize(size, 1);
this->id.resize(size);
for(int i = 0; i < size; i++) {
id[i] = i;
}
}
int getSize() {
return this->size;
}
int Find(int a) {
int root = a;
while(root != id[root]) {
root = id[root];
}
while(a != root) {
id[a] = root;
a = id[a];
}
return root;
}
int Union(int a, int b) {
int root_a = Find(a);
int root_b = Find(b);
if(root_a == root_b) {
return root_a;
} else {
if (component_size[root_a] >= component_size[root_b]) {
component_size[root_a] += component_size[id[root_b]];
components--;
return id[root_b] = root_a;
} else {
component_size[root_b] += component_size[id[root_a]];
components--;
return id[root_a] = root_b;
}
}
}
void Show() {
for(int i=0; i<size; i++) {
cout << i << ' ' << id[i] << endl;
}
cout << endl;
for(int i=0; i<size; i++) {
cout << i << ' ' << component_size[Find(i)] << endl;
}
}
};
void test();
int comb2(int n);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin >> t;
while(t--) {
test();
cout << endl;
}
}
void test() {
int n, m;
cin >> n >> m;
DSU dsu(n);
vector<bool> c(n, false);
li(m) {
int u, v;
cin >> u >> v;
u--; v--;
dsu.Union(u, v);
}
int edges = 0;
li(n) {
int root = dsu.Find(i);
if(!c[root]) {
edges += comb2(dsu.component_size[root]);
c[root] = true;
}
}
// dsu.Show();
// cout << edges << endl;
cout << (edges == m ? "YES" : "NO");
}
int comb2(int n) {
if(n < 2) {
return 0;
} else {
return n * (n-1) / 2;
}
} | Title: Bear and Friendship Condition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
Input Specification:
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
Output Specification:
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
Demo Input:
['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | ```python
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define li(n) for(int i=0; i<n; i++)
class DSU {
public:
int size;
int components;
vector<int> component_size;
vector<int> id;
DSU(int size) {
this->size = size;
this->components = size;
this->component_size.resize(size, 1);
this->id.resize(size);
for(int i = 0; i < size; i++) {
id[i] = i;
}
}
int getSize() {
return this->size;
}
int Find(int a) {
int root = a;
while(root != id[root]) {
root = id[root];
}
while(a != root) {
id[a] = root;
a = id[a];
}
return root;
}
int Union(int a, int b) {
int root_a = Find(a);
int root_b = Find(b);
if(root_a == root_b) {
return root_a;
} else {
if (component_size[root_a] >= component_size[root_b]) {
component_size[root_a] += component_size[id[root_b]];
components--;
return id[root_b] = root_a;
} else {
component_size[root_b] += component_size[id[root_a]];
components--;
return id[root_a] = root_b;
}
}
}
void Show() {
for(int i=0; i<size; i++) {
cout << i << ' ' << id[i] << endl;
}
cout << endl;
for(int i=0; i<size; i++) {
cout << i << ' ' << component_size[Find(i)] << endl;
}
}
};
void test();
int comb2(int n);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin >> t;
while(t--) {
test();
cout << endl;
}
}
void test() {
int n, m;
cin >> n >> m;
DSU dsu(n);
vector<bool> c(n, false);
li(m) {
int u, v;
cin >> u >> v;
u--; v--;
dsu.Union(u, v);
}
int edges = 0;
li(n) {
int root = dsu.Find(i);
if(!c[root]) {
edges += comb2(dsu.component_size[root]);
c[root] = true;
}
}
// dsu.Show();
// cout << edges << endl;
cout << (edges == m ? "YES" : "NO");
}
int comb2(int n) {
if(n < 2) {
return 0;
} else {
return n * (n-1) / 2;
}
}
``` | -1 |
|
142 | A | Help Farmer | PROGRAMMING | 1,600 | [
"brute force",
"math"
] | null | null | Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*.
Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks. | The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109). | Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | [
"4\n",
"7\n",
"12\n"
] | [
"28 41\n",
"47 65\n",
"48 105\n"
] | Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks. | 500 | [
{
"input": "4",
"output": "28 41"
},
{
"input": "7",
"output": "47 65"
},
{
"input": "12",
"output": "48 105"
},
{
"input": "1",
"output": "17 17"
},
{
"input": "6",
"output": "34 57"
},
{
"input": "8",
"output": "40 73"
},
{
"input": "9",
"output": "41 81"
},
{
"input": "14",
"output": "58 121"
},
{
"input": "15",
"output": "55 129"
},
{
"input": "16",
"output": "56 137"
},
{
"input": "18",
"output": "57 153"
},
{
"input": "20",
"output": "64 169"
},
{
"input": "299999771",
"output": "1499998867 2399998177"
},
{
"input": "54",
"output": "106 441"
},
{
"input": "96",
"output": "144 777"
},
{
"input": "348",
"output": "396 2793"
},
{
"input": "748",
"output": "487 5993"
},
{
"input": "908",
"output": "1840 7273"
},
{
"input": "1026",
"output": "591 8217"
},
{
"input": "1985",
"output": "3601 15889"
},
{
"input": "4472",
"output": "1603 35785"
},
{
"input": "20845",
"output": "8873 166769"
},
{
"input": "50480",
"output": "17884 403849"
},
{
"input": "62497",
"output": "312497 499985"
},
{
"input": "646055",
"output": "140995 5168449"
},
{
"input": "790620",
"output": "316416 6324969"
},
{
"input": "989903",
"output": "1082167 7919233"
},
{
"input": "7033800",
"output": "210976 56270409"
},
{
"input": "7661860",
"output": "546725 61294889"
},
{
"input": "7834243",
"output": "8302235 62673953"
},
{
"input": "45134118",
"output": "19223945 361072953"
},
{
"input": "89054701",
"output": "445273517 712437617"
},
{
"input": "99264891",
"output": "15587889 794119137"
},
{
"input": "127039320",
"output": "1209066 1016314569"
},
{
"input": "206898748",
"output": "1683461 1655189993"
},
{
"input": "231136953",
"output": "539319577 1849095633"
},
{
"input": "257259713",
"output": "2122207 2058077713"
},
{
"input": "286736327",
"output": "290355727 2293890625"
},
{
"input": "311933803",
"output": "1559669027 2495470433"
},
{
"input": "332393619",
"output": "10714371 2659148961"
},
{
"input": "422114561",
"output": "78417139 3376916497"
},
{
"input": "453012754",
"output": "2844347 3624102041"
},
{
"input": "470860680",
"output": "129486993 3766885449"
},
{
"input": "509607936",
"output": "3045276 4076863497"
},
{
"input": "534879507",
"output": "253364145 4279036065"
},
{
"input": "535074941",
"output": "647722381 4280599537"
},
{
"input": "536870912",
"output": "3151876 4294967305"
},
{
"input": "573308928",
"output": "3301020 4586471433"
},
{
"input": "603979776",
"output": "3414276 4831838217"
},
{
"input": "605404800",
"output": "3414952 4843238409"
},
{
"input": "615716902",
"output": "10508698 4925735225"
},
{
"input": "628464178",
"output": "3574502 5027713433"
},
{
"input": "631243141",
"output": "634644469 5049945137"
},
{
"input": "644972544",
"output": "3573148 5159780361"
},
{
"input": "659274082",
"output": "1977822262 5274192665"
},
{
"input": "679477248",
"output": "3693060 5435817993"
},
{
"input": "735134400",
"output": "3886608 5881075209"
},
{
"input": "764411904",
"output": "3988228 6115295241"
},
{
"input": "778377600",
"output": "4036708 6227020809"
},
{
"input": "791683200",
"output": "4082888 6333465609"
},
{
"input": "805306368",
"output": "4201476 6442450953"
},
{
"input": "821620800",
"output": "4185636 6572966409"
},
{
"input": "856079286",
"output": "196667409 6848634297"
},
{
"input": "857656800",
"output": "4307008 6861254409"
},
{
"input": "859963392",
"output": "4320292 6879707145"
},
{
"input": "864864000",
"output": "4331048 6918912009"
},
{
"input": "882161280",
"output": "4388720 7057290249"
},
{
"input": "884822400",
"output": "4396766 7078579209"
},
{
"input": "905969664",
"output": "4529412 7247757321"
},
{
"input": "908107200",
"output": "4474050 7264857609"
},
{
"input": "918918000",
"output": "4511288 7351344009"
},
{
"input": "931170240",
"output": "4548514 7449361929"
},
{
"input": "935625600",
"output": "4563150 7485004809"
},
{
"input": "936354996",
"output": "40069269 7490839977"
},
{
"input": "951350400",
"output": "4614600 7610803209"
},
{
"input": "958557600",
"output": "4637398 7668460809"
},
{
"input": "972972000",
"output": "4685478 7783776009"
},
{
"input": "980179200",
"output": "4707050 7841433609"
},
{
"input": "985944960",
"output": "4725040 7887559689"
},
{
"input": "994593600",
"output": "4752650 7956748809"
},
{
"input": "999893227",
"output": "1000183267 7999145825"
},
{
"input": "999893387",
"output": "1000724227 7999147105"
},
{
"input": "999905161",
"output": "1000161721 7999241297"
},
{
"input": "999942949",
"output": "1000368197 7999543601"
},
{
"input": "999996583",
"output": "1022096687 7999972673"
},
{
"input": "999999797",
"output": "4999998997 7999998385"
},
{
"input": "999999883",
"output": "4999999427 7999999073"
},
{
"input": "999999893",
"output": "4999999477 7999999153"
},
{
"input": "999999929",
"output": "4999999657 7999999441"
},
{
"input": "999999937",
"output": "4999999697 7999999505"
},
{
"input": "999999991",
"output": "1059701759 7999999937"
},
{
"input": "999999992",
"output": "129518035 7999999945"
},
{
"input": "999999993",
"output": "490196227 7999999953"
},
{
"input": "999999994",
"output": "928571477 7999999961"
},
{
"input": "999999995",
"output": "4924975 7999999969"
},
{
"input": "999999996",
"output": "1000000044 7999999977"
},
{
"input": "999999997",
"output": "15309947 7999999985"
},
{
"input": "999999998",
"output": "504345691 7999999993"
},
{
"input": "999999999",
"output": "52392027 8000000001"
},
{
"input": "1000000000",
"output": "4770064 8000000009"
}
] | 1,590,819,917 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 49 | 1,000 | 2,355,200 | n=int(input())
k=n
a=set()
a.add(n)
a.add(1)
w=999999999999999999999999999999999999999
ans=[1,1,1]
for i in range(2,int(n**0.5)+1):
if n%i==0:
a.add(i)
a.add(n//i)
#print(a)
for i in a:
for j in a:
for k in a:
if i*j*k!=n:
continue
ans[0]=i
ans[1]=j
ans[2]=k
ans.sort()
ans[0]+=1
ans[1]+=2
ans[2]+=2
w=min(w,ans[0]*ans[1]*ans[-1]-n)
e=8*n+9
print(w,e) | Title: Help Farmer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*.
Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks.
Input Specification:
The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109).
Output Specification:
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Demo Input:
['4\n', '7\n', '12\n']
Demo Output:
['28 41\n', '47 65\n', '48 105\n']
Note:
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks. | ```python
n=int(input())
k=n
a=set()
a.add(n)
a.add(1)
w=999999999999999999999999999999999999999
ans=[1,1,1]
for i in range(2,int(n**0.5)+1):
if n%i==0:
a.add(i)
a.add(n//i)
#print(a)
for i in a:
for j in a:
for k in a:
if i*j*k!=n:
continue
ans[0]=i
ans[1]=j
ans[2]=k
ans.sort()
ans[0]+=1
ans[1]+=2
ans[2]+=2
w=min(w,ans[0]*ans[1]*ans[-1]-n)
e=8*n+9
print(w,e)
``` | 0 |
|
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
},
{
"input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1",
"output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 "
},
{
"input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3",
"output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 "
},
{
"input": "10 17\n5 1\n8 1\n2 1\n2 6\n3 1\n5 7\n3 7\n8 6\n4 7\n2 7\n9 7\n10 7\n3 6\n4 1\n9 1\n8 7\n10 1",
"output": "7\n5 3 2 8 4 9 10 \n3\n1 7 6 "
},
{
"input": "10 15\n5 9\n7 8\n2 9\n1 9\n3 8\n3 9\n5 8\n1 8\n6 9\n7 9\n4 8\n4 9\n10 9\n10 8\n6 8",
"output": "2\n9 8 \n8\n1 5 7 3 4 10 6 2 "
},
{
"input": "10 9\n4 9\n1 9\n10 9\n2 9\n3 9\n6 9\n5 9\n7 9\n8 9",
"output": "1\n9 \n9\n1 4 10 2 3 6 5 7 8 "
},
{
"input": "2 1\n1 2",
"output": "1\n2 \n1\n1 "
},
{
"input": "10 10\n6 4\n9 1\n3 6\n6 7\n4 2\n9 6\n8 6\n5 7\n1 4\n6 10",
"output": "6\n9 4 3 7 8 10 \n4\n1 6 2 5 "
},
{
"input": "20 22\n20 8\n1 3\n3 18\n14 7\n19 6\n7 20\n14 8\n8 10\n2 5\n11 2\n4 19\n14 2\n7 11\n15 1\n12 15\n7 6\n11 13\n1 16\n9 12\n1 19\n17 3\n11 20",
"output": "-1"
},
{
"input": "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15",
"output": "-1"
},
{
"input": "1000 1\n839 771",
"output": "1\n839 \n1\n771 "
},
{
"input": "1000 1\n195 788",
"output": "1\n788 \n1\n195 "
},
{
"input": "100000 1\n42833 64396",
"output": "1\n64396 \n1\n42833 "
},
{
"input": "100000 1\n26257 21752",
"output": "1\n26257 \n1\n21752 "
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "-1"
}
] | 1,566,437,969 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 764 | 13,209,600 | n,m = list(map(int,input().split()))
graph = [[]for _ in range(n)]
color = [0]*n
for i in range(m):
a,b = list(map(int,input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
for i in range(n):
if color[i]:
continue
color[i] = 1
queue = [i]
while queue:
u = queue.pop()
for v in graph[u]:
if color[v]:
if color[v]==color[u]:
print(-1)
exit(0)
else:
color[v] = 3-color[u]
queue.append(v)
arr1 = []
arr2 = []
for i in range(len(color)):
if color[i]==1:
arr1.append(i+1)
else:
arr2.append(i+1)
print(len(arr1))
print(*arr1)
print(len(arr2))
print(*arr2) | Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges.
Output Specification:
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty.
Demo Input:
['4 2\n1 2\n2 3\n', '3 3\n1 2\n2 3\n1 3\n']
Demo Output:
['1\n2 \n2\n1 3 \n', '-1\n']
Note:
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | ```python
n,m = list(map(int,input().split()))
graph = [[]for _ in range(n)]
color = [0]*n
for i in range(m):
a,b = list(map(int,input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
for i in range(n):
if color[i]:
continue
color[i] = 1
queue = [i]
while queue:
u = queue.pop()
for v in graph[u]:
if color[v]:
if color[v]==color[u]:
print(-1)
exit(0)
else:
color[v] = 3-color[u]
queue.append(v)
arr1 = []
arr2 = []
for i in range(len(color)):
if color[i]==1:
arr1.append(i+1)
else:
arr2.append(i+1)
print(len(arr1))
print(*arr1)
print(len(arr2))
print(*arr2)
``` | 3 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,449,091,604 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | y = input("")
x = input("").split()
for i in range(len(x)):
x[i] = int(x[i])
even = 0
odd = 0
for i in range(len(x)):
if(x[i] % 2 == 0):
even += 1
else:
odd += 1
if(even == 1):
for j in range(len(x)):
if(x[j] % 2 == 0):
print(j + 1)
else:
for j in range(len(x)):
if(x[j] % 2 == 1):
print(j + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
y = input("")
x = input("").split()
for i in range(len(x)):
x[i] = int(x[i])
even = 0
odd = 0
for i in range(len(x)):
if(x[i] % 2 == 0):
even += 1
else:
odd += 1
if(even == 1):
for j in range(len(x)):
if(x[j] % 2 == 0):
print(j + 1)
else:
for j in range(len(x)):
if(x[j] % 2 == 1):
print(j + 1)
``` | 3.977 |
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the string is "s-palindrome". | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkgbNb",
"output": "NIE"
},
{
"input": "vMhhXCMWDe",
"output": "NIE"
},
{
"input": "iIcamjTRFH",
"output": "NIE"
},
{
"input": "WvoWvvWovW",
"output": "TAK"
},
{
"input": "WXxAdbAxXW",
"output": "TAK"
},
{
"input": "vqMTUUTMpv",
"output": "TAK"
},
{
"input": "iii",
"output": "NIE"
},
{
"input": "AAWW",
"output": "NIE"
},
{
"input": "ss",
"output": "NIE"
},
{
"input": "i",
"output": "NIE"
},
{
"input": "ii",
"output": "NIE"
},
{
"input": "mm",
"output": "NIE"
},
{
"input": "LJ",
"output": "NIE"
},
{
"input": "m",
"output": "NIE"
},
{
"input": "ioi",
"output": "NIE"
},
{
"input": "OA",
"output": "NIE"
},
{
"input": "aaaiaaa",
"output": "NIE"
},
{
"input": "SS",
"output": "NIE"
},
{
"input": "iiii",
"output": "NIE"
},
{
"input": "ssops",
"output": "NIE"
},
{
"input": "ssss",
"output": "NIE"
},
{
"input": "ll",
"output": "NIE"
},
{
"input": "s",
"output": "NIE"
},
{
"input": "bb",
"output": "NIE"
},
{
"input": "uu",
"output": "NIE"
},
{
"input": "ZoZ",
"output": "NIE"
},
{
"input": "mom",
"output": "NIE"
},
{
"input": "uou",
"output": "NIE"
},
{
"input": "u",
"output": "NIE"
},
{
"input": "JL",
"output": "NIE"
},
{
"input": "mOm",
"output": "NIE"
},
{
"input": "llll",
"output": "NIE"
},
{
"input": "ouo",
"output": "NIE"
},
{
"input": "aa",
"output": "NIE"
},
{
"input": "olo",
"output": "NIE"
},
{
"input": "S",
"output": "NIE"
},
{
"input": "lAl",
"output": "NIE"
},
{
"input": "nnnn",
"output": "NIE"
},
{
"input": "ZzZ",
"output": "NIE"
},
{
"input": "bNd",
"output": "NIE"
},
{
"input": "ZZ",
"output": "NIE"
},
{
"input": "oNoNo",
"output": "NIE"
},
{
"input": "l",
"output": "NIE"
},
{
"input": "zz",
"output": "NIE"
},
{
"input": "NON",
"output": "NIE"
},
{
"input": "nn",
"output": "NIE"
},
{
"input": "NoN",
"output": "NIE"
},
{
"input": "sos",
"output": "NIE"
},
{
"input": "lol",
"output": "NIE"
},
{
"input": "mmm",
"output": "NIE"
},
{
"input": "YAiAY",
"output": "NIE"
},
{
"input": "ipIqi",
"output": "NIE"
},
{
"input": "AAA",
"output": "TAK"
},
{
"input": "uoOou",
"output": "NIE"
},
{
"input": "SOS",
"output": "NIE"
},
{
"input": "NN",
"output": "NIE"
},
{
"input": "n",
"output": "NIE"
},
{
"input": "h",
"output": "NIE"
},
{
"input": "blld",
"output": "NIE"
},
{
"input": "ipOqi",
"output": "NIE"
},
{
"input": "pop",
"output": "NIE"
},
{
"input": "BB",
"output": "NIE"
},
{
"input": "OuO",
"output": "NIE"
},
{
"input": "lxl",
"output": "NIE"
},
{
"input": "Z",
"output": "NIE"
},
{
"input": "vvivv",
"output": "NIE"
},
{
"input": "nnnnnnnnnnnnn",
"output": "NIE"
},
{
"input": "AA",
"output": "TAK"
},
{
"input": "t",
"output": "NIE"
},
{
"input": "z",
"output": "NIE"
},
{
"input": "mmmAmmm",
"output": "NIE"
},
{
"input": "qlililp",
"output": "NIE"
},
{
"input": "mpOqm",
"output": "NIE"
},
{
"input": "iiiiiiiiii",
"output": "NIE"
},
{
"input": "BAAAB",
"output": "NIE"
},
{
"input": "UA",
"output": "NIE"
},
{
"input": "mmmmmmm",
"output": "NIE"
},
{
"input": "NpOqN",
"output": "NIE"
},
{
"input": "uOu",
"output": "NIE"
},
{
"input": "uuu",
"output": "NIE"
},
{
"input": "NAMAN",
"output": "NIE"
},
{
"input": "lllll",
"output": "NIE"
},
{
"input": "T",
"output": "TAK"
},
{
"input": "mmmmmmmmmmmmmmmm",
"output": "NIE"
},
{
"input": "AiiA",
"output": "NIE"
},
{
"input": "iOi",
"output": "NIE"
},
{
"input": "lll",
"output": "NIE"
},
{
"input": "N",
"output": "NIE"
},
{
"input": "viv",
"output": "NIE"
},
{
"input": "oiio",
"output": "NIE"
},
{
"input": "AiiiA",
"output": "NIE"
},
{
"input": "NNNN",
"output": "NIE"
},
{
"input": "ixi",
"output": "NIE"
},
{
"input": "AuuA",
"output": "NIE"
},
{
"input": "AAAANANAAAA",
"output": "NIE"
},
{
"input": "mmmmm",
"output": "NIE"
},
{
"input": "oYo",
"output": "TAK"
},
{
"input": "dd",
"output": "NIE"
},
{
"input": "A",
"output": "TAK"
},
{
"input": "ioh",
"output": "NIE"
},
{
"input": "mmmm",
"output": "NIE"
},
{
"input": "uuuu",
"output": "NIE"
},
{
"input": "puq",
"output": "NIE"
},
{
"input": "rrrrrr",
"output": "NIE"
},
{
"input": "c",
"output": "NIE"
},
{
"input": "AbpA",
"output": "NIE"
},
{
"input": "qAq",
"output": "NIE"
},
{
"input": "tt",
"output": "NIE"
},
{
"input": "mnmnm",
"output": "NIE"
},
{
"input": "sss",
"output": "NIE"
},
{
"input": "yy",
"output": "NIE"
},
{
"input": "bob",
"output": "NIE"
},
{
"input": "NAN",
"output": "NIE"
},
{
"input": "mAm",
"output": "NIE"
},
{
"input": "tAt",
"output": "NIE"
},
{
"input": "yAy",
"output": "NIE"
},
{
"input": "zAz",
"output": "NIE"
},
{
"input": "aZ",
"output": "NIE"
},
{
"input": "hh",
"output": "NIE"
},
{
"input": "bbbb",
"output": "NIE"
},
{
"input": "ZAZ",
"output": "NIE"
},
{
"input": "Y",
"output": "TAK"
},
{
"input": "AAMM",
"output": "NIE"
},
{
"input": "lml",
"output": "NIE"
},
{
"input": "AZA",
"output": "NIE"
},
{
"input": "mXm",
"output": "NIE"
},
{
"input": "bd",
"output": "TAK"
},
{
"input": "H",
"output": "TAK"
},
{
"input": "uvu",
"output": "NIE"
},
{
"input": "dxxd",
"output": "NIE"
},
{
"input": "dp",
"output": "NIE"
},
{
"input": "vV",
"output": "NIE"
},
{
"input": "vMo",
"output": "NIE"
},
{
"input": "O",
"output": "TAK"
},
{
"input": "vYv",
"output": "TAK"
},
{
"input": "fv",
"output": "NIE"
},
{
"input": "U",
"output": "TAK"
},
{
"input": "iAi",
"output": "NIE"
},
{
"input": "I",
"output": "TAK"
},
{
"input": "VxrV",
"output": "NIE"
},
{
"input": "POP",
"output": "NIE"
},
{
"input": "bid",
"output": "NIE"
},
{
"input": "bmd",
"output": "NIE"
},
{
"input": "AiA",
"output": "NIE"
},
{
"input": "mmmmmm",
"output": "NIE"
},
{
"input": "XHX",
"output": "TAK"
},
{
"input": "llllll",
"output": "NIE"
},
{
"input": "aAa",
"output": "NIE"
},
{
"input": "Db",
"output": "NIE"
},
{
"input": "lOl",
"output": "NIE"
},
{
"input": "bzd",
"output": "NIE"
}
] | 1,588,471,265 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | s=input()
n=len(s)
if len(s)%2==0:
print("NIE")
else:
i=0
j=n-1
while i<=j:
if s[i]==s[j]:
pass
elif s[i]=='p' or 'q' and s[j]=="p" or "q":
pass
elif s[i] == 'b' or 'd' and s[j] == "b" or "d":
pass
else:
print("NIE")
exit()
i += 1
j -= 1
print("TAK") | Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the string is "s-palindrome".
Input Specification:
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters.
Output Specification:
Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise.
Demo Input:
['oXoxoXo\n', 'bod\n', 'ER\n']
Demo Output:
['TAK\n', 'TAK\n', 'NIE\n']
Note:
none | ```python
s=input()
n=len(s)
if len(s)%2==0:
print("NIE")
else:
i=0
j=n-1
while i<=j:
if s[i]==s[j]:
pass
elif s[i]=='p' or 'q' and s[j]=="p" or "q":
pass
elif s[i] == 'b' or 'd' and s[j] == "b" or "d":
pass
else:
print("NIE")
exit()
i += 1
j -= 1
print("TAK")
``` | 0 |
|
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed.
As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears.
For each query find the moment when the server will finish to process it or print -1 if this query will be rejected. | The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=<<=*t**i* for all *i*<=><=1. | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22. | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000",
"output": "1999999996 2999999996 3999999996 4999999996 "
},
{
"input": "5 1\n2 1\n3 6\n4 5\n6 4\n7 2",
"output": "3 9 14 -1 -1 "
},
{
"input": "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2",
"output": "18 20 26 -1 -1 -1 -1 -1 -1 28 "
},
{
"input": "6 4\n2 4\n4 2\n5 2\n6 2\n7 2\n9 2",
"output": "6 8 10 12 14 16 "
},
{
"input": "8 3\n1 2\n3 1\n4 3\n5 3\n6 1\n7 2\n8 8\n9 7",
"output": "3 4 7 10 11 13 21 -1 "
},
{
"input": "10 3\n1 14\n3 2\n5 4\n6 9\n9 1\n12 22\n15 11\n18 8\n28 2\n29 4",
"output": "15 17 21 30 -1 -1 41 49 51 -1 "
},
{
"input": "5 2\n2 7\n3 3\n7 4\n9 1\n10 2",
"output": "9 12 16 17 -1 "
},
{
"input": "4 1\n2 1\n6 5\n9 2\n10 3",
"output": "3 11 13 -1 "
},
{
"input": "4 1\n1 2\n2 1\n3 1\n4 3",
"output": "3 4 5 8 "
},
{
"input": "6 3\n1 2\n2 3\n100 200\n200 300\n10000 20000\n20000 30000",
"output": "3 6 300 600 30000 60000 "
}
] | 1,458,256,296 | 137,496 | Python 3 | OK | TESTS | 71 | 1,824 | 31,027,200 | n, b = [int(i) for i in input().split()]
q = [0] * n
bg = 0
en = 0
time = 0
res = [-1] * n
for it in range(n):
ev = [int(i) for i in input().split()]
ev.append(it)
while bg < en and max(time, q[bg][0]) <= ev[0]:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
time += q[bg][1]
bg += 1
if en - bg < b:
q[en] = ev
en += 1
while bg < en:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
time += q[bg][1]
bg += 1
for i in range(n):
print(res[i], end=' ')
| Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed.
As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears.
For each query find the moment when the server will finish to process it or print -1 if this query will be rejected.
Input Specification:
The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=<<=*t**i* for all *i*<=><=1.
Output Specification:
Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected.
Demo Input:
['5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n', '4 1\n2 8\n4 8\n10 9\n15 2\n']
Demo Output:
['11 19 -1 21 22 \n', '10 18 27 -1 \n']
Note:
Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22. | ```python
n, b = [int(i) for i in input().split()]
q = [0] * n
bg = 0
en = 0
time = 0
res = [-1] * n
for it in range(n):
ev = [int(i) for i in input().split()]
ev.append(it)
while bg < en and max(time, q[bg][0]) <= ev[0]:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
time += q[bg][1]
bg += 1
if en - bg < b:
q[en] = ev
en += 1
while bg < en:
time = max(time, q[bg][0])
res[q[bg][2]] = time + q[bg][1]
time += q[bg][1]
bg += 1
for i in range(n):
print(res[i], end=' ')
``` | 3 |
|
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3",
"output": "16"
},
{
"input": "10\n2 3 0 1 3 1 2 2 1 0",
"output": "3"
},
{
"input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n3 3",
"output": "0"
},
{
"input": "3\n3 3 3",
"output": "0"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "2\n0 2",
"output": "1"
},
{
"input": "10\n2 2 3 3 3 3 2 1 3 2",
"output": "2"
},
{
"input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0",
"output": "11"
},
{
"input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1",
"output": "4"
},
{
"input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2",
"output": "3"
},
{
"input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0",
"output": "12"
},
{
"input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3",
"output": "5"
},
{
"input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2",
"output": "4"
},
{
"input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1",
"output": "16"
},
{
"input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3",
"output": "5"
},
{
"input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3",
"output": "3"
},
{
"input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0",
"output": "22"
},
{
"input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2",
"output": "9"
},
{
"input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3",
"output": "2"
},
{
"input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0",
"output": "21"
},
{
"input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2",
"output": "11"
},
{
"input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2",
"output": "7"
},
{
"input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0",
"output": "28"
},
{
"input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1",
"output": "10"
},
{
"input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3",
"output": "8"
},
{
"input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2",
"output": "29"
},
{
"input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3",
"output": "8"
},
{
"input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0",
"output": "32"
},
{
"input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2",
"output": "16"
},
{
"input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3",
"output": "7"
},
{
"input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0",
"output": "40"
},
{
"input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2",
"output": "13"
},
{
"input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3",
"output": "7"
},
{
"input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0",
"output": "44"
},
{
"input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2",
"output": "15"
},
{
"input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3",
"output": "8"
},
{
"input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1",
"output": "35"
},
{
"input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3",
"output": "13"
},
{
"input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3",
"output": "6"
},
{
"input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1",
"output": "43"
},
{
"input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1",
"output": "16"
},
{
"input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1",
"output": "10"
},
{
"input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0",
"output": "51"
},
{
"input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1",
"output": "16"
},
{
"input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1",
"output": "11"
},
{
"input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1",
"output": "56"
},
{
"input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0",
"output": "17"
},
{
"input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3",
"output": "9"
},
{
"input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0",
"output": "54"
},
{
"input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3",
"output": "19"
},
{
"input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3",
"output": "9"
},
{
"input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1",
"output": "57"
},
{
"input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1",
"output": "17"
},
{
"input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2",
"output": "9"
},
{
"input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1",
"output": "61"
},
{
"input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2",
"output": "15"
},
{
"input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2",
"output": "14"
},
{
"input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2",
"output": "63"
},
{
"input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3",
"output": "15"
},
{
"input": "100\n1 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 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 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 1 2 1 2 1 2 1 2",
"output": "0"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "50"
},
{
"input": "99\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",
"output": "49"
},
{
"input": "100\n2 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 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 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 1 2 1 2 1 2 1 2 1",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "2\n0 3",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 0",
"output": "1"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n3 0",
"output": "1"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0",
"output": "50"
}
] | 1,686,713,370 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 11,980,800 | n=int(input())
x=list(map(int,input().split()))
def solve(i,p=0):
if i==n:
return 0
if x[i]==1 and p!=1:
return solve(i+1,1)
elif x[i]==2 and p!=2:
return solve(i+1,2)
elif x[i]==3:
if p:
return solve(i+1,[2,1][p-1])
else:
return min(solve(i+1,1),solve(i+1,2))
else:
return 1+min(solve(i+1,1),solve(i+1,2))
print(solve(0)) | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Output Specification:
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days.
Demo Input:
['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | ```python
n=int(input())
x=list(map(int,input().split()))
def solve(i,p=0):
if i==n:
return 0
if x[i]==1 and p!=1:
return solve(i+1,1)
elif x[i]==2 and p!=2:
return solve(i+1,2)
elif x[i]==3:
if p:
return solve(i+1,[2,1][p-1])
else:
return min(solve(i+1,1),solve(i+1,2))
else:
return 1+min(solve(i+1,1),solve(i+1,2))
print(solve(0))
``` | 0 |
|
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"input": "xulsyfkuizjauadjjopu",
"output": "526"
},
{
"input": "e",
"output": "51"
},
{
"input": "zv",
"output": "76"
},
{
"input": "jgv",
"output": "101"
},
{
"input": "zsfo",
"output": "126"
},
{
"input": "jselr",
"output": "151"
},
{
"input": "dwemig",
"output": "176"
},
{
"input": "mddoxsf",
"output": "201"
},
{
"input": "jgirkrmi",
"output": "226"
},
{
"input": "spkxurcum",
"output": "251"
},
{
"input": "fykkiubdkt",
"output": "276"
},
{
"input": "fznbcxsxygs",
"output": "301"
},
{
"input": "qcrvrdqcbtou",
"output": "326"
},
{
"input": "qktrbjzrqgmlr",
"output": "351"
},
{
"input": "foamodbvptlxxg",
"output": "376"
},
{
"input": "ydzpjhsidipricw",
"output": "401"
},
{
"input": "lpfpndmjfvqejdgf",
"output": "426"
},
{
"input": "ofkvparuvjtggnmab",
"output": "451"
},
{
"input": "xxncfutrtxcwdzwbgs",
"output": "476"
},
{
"input": "zovhffccflkgqncsdte",
"output": "501"
},
{
"input": "cskgsxywlvfeicoueglr",
"output": "526"
},
{
"input": "gggggggggggggggggggg",
"output": "526"
},
{
"input": "qdqdddqddqqddqddqdqd",
"output": "526"
},
{
"input": "takttttaakaaktakttkt",
"output": "526"
},
{
"input": "coccoooogogcgocccmcg",
"output": "526"
},
{
"input": "kskkskkkssksssk",
"output": "401"
},
{
"input": "lllllllllllllll",
"output": "401"
}
] | 1,503,941,747 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | s=input()
n=len(s)
print((n+1)*26-n) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Please help Haruhi solve this problem.
Input Specification:
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output Specification:
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
Demo Input:
['a\n', 'hi\n']
Demo Output:
['51\n', '76\n']
Note:
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | ```python
s=input()
n=len(s)
print((n+1)*26-n)
``` | 3 |
|
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors. | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors. | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
"input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3",
"output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50"
}
] | 1,696,171,377 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 296 | 33,280,000 | def get_pos(curr, strength_left, arrow):
l = curr
h = n - 1
while (l < h):
m = (l + h) // 2
strength_req = strength[m] - strength[curr] + strength_left
if strength_req > arrow:
h = m
elif strength_req == arrow:
return m
else:
if m == n - 1:
return m
l = m + 1
return l
n, minutes = map(int, input().split())
strength = [int(x) for x in input().split()]
arrows = [int(x) for x in input().split()]
res = [0] * minutes
for i in range(1, n):
strength[i] = strength[i] + strength[i - 1]
curr = 0
strength_left = strength[0]
for i in range(minutes):
arrow = arrows[i]
new_pos = get_pos(curr, strength_left, arrow)
temp = strength[new_pos] - strength[curr] + strength_left
if temp > arrow:
curr = new_pos
strength_left = temp - arrow
res[i] = n - curr
else:
curr = (new_pos + 1) % n
if curr:
strength_left = strength[curr] - strength[curr - 1]
else:
strength_left = strength[curr]
res[i] = n - curr
print(*res, sep='\n')
| Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
Input Specification:
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
Output Specification:
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
Demo Input:
['5 5\n1 2 1 2 1\n3 10 1 1 1\n', '4 4\n1 2 3 4\n9 1 10 6\n']
Demo Output:
['3\n5\n4\n4\n3\n', '1\n4\n4\n1\n']
Note:
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | ```python
def get_pos(curr, strength_left, arrow):
l = curr
h = n - 1
while (l < h):
m = (l + h) // 2
strength_req = strength[m] - strength[curr] + strength_left
if strength_req > arrow:
h = m
elif strength_req == arrow:
return m
else:
if m == n - 1:
return m
l = m + 1
return l
n, minutes = map(int, input().split())
strength = [int(x) for x in input().split()]
arrows = [int(x) for x in input().split()]
res = [0] * minutes
for i in range(1, n):
strength[i] = strength[i] + strength[i - 1]
curr = 0
strength_left = strength[0]
for i in range(minutes):
arrow = arrows[i]
new_pos = get_pos(curr, strength_left, arrow)
temp = strength[new_pos] - strength[curr] + strength_left
if temp > arrow:
curr = new_pos
strength_left = temp - arrow
res[i] = n - curr
else:
curr = (new_pos + 1) % n
if curr:
strength_left = strength[curr] - strength[curr - 1]
else:
strength_left = strength[curr]
res[i] = n - curr
print(*res, sep='\n')
``` | 3 |
|
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,658,166,179 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 61 | 0 | import math
n = int(input())
q = n/4
print(int(math.ceil(q) - 1) if n % 2 == 0 else 0)
| 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
import math
n = int(input())
q = n/4
print(int(math.ceil(q) - 1) if n % 2 == 0 else 0)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).
The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.
Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right. | 0 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"output": "8043 2940 R"
},
{
"input": "1 1 1",
"output": "1 1 L"
},
{
"input": "1 1 2",
"output": "1 1 R"
},
{
"input": "1 10000 1",
"output": "1 1 L"
},
{
"input": "1 10000 20000",
"output": "1 10000 R"
},
{
"input": "10000 1 1",
"output": "1 1 L"
},
{
"input": "10000 1 10000",
"output": "5000 1 R"
},
{
"input": "10000 1 20000",
"output": "10000 1 R"
},
{
"input": "3 2 1",
"output": "1 1 L"
},
{
"input": "3 2 2",
"output": "1 1 R"
},
{
"input": "3 2 3",
"output": "1 2 L"
},
{
"input": "3 2 4",
"output": "1 2 R"
},
{
"input": "3 2 5",
"output": "2 1 L"
},
{
"input": "3 2 6",
"output": "2 1 R"
},
{
"input": "3 2 7",
"output": "2 2 L"
},
{
"input": "3 2 8",
"output": "2 2 R"
},
{
"input": "3 2 9",
"output": "3 1 L"
},
{
"input": "3 2 10",
"output": "3 1 R"
},
{
"input": "3 2 11",
"output": "3 2 L"
},
{
"input": "3 2 12",
"output": "3 2 R"
},
{
"input": "300 2000 1068628",
"output": "268 314 R"
},
{
"input": "300 2000 584756",
"output": "147 378 R"
},
{
"input": "300 2000 268181",
"output": "68 91 L"
},
{
"input": "10000 9999 186450844",
"output": "9324 4745 R"
},
{
"input": "10000 9999 197114268",
"output": "9857 6990 R"
},
{
"input": "10000 9999 112390396",
"output": "5621 818 R"
},
{
"input": "10000 10000 1",
"output": "1 1 L"
},
{
"input": "10000 10000 2",
"output": "1 1 R"
},
{
"input": "10000 10000 100000001",
"output": "5001 1 L"
},
{
"input": "10000 10000 199999999",
"output": "10000 10000 L"
},
{
"input": "10000 10000 200000000",
"output": "10000 10000 R"
},
{
"input": "1 2 1",
"output": "1 1 L"
},
{
"input": "1 2 2",
"output": "1 1 R"
},
{
"input": "1 2 3",
"output": "1 2 L"
},
{
"input": "1 2 4",
"output": "1 2 R"
},
{
"input": "2 1 1",
"output": "1 1 L"
},
{
"input": "2 1 2",
"output": "1 1 R"
},
{
"input": "2 1 3",
"output": "2 1 L"
},
{
"input": "2 1 4",
"output": "2 1 R"
},
{
"input": "4 3 7",
"output": "2 1 L"
},
{
"input": "1 1 1",
"output": "1 1 L"
}
] | 1,680,794,351 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n, m, k = map(int, input().split())
print((k-1)//(2*n)+1, (k-1)%(2*n)//2+1, "RL"[k%2]) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).
The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.
Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
Input Specification:
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Output Specification:
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
Demo Input:
['4 3 9\n', '4 3 24\n', '2 4 4\n']
Demo Output:
['2 2 L\n', '4 3 R\n', '1 2 R\n']
Note:
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right. | ```python
n, m, k = map(int, input().split())
print((k-1)//(2*n)+1, (k-1)%(2*n)//2+1, "RL"[k%2])
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,678,754,383 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | message = str(input())
desired_message = ["h", "e", "l", "l", "o"]
pointer = 0
created_word = []
for char in desired_message:
while pointer < len(message):
if char == message[pointer]:
created_word.append(char)
pointer += 1
break
else:
pointer += 1
if created_word == desired_message:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
message = str(input())
desired_message = ["h", "e", "l", "l", "o"]
pointer = 0
created_word = []
for char in desired_message:
while pointer < len(message):
if char == message[pointer]:
created_word.append(char)
pointer += 1
break
else:
pointer += 1
if created_word == desired_message:
print("YES")
else:
print("NO")
``` | 3.969 |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence. | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 343 489 474 385 23 100 94 276",
"output": "-1"
},
{
"input": "62800\n867 936 2 888 474 530 287 822 220",
"output": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..."
},
{
"input": "27\n836 637 966 929 82 678 213 465 688",
"output": "-1"
},
{
"input": "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000",
"output": "9999999999"
},
{
"input": "898207\n99745 99746 99748 99752 99760 99776 99808 99872 100000",
"output": "987654321"
},
{
"input": "80910\n64537 83748 97081 82722 12334 3056 9491 59130 28478",
"output": "66666666666666666666666666"
},
{
"input": "120081\n11268 36403 73200 12674 83919 74218 74172 91581 68432",
"output": "4444411111"
},
{
"input": "839851\n29926 55862 57907 51153 56350 86145 1909 22622 89861",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "751233\n69761 51826 91095 73642 98995 93262 377 38818 97480",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "306978\n95955 99204 81786 41258 96065 46946 64532 36297 70808",
"output": "88888888"
},
{
"input": "366313\n18486 12701 92334 95391 61480 14118 20465 69784 13592",
"output": "9999999999922222222222222222"
},
{
"input": "320671\n95788 46450 97582 95928 47742 15508 10466 10301 38822",
"output": "8888888888888888888888888888888"
},
{
"input": "913928\n80373 47589 53204 68236 44060 97485 82241 44149 59825",
"output": "99888888888888855555"
},
{
"input": "630384\n19652 11530 20316 3161 87360 64207 74067 77894 81452",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "95\n22076 12056 63350 12443 43123 585 52908 18372 96799",
"output": "-1"
},
{
"input": "271380\n19135 80309 23783 48534 98990 37278 85258 67602 40288",
"output": "11111111111111"
},
{
"input": "80085\n56973 29725 30219 17439 53162 6051 41388 35555 39392",
"output": "6666666666666"
},
{
"input": "201332\n20008 22829 30296 1967 32154 67760 11437 90972 79865",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "3402\n64151 98148 81468 82342 48823 93464 5989 58868 77138",
"output": "-1"
},
{
"input": "432544\n95724 98294 23292 24174 57778 95072 81898 50019 86824",
"output": "444444444444444333"
},
{
"input": "1000000\n1 1 1 1 1 1 1 1 1",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..."
},
{
"input": "1000000\n2 2 2 2 2 2 2 2 2",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..."
},
{
"input": "1000000\n2 3 2 2 3 2 2 3 2",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..."
},
{
"input": "999999\n2 3 2 2 3 2 2 3 3",
"output": "9777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "153\n85 91 28 53 29 30 92 36 89",
"output": "86653"
},
{
"input": "26531\n64 93 48 49 86 57 93 60 96",
"output": "8864433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..."
},
{
"input": "17186\n50 90 76 51 91 54 71 90 73",
"output": "9666411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "11213\n51 82 49 50 99 52 69 96 85",
"output": "964433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "20075\n57 42 99 45 56 80 76 71 63",
"output": "954422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "21069\n31 19 49 30 28 43 21 25 28",
"output": "9872222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222..."
},
{
"input": "4822\n35 36 21 13 34 36 14 16 20",
"output": "9877444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
}
] | 1,618,707,857 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 248 | 409,600 | def paint(vLeft):
if vLeft in dp:
return dp[vLeft]
if vLeft < minDigitCost:
return ('', 0)
max_ = 0
for digit in range(9):
if vLeft >= digitCost[digit]:
temp = paint(vLeft%digitCost[digit])
if temp[1] + vLeft//digitCost[digit] >= max_:
max_ = temp[1] + vLeft//digitCost[digit]
dp[vLeft] = (str(digit+1)*(vLeft//digitCost[digit]) + temp[0], vLeft//digitCost[digit] + temp[1])
return dp[vLeft]
v = int(input())
digitCost = list(map(int, input().split()))
minDigitCost = min(digitCost)
dp = {}
ans = paint(v)
if ans[0]:
print(int(ans[0]))
else:
print(-1) | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence.
Input Specification:
The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
Demo Input:
['5\n5 4 3 2 1 2 3 4 5\n', '2\n9 11 1 12 5 8 9 10 6\n', '0\n1 1 1 1 1 1 1 1 1\n']
Demo Output:
['55555\n', '33\n', '-1\n']
Note:
none | ```python
def paint(vLeft):
if vLeft in dp:
return dp[vLeft]
if vLeft < minDigitCost:
return ('', 0)
max_ = 0
for digit in range(9):
if vLeft >= digitCost[digit]:
temp = paint(vLeft%digitCost[digit])
if temp[1] + vLeft//digitCost[digit] >= max_:
max_ = temp[1] + vLeft//digitCost[digit]
dp[vLeft] = (str(digit+1)*(vLeft//digitCost[digit]) + temp[0], vLeft//digitCost[digit] + temp[1])
return dp[vLeft]
v = int(input())
digitCost = list(map(int, input().split()))
minDigitCost = min(digitCost)
dp = {}
ans = paint(v)
if ans[0]:
print(int(ans[0]))
else:
print(-1)
``` | 0 |
|
505 | C | Mr. Kitayuta, the Treasure Hunter | PROGRAMMING | 1,900 | [
"dfs and similar",
"dp",
"two pointers"
] | null | null | The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are *n* gems in the Shuseki Islands in total, and the *i*-th gem is located on island *p**i*.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
- First, he will jump from island 0 to island *d*. - After that, he will continue jumping according to the following rule. Let *l* be the length of the previous jump, that is, if his previous jump was from island *prev* to island *cur*, let *l*<==<=*cur*<=-<=*prev*. He will perform a jump of length *l*<=-<=1, *l* or *l*<=+<=1 to the east. That is, he will jump to island (*cur*<=+<=*l*<=-<=1), (*cur*<=+<=*l*) or (*cur*<=+<=*l*<=+<=1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when *l*<==<=1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect. | The first line of the input contains two space-separated integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next *n* lines describe the location of the gems. The *i*-th of them (1<=≤<=*i*<=≤<=*n*) contains a integer *p**i* (*d*<=≤<=*p*1<=≤<=*p*2<=≤<=...<=≤<=*p**n*<=≤<=30000), denoting the number of the island that contains the *i*-th gem. | Print the maximum number of gems that Mr. Kitayuta can collect. | [
"4 10\n10\n21\n27\n27\n",
"8 8\n9\n19\n28\n36\n45\n55\n66\n78\n",
"13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30\n"
] | [
"3\n",
"6\n",
"4\n"
] | In the first sample, the optimal route is 0 → 10 (+1 gem) → 19 → 27 (+2 gems) → ...
In the second sample, the optimal route is 0 → 8 → 15 → 21 → 28 (+1 gem) → 36 (+1 gem) → 45 (+1 gem) → 55 (+1 gem) → 66 (+1 gem) → 78 (+1 gem) → ...
In the third sample, the optimal route is 0 → 7 → 13 → 18 (+1 gem) → 24 (+2 gems) → 30 (+1 gem) → ... | 1,500 | [
{
"input": "4 10\n10\n21\n27\n27",
"output": "3"
},
{
"input": "8 8\n9\n19\n28\n36\n45\n55\n66\n78",
"output": "6"
},
{
"input": "13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30",
"output": "4"
},
{
"input": "8 4\n9\n15\n15\n16\n22\n25\n25\n28",
"output": "8"
},
{
"input": "1 30000\n30000",
"output": "1"
},
{
"input": "1 12345\n23456",
"output": "0"
},
{
"input": "1 1\n30000",
"output": "1"
},
{
"input": "5 4\n4\n5\n9\n21\n25",
"output": "4"
},
{
"input": "8 7\n8\n15\n18\n19\n23\n24\n25\n27",
"output": "3"
},
{
"input": "11 15\n15\n18\n19\n19\n21\n23\n24\n26\n26\n29\n30",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "12 244\n448\n29889\n29890\n29891\n29892\n29893\n29894\n29895\n29896\n29897\n29898\n29899",
"output": "11"
},
{
"input": "1 1500\n1500",
"output": "1"
},
{
"input": "1 410\n30000",
"output": "1"
},
{
"input": "10 220\n29991\n29992\n29993\n29994\n29995\n29996\n29997\n29998\n29999\n30000",
"output": "10"
},
{
"input": "5 203\n29996\n29997\n29998\n29999\n30000",
"output": "5"
}
] | 1,679,810,414 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 389 | 62,976,000 | n, d = map(int, input().split())
# Read gem locations and store them in a set for fast lookup
gems = set()
for i in range(n):
p = int(input())
gems.add(p)
# Initialize dp array with -1
dp = [[-1] * 501 for _ in range(30001)]
def collect_gems(x, y):
# Base case: if x is beyond the last island or there are no more gems to collect
if x > 30000 or not gems:
return 0
# If the maximum number of gems for this island and jump length is already calculated, return that value
if dp[x][y] != -1:
return dp[x][y]
max_gems = 0
# Try all possible jump lengths between y-1 to y+1
for l in range(y-1, y+2):
if l <= 0:
continue
# Calculate the next island to jump to
next_island = x + l
# If the next island has a gem, remove it from the set of remaining gems and update the max gems
if next_island in gems:
gems.remove(next_island)
max_gems = max(max_gems, 1 + collect_gems(next_island, l))
gems.add(next_island) # Add the gem back to the set for backtracking
# Update dp array with the calculated maximum number of gems
dp[x][y] = max_gems
return max_gems
# Call collect_gems function to find the maximum number of gems that can be collected starting from island 0 with jump length d
print(collect_gems(d, d))
| Title: Mr. Kitayuta, the Treasure Hunter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are *n* gems in the Shuseki Islands in total, and the *i*-th gem is located on island *p**i*.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
- First, he will jump from island 0 to island *d*. - After that, he will continue jumping according to the following rule. Let *l* be the length of the previous jump, that is, if his previous jump was from island *prev* to island *cur*, let *l*<==<=*cur*<=-<=*prev*. He will perform a jump of length *l*<=-<=1, *l* or *l*<=+<=1 to the east. That is, he will jump to island (*cur*<=+<=*l*<=-<=1), (*cur*<=+<=*l*) or (*cur*<=+<=*l*<=+<=1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when *l*<==<=1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.
Input Specification:
The first line of the input contains two space-separated integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next *n* lines describe the location of the gems. The *i*-th of them (1<=≤<=*i*<=≤<=*n*) contains a integer *p**i* (*d*<=≤<=*p*1<=≤<=*p*2<=≤<=...<=≤<=*p**n*<=≤<=30000), denoting the number of the island that contains the *i*-th gem.
Output Specification:
Print the maximum number of gems that Mr. Kitayuta can collect.
Demo Input:
['4 10\n10\n21\n27\n27\n', '8 8\n9\n19\n28\n36\n45\n55\n66\n78\n', '13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30\n']
Demo Output:
['3\n', '6\n', '4\n']
Note:
In the first sample, the optimal route is 0 → 10 (+1 gem) → 19 → 27 (+2 gems) → ...
In the second sample, the optimal route is 0 → 8 → 15 → 21 → 28 (+1 gem) → 36 (+1 gem) → 45 (+1 gem) → 55 (+1 gem) → 66 (+1 gem) → 78 (+1 gem) → ...
In the third sample, the optimal route is 0 → 7 → 13 → 18 (+1 gem) → 24 (+2 gems) → 30 (+1 gem) → ... | ```python
n, d = map(int, input().split())
# Read gem locations and store them in a set for fast lookup
gems = set()
for i in range(n):
p = int(input())
gems.add(p)
# Initialize dp array with -1
dp = [[-1] * 501 for _ in range(30001)]
def collect_gems(x, y):
# Base case: if x is beyond the last island or there are no more gems to collect
if x > 30000 or not gems:
return 0
# If the maximum number of gems for this island and jump length is already calculated, return that value
if dp[x][y] != -1:
return dp[x][y]
max_gems = 0
# Try all possible jump lengths between y-1 to y+1
for l in range(y-1, y+2):
if l <= 0:
continue
# Calculate the next island to jump to
next_island = x + l
# If the next island has a gem, remove it from the set of remaining gems and update the max gems
if next_island in gems:
gems.remove(next_island)
max_gems = max(max_gems, 1 + collect_gems(next_island, l))
gems.add(next_island) # Add the gem back to the set for backtracking
# Update dp array with the calculated maximum number of gems
dp[x][y] = max_gems
return max_gems
# Call collect_gems function to find the maximum number of gems that can be collected starting from island 0 with jump length d
print(collect_gems(d, d))
``` | 0 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,666,239,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a,b = [int(x) for x in input().split(' ')]
import math
k = 7-max(a,b)
print(int(k/math.gcd(k,6)),'/',int(6/math.gcd(k,6))) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
a,b = [int(x) for x in input().split(' ')]
import math
k = 7-max(a,b)
print(int(k/math.gcd(k,6)),'/',int(6/math.gcd(k,6)))
``` | 0 |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 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 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 1,437,434,400 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
a = [int(x) for x in input().split()]
print(max([min([a[i+1]-a[i] for i in range(n-2)])] + [a[i+1]-a[i] for i in range(n-1)]))
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
Input Specification:
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output Specification:
Print a single number — the minimum difficulty of the track after removing a single hold.
Demo Input:
['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n']
Demo Output:
['5\n', '2\n', '4\n']
Note:
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | ```python
n = int(input())
a = [int(x) for x in input().split()]
print(max([min([a[i+1]-a[i] for i in range(n-2)])] + [a[i+1]-a[i] for i in range(n-1)]))
``` | 0 |
|
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 45 45 45 45 45 45 45",
"output": "0"
},
{
"input": "3\n120 120 120",
"output": "120"
},
{
"input": "5\n110 90 70 50 40",
"output": "40"
},
{
"input": "2\n170 190",
"output": "20"
},
{
"input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10",
"output": "10"
},
{
"input": "5\n30 60 180 60 30",
"output": "0"
},
{
"input": "2\n359 1",
"output": "358"
},
{
"input": "5\n100 100 30 100 30",
"output": "40"
},
{
"input": "5\n36 34 35 11 244",
"output": "128"
},
{
"input": "5\n96 94 95 71 4",
"output": "18"
},
{
"input": "2\n85 275",
"output": "190"
},
{
"input": "3\n281 67 12",
"output": "202"
},
{
"input": "5\n211 113 25 9 2",
"output": "62"
},
{
"input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1",
"output": "212"
},
{
"input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "92"
},
{
"input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 358",
"output": "356"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341",
"output": "322"
},
{
"input": "33\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 328",
"output": "296"
},
{
"input": "70\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 291",
"output": "222"
},
{
"input": "130\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231",
"output": "102"
},
{
"input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161",
"output": "0"
},
{
"input": "222\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139",
"output": "0"
},
{
"input": "10\n8 3 11 4 1 10 10 1 8 304",
"output": "248"
},
{
"input": "12\n8 7 7 3 11 2 10 1 10 8 10 283",
"output": "206"
},
{
"input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275",
"output": "190"
},
{
"input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280",
"output": "200"
},
{
"input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275",
"output": "190"
},
{
"input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189",
"output": "18"
},
{
"input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189",
"output": "18"
},
{
"input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168",
"output": "0"
},
{
"input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5",
"output": "0"
},
{
"input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68",
"output": "0"
},
{
"input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "6\n27 15 28 34 41 215",
"output": "70"
},
{
"input": "7\n41 38 41 31 22 41 146",
"output": "14"
},
{
"input": "8\n24 27 34 23 29 23 30 170",
"output": "20"
},
{
"input": "9\n11 11 20 20 33 32 35 26 172",
"output": "6"
},
{
"input": "10\n36 13 28 13 33 34 23 25 34 121",
"output": "0"
},
{
"input": "11\n19 37 13 41 37 15 32 12 19 35 100",
"output": "10"
},
{
"input": "12\n37 25 34 38 21 24 34 38 11 29 28 41",
"output": "2"
},
{
"input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28",
"output": "2"
},
{
"input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44",
"output": "4"
},
{
"input": "3\n95 91 174",
"output": "12"
},
{
"input": "4\n82 75 78 125",
"output": "46"
},
{
"input": "6\n87 75 88 94 15 1",
"output": "4"
},
{
"input": "10\n27 52 58 64 45 64 1 19 2 28",
"output": "12"
},
{
"input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1",
"output": "0"
},
{
"input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3",
"output": "0"
},
{
"input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1",
"output": "0"
},
{
"input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2",
"output": "0"
},
{
"input": "5\n35 80 45 100 100",
"output": "40"
},
{
"input": "4\n90 179 90 1",
"output": "2"
},
{
"input": "5\n50 50 20 160 80",
"output": "0"
},
{
"input": "5\n30 175 30 5 120",
"output": "10"
},
{
"input": "4\n170 30 10 150",
"output": "20"
},
{
"input": "6\n90 30 90 30 90 30",
"output": "60"
},
{
"input": "4\n70 80 110 100",
"output": "20"
},
{
"input": "7\n35 45 70 100 10 10 90",
"output": "0"
},
{
"input": "6\n50 90 10 90 20 100",
"output": "20"
},
{
"input": "6\n10 155 162 1 26 6",
"output": "18"
},
{
"input": "7\n80 90 80 45 10 10 45",
"output": "20"
},
{
"input": "4\n18 36 162 144",
"output": "36"
},
{
"input": "5\n20 50 50 160 80",
"output": "40"
},
{
"input": "5\n10 30 140 20 160",
"output": "0"
},
{
"input": "6\n90 80 60 50 40 40",
"output": "20"
},
{
"input": "9\n40 20 20 20 20 20 20 40 160",
"output": "40"
},
{
"input": "4\n90 54 90 126",
"output": "72"
},
{
"input": "4\n150 170 30 10",
"output": "20"
},
{
"input": "8\n130 12 13 85 41 67 5 7",
"output": "26"
},
{
"input": "7\n70 170 20 10 30 30 30",
"output": "20"
},
{
"input": "8\n100 100 50 50 15 15 15 15",
"output": "40"
},
{
"input": "4\n100 70 80 110",
"output": "20"
},
{
"input": "5\n160 130 40 20 10",
"output": "20"
},
{
"input": "4\n20 149 151 40",
"output": "22"
},
{
"input": "4\n100 10 100 150",
"output": "60"
},
{
"input": "6\n19 64 105 168 1 3",
"output": "16"
},
{
"input": "8\n10 10 70 70 90 90 10 10",
"output": "0"
}
] | 1,511,718,407 | 6,107 | PyPy 3 | WRONG_ANSWER | PRETESTS | 7 | 109 | 23,142,400 | n = int(input())
ar = input().split(" ")
ar = [int(i) for i in ar]
ar.sort()
lala = [ar[0]]
ar = ar[1:]
while(len(ar) != 0):
now = []
for i in lala:
now.append(i+ar[0])
lala += now
lala = list(set(lala))
ar = ar[1:]
# print(ar)
ans = 360
for i in lala:
ans = min(ans,abs(360-2*i))
print(ans)
| Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Output Specification:
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
Demo Input:
['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n']
Demo Output:
['0\n', '40\n', '360\n', '0\n']
Note:
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | ```python
n = int(input())
ar = input().split(" ")
ar = [int(i) for i in ar]
ar.sort()
lala = [ar[0]]
ar = ar[1:]
while(len(ar) != 0):
now = []
for i in lala:
now.append(i+ar[0])
lala += now
lala = list(set(lala))
ar = ar[1:]
# print(ar)
ans = 360
for i in lala:
ans = min(ans,abs(360-2*i))
print(ans)
``` | 0 |
|
534 | C | Polycarpus' Dice | PROGRAMMING | 1,600 | [
"math"
] | null | null | Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*. | The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show. | Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. | [
"2 8\n4 4\n",
"1 3\n5\n",
"2 3\n2 3\n"
] | [
"3 3 ",
"4 ",
"0 1 "
] | In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | 1,500 | [
{
"input": "2 8\n4 4",
"output": "3 3 "
},
{
"input": "1 3\n5",
"output": "4 "
},
{
"input": "2 3\n2 3",
"output": "0 1 "
},
{
"input": "1 1\n3",
"output": "2 "
},
{
"input": "1 2\n3",
"output": "2 "
},
{
"input": "2 2\n2 3",
"output": "1 2 "
},
{
"input": "2 4\n2 3",
"output": "0 1 "
},
{
"input": "3 3\n5 1 5",
"output": "4 0 4 "
},
{
"input": "3 4\n5 1 5",
"output": "3 0 3 "
},
{
"input": "3 5\n5 1 5",
"output": "2 0 2 "
},
{
"input": "3 6\n5 1 5",
"output": "1 0 1 "
},
{
"input": "3 7\n5 1 5",
"output": "0 0 0 "
},
{
"input": "3 8\n5 1 5",
"output": "1 0 1 "
},
{
"input": "3 5\n1 2 100",
"output": "0 0 98 "
},
{
"input": "10 20\n1 1 1 1 5 100 1 1 1 1",
"output": "0 0 0 0 0 95 0 0 0 0 "
},
{
"input": "5 50\n1 1 1 1 1000000",
"output": "0 0 0 0 999999 "
},
{
"input": "5 50\n2 2 2 2 1000000",
"output": "0 0 0 0 999995 "
},
{
"input": "5 50\n10 10 10 10 1000000",
"output": "0 0 0 0 999963 "
},
{
"input": "10 19\n1 5 6 1 6 4 1 2 9 5",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10 40\n1 5 6 1 6 4 1 2 9 5",
"output": "0 4 5 0 5 3 0 1 8 4 "
},
{
"input": "10 16\n5 7 7 5 9 3 8 5 7 2",
"output": "0 0 0 0 2 0 1 0 0 0 "
},
{
"input": "10 58\n5 7 7 5 9 3 8 5 7 2",
"output": "4 6 6 4 8 2 7 4 6 1 "
},
{
"input": "10 13\n9 9 6 9 10 4 5 10 8 9",
"output": "5 5 2 5 6 0 1 6 4 5 "
},
{
"input": "10 79\n9 9 6 9 10 4 5 10 8 9",
"output": "8 8 5 8 9 3 4 9 7 8 "
},
{
"input": "10 16\n4 1 8 3 3 3 4 3 6 6",
"output": "0 0 1 0 0 0 0 0 0 0 "
},
{
"input": "10 41\n4 1 8 3 3 3 4 3 6 6",
"output": "3 0 7 2 2 2 3 2 5 5 "
},
{
"input": "10 18\n8 1 9 8 4 1 1 8 6 2",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10 48\n8 1 9 8 4 1 1 8 6 2",
"output": "7 0 8 7 3 0 0 7 5 1 "
},
{
"input": "1 5\n5",
"output": "4 "
}
] | 1,680,321,642 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 102,400 | import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
# for _ in range(int(input())):
n,k=get_ints()
a=get_array()
s=sum(a)
for i in range(n):
if s-a[i]>=k:
print(0,end=' ')
else:
ran=[k-(s-a[i]),min(a[i],k-n+1)]
# print(ran)
print(a[i]-(ran[1]-ran[0]+1),end=' ') | Title: Polycarpus' Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*.
Input Specification:
The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show.
Output Specification:
Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them.
Demo Input:
['2 8\n4 4\n', '1 3\n5\n', '2 3\n2 3\n']
Demo Output:
['3 3 ', '4 ', '0 1 ']
Note:
In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | ```python
import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
# for _ in range(int(input())):
n,k=get_ints()
a=get_array()
s=sum(a)
for i in range(n):
if s-a[i]>=k:
print(0,end=' ')
else:
ran=[k-(s-a[i]),min(a[i],k-n+1)]
# print(ran)
print(a[i]-(ran[1]-ran[0]+1),end=' ')
``` | 0 |
|
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$). | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010",
"output": "Yes"
},
{
"input": "4\n0100",
"output": "No"
},
{
"input": "42\n011000100101001001101011011010100010011010",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "64\n1001001010010010100101010010010100100101001001001001010100101001",
"output": "Yes"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0000",
"output": "No"
},
{
"input": "4\n0001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "4\n0011",
"output": "No"
},
{
"input": "4\n0101",
"output": "Yes"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "4\n0111",
"output": "No"
},
{
"input": "4\n1000",
"output": "No"
},
{
"input": "4\n1001",
"output": "Yes"
},
{
"input": "4\n1010",
"output": "Yes"
},
{
"input": "4\n1100",
"output": "No"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "4\n1110",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "3\n000",
"output": "No"
},
{
"input": "3\n010",
"output": "Yes"
},
{
"input": "3\n011",
"output": "No"
},
{
"input": "3\n100",
"output": "No"
},
{
"input": "3\n110",
"output": "No"
},
{
"input": "100\n0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110",
"output": "No"
},
{
"input": "357\n100101010010010010010100101001001010101010100100100100101001010101001010010100101001010100101001010010100100101001010101010101001001010100101010010100101001010100100100101010010010010100101010010010101001010010010101001001010010010101010100100101010010100100101001010100101001010100101001010010010010100101001010100100100100100100100101010101010010010100101",
"output": "Yes"
},
{
"input": "459\n000111000101010000100001001010111110011011010001100101111010111011101110111101111101100101100011011001100110001001111001101000111001011100110100011111011111000010000110010011100110011011111110011100001101001111000100111011001000001011111100110100001001001100101011100001110110100101011011110100100111101011000101110000100110100100010000000100001001111111000011101010010011001111010111001100000100111001010111011010000011000011100101101011101000011011000110011",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "15\n000010101010000",
"output": "No"
},
{
"input": "8\n10010100",
"output": "No"
},
{
"input": "5\n00100",
"output": "No"
},
{
"input": "6\n100100",
"output": "No"
},
{
"input": "7\n1000001",
"output": "No"
},
{
"input": "98\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "Yes"
}
] | 1,528,999,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n = int(input())
s = input()
a, b = '', ''
for i in range(n):
if i % 2 == 0:
a += '1'
b += '0'
else:
a += '0'
b += '1'
if s == a or s == b:
print("Yes")
else:
print("No") | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$).
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output Specification:
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
Demo Input:
['3\n101\n', '4\n1011\n', '5\n10001\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | ```python
n = int(input())
s = input()
a, b = '', ''
for i in range(n):
if i % 2 == 0:
a += '1'
b += '0'
else:
a += '0'
b += '1'
if s == a or s == b:
print("Yes")
else:
print("No")
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,542,456,772 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | m = list(input())
n = list(input())
z = [0 for i in range(len(n))]
for i in range(len(n)):
if m[i] == n[i]:
z[i] = 0
else:
z[i] = 1
print(*z,sep="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
m = list(input())
n = list(input())
z = [0 for i in range(len(n))]
for i in range(len(n)):
if m[i] == n[i]:
z[i] = 0
else:
z[i] = 1
print(*z,sep="")
``` | 3.969 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game. | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "41 12 65",
"output": "1"
},
{
"input": "13 61 100",
"output": "1"
},
{
"input": "100 100 10",
"output": "0"
},
{
"input": "12 24 26",
"output": "1"
},
{
"input": "73 21 96",
"output": "1"
},
{
"input": "17 22 81",
"output": "1"
},
{
"input": "14 88 97",
"output": "1"
},
{
"input": "42 81 17",
"output": "0"
},
{
"input": "34 36 19",
"output": "1"
},
{
"input": "21 87 12",
"output": "1"
},
{
"input": "97 92 98",
"output": "1"
},
{
"input": "49 25 62",
"output": "1"
},
{
"input": "29 17 44",
"output": "1"
},
{
"input": "10 1 10",
"output": "0"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "100 100 1",
"output": "0"
},
{
"input": "11 99 55",
"output": "0"
},
{
"input": "8 13 21",
"output": "0"
},
{
"input": "34 55 89",
"output": "0"
},
{
"input": "21 34 55",
"output": "1"
},
{
"input": "13 21 34",
"output": "1"
},
{
"input": "34 21 55",
"output": "0"
},
{
"input": "10 20 84",
"output": "1"
},
{
"input": "4 2 5",
"output": "0"
},
{
"input": "3 2 3",
"output": "0"
},
{
"input": "31 23 1",
"output": "0"
},
{
"input": "100 100 100",
"output": "0"
},
{
"input": "100 1 100",
"output": "0"
},
{
"input": "1 100 100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "17 23 100",
"output": "1"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "1 1 2",
"output": "1"
},
{
"input": "2 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "10 10 3",
"output": "1"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "9 5 1",
"output": "0"
}
] | 1,544,620,545 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | import math
a , b, n= [int(i) for i in input().split()]
ans = False
while True:
if ans == False:
g = math.gcd(a,n)
n -=g
if n <=0:
print(int(ans))
break
ans = not ans
else:
g = math.gcd(b,n)
n -=g
if n <=0:
print(int(ans))
break
ans = not ans | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game.
Input Specification:
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output Specification:
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Demo Input:
['3 5 9\n', '1 1 100\n']
Demo Output:
['0', '1']
Note:
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | ```python
import math
a , b, n= [int(i) for i in input().split()]
ans = False
while True:
if ans == False:
g = math.gcd(a,n)
n -=g
if n <=0:
print(int(ans))
break
ans = not ans
else:
g = math.gcd(b,n)
n -=g
if n <=0:
print(int(ans))
break
ans = not ans
``` | 3 |
|
448 | B | Suffix Structures | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order. | The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters. | In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton. | [
"automaton\ntomat\n",
"array\narary\n",
"both\nhot\n",
"need\ntree\n"
] | [
"automaton\n",
"array\n",
"both\n",
"need tree\n"
] | In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | 1,000 | [
{
"input": "automaton\ntomat",
"output": "automaton"
},
{
"input": "array\narary",
"output": "array"
},
{
"input": "both\nhot",
"output": "both"
},
{
"input": "need\ntree",
"output": "need tree"
},
{
"input": "abacaba\naaaa",
"output": "automaton"
},
{
"input": "z\nzz",
"output": "need tree"
},
{
"input": "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet",
"output": "need tree"
},
{
"input": "y\nu",
"output": "need tree"
},
{
"input": "nbjigpsbammkuuqrxfnmhtimwpflrflehffykbylmnxgadldchdbqklqbremcmzlpxieozgpfgrhegmdcxxfyehzzelcwgkierrj\nbjbakuqrnhimwhffykylmngadhbqkqbrcziefredxxezcgkerj",
"output": "automaton"
},
{
"input": "gzvvawianfysfuxhruarhverinqsbrfxvkcsermuzowahevgskmpvfdljtcztnbkzftfhvnarvkfkqjgrzbrcfthqmspvpqcva\nwnm",
"output": "automaton"
},
{
"input": "dvzohfzgzdjavqwhjcrdphpdqjwtqijabbrhformstqaonlhbglmxugkwviigqaohwvqfhdwwcvdkjrcgxblhvtashhcxssbvpo\nzgvqhpjhforlugkwfwrchvhp",
"output": "automaton"
},
{
"input": "wkfoyetcjivofxaktmauapzeuhcpzjloszzxwydgavebgniiuzrscytsokjkjfkpylvxtlqlquzduywbhqdzmtwprfdohmwgmysy\ny",
"output": "automaton"
},
{
"input": "npeidcoiulxdxzjozsonkdwnoazsbntfclnpubgweaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf\nnpeidcoiulxdxzjozsonkdwnoazsbntfclnpubgeaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf",
"output": "automaton"
},
{
"input": "gahcqpgmypeahjcwkzahnhmsmxosnikucqwyzklbfwtujjlzvwklqzxakcrcqalhsvsgvknpxsoqkjnyjkypfsiogbcaxjyugeet\ngahcqpgmypeahjwwkzahnhmsmxopnikucacyzklbfwtujjlzvwkoqzxakcrcqqlhsvsgvknpxslgkjnyjkysfoisqbcaxjyuteeg",
"output": "array"
},
{
"input": "vwesbxsifsjqapwridrenumrukgemlldpbtdhxivsrmzbgprtkqgaryniudkjgpjndluwxuohwwysmyuxyrulwsodgunzirudgtx\nugeabdszfshqsksddireguvsukieqlluhngdpxjvwwnzdrtrtrdjiuxgadtgjpxrmlynspyyryngxuiibrmurwpmoxwwuklbwumo",
"output": "array"
},
{
"input": "kjnohlseyntrslfssrshjxclzlsbkfzfwwwgyxsysvmfkxugdwjodfyxhdsveruoioutwmtcbaljomaorvzjsbmglqckmsyieeiu\netihhycsjgdysowuljmaoksoecxawsgsljofkrjftuweidrkwtymyswdlilsozsxevfbformnbsumlxzqzykjvsnrlxufvgbmshc",
"output": "array"
},
{
"input": "ezbpsylkfztypqrefinexshtgglmkoinrktkloitqhfkivoabrfrivvqrcxkjckzvcozpchhiodrbbxuhnwcjigftnrjfiqyxakh\niacxghqffzdbsiqunhxbiooqvfohzticjpvrzykcrlrxklgknyrkrhjxcetmfocierekatfvkbslkkrbhftwngoijpipvqyznthi",
"output": "array"
},
{
"input": "smywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhuqqcttokbljfbppdinzqgdupkfevmke\nsmywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhufqcttokbljfbppdinzqgdupkqevmke",
"output": "array"
},
{
"input": "hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghposgyfeslzumaovfkallszzumztftgpcilwfrzpvhhbgdzdvnmseqywlzmhhoxh\ndbelhtzgkssyfrqgzuurdjhwvmdbhylhmvphjgxpzhxbb",
"output": "both"
},
{
"input": "nppjzscfgcvdcnsjtiaudvutmgswqbewejlzibczzowgkdrjgxrpirfdaekvngcsonroheepdoeoeevaullbfwprcnhlxextbxpd\nifilrvacohnwcgzuleicucebrfxphosrgwnglxxkqrcorsxegjoppbb",
"output": "both"
},
{
"input": "ggzmtrhkpdswwqgcbtviahqrgzhyhzddtdekchrpjgngupitzyyuipwstgzewktcqpwezidwvvxgjixnflpjhfznokmpbyzczrzk\ngpgwhtzrcytstezmhettkppgmvxlxqnkjzibiqdtceczkbfhdziuajwjqzgwnhnkdzizprgzwud",
"output": "both"
},
{
"input": "iypjqiiqxhtinlmywpetgqqsdopxhghthjopgbodkwrdxzaaxmtaqcfuiarhrvasusanklzcqaytdyzndakcpljqupowompjjved\nhxeatriypptbhnokarhgqdrkqkypqzdttixphngmpqjodzjqlmcztyjfgoswjelwwdaqdjayavsdocuhqsluxaaopniviaumxip",
"output": "both"
},
{
"input": "ypyhyabmljukejpltkgunwuanhxblhiouyltdiczttndrhdprqtlpfanmzlyzbqanfwfyurxhepuzspdvehxnblhajczqcxlqebx\nlladxuucky",
"output": "both"
},
{
"input": "ddmgoarkuhknbtjggnomyxvvavobmylixwuxnnsdrrbibitoteaiydptnvtfblathihflefuggfnyayniragbtkommycpdyhft\ntejwybmyrhmalraptqwhghsckvnnaagtmzhnpwbhzzgfgritqwqqamgssllnicjqdkivrwaqyxngsqopwieljfxcdywjaal",
"output": "need tree"
},
{
"input": "kipjuscf\nkbwfqfwuvkyhmvnaznzsgdgdnpipikbicmlcwehjirmhgwpxwpgfztqjwfqfaapmsgskr",
"output": "need tree"
},
{
"input": "kobhhrqgwbgqkzcoacrhpkegyepzfds\nhlwcgbvvlegoyrcrjhsjywpdnccxtzgmeujxciuwjlnefllwldidlnjswmetkarxqjigokfvmpxpzfxarhkpdcia",
"output": "need tree"
},
{
"input": "lllolloloolllloolollololololollllooololoooloooolololloolloollllolloolloooooooololllolllolllloolllool\nlollollololololooooloooooooooolloolllololooollllol",
"output": "automaton"
},
{
"input": "lloloooolooollololloooloololooollooloollolllloolllllllloollollllolooloollloololollllooloooololooolol\nlooooollooolllololloollooooololollollloloollollolo",
"output": "both"
},
{
"input": "yyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxyxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx\nyyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxxxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx",
"output": "need tree"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "automaton"
},
{
"input": "abracadabra\nlol",
"output": "need tree"
},
{
"input": "abc\naa",
"output": "need tree"
},
{
"input": "ba\naa",
"output": "need tree"
},
{
"input": "abbb\naaab",
"output": "need tree"
},
{
"input": "baaa\nbb",
"output": "need tree"
},
{
"input": "boosss\nosos",
"output": "both"
}
] | 1,643,451,745 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 77 | 0 | def main():
s = input()
t = input()
ans_list = ['automaton', 'array', 'both', 'need tree']
ans = ''
if s == t:
ans = ans_list[0]
elif sorted(s) == sorted(t):
ans = ans_list[1]
elif len(s) < len(t):
ans = ans_list[3]
if ans != '':
print(ans)
return
ls = [0 for _ in range(26)]
lt = ls.copy()
for c in s:
ls[ord(c) - ord('a')] += 1
for c in t:
lt[ord(c) - ord('a')] += 1
chk = True
for i in range(26):
if ls[i] < lt[i]:
chk = False
if not chk:
print(ans_list[3])
return
x, y, n, m = 0, 0, len(s), len(t)
while y < m:
while x < n:
x += 1
if s[x-1] == t[y]:
y += 1
break
if x == n:
break
if y < m:
print(ans_list[2])
else:
print(ans_list[0])
if __name__ == '__main__':
main() | Title: Suffix Structures
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
Input Specification:
The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
Output Specification:
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
Demo Input:
['automaton\ntomat\n', 'array\narary\n', 'both\nhot\n', 'need\ntree\n']
Demo Output:
['automaton\n', 'array\n', 'both\n', 'need tree\n']
Note:
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | ```python
def main():
s = input()
t = input()
ans_list = ['automaton', 'array', 'both', 'need tree']
ans = ''
if s == t:
ans = ans_list[0]
elif sorted(s) == sorted(t):
ans = ans_list[1]
elif len(s) < len(t):
ans = ans_list[3]
if ans != '':
print(ans)
return
ls = [0 for _ in range(26)]
lt = ls.copy()
for c in s:
ls[ord(c) - ord('a')] += 1
for c in t:
lt[ord(c) - ord('a')] += 1
chk = True
for i in range(26):
if ls[i] < lt[i]:
chk = False
if not chk:
print(ans_list[3])
return
x, y, n, m = 0, 0, len(s), len(t)
while y < m:
while x < n:
x += 1
if s[x-1] == t[y]:
y += 1
break
if x == n:
break
if y < m:
print(ans_list[2])
else:
print(ans_list[0])
if __name__ == '__main__':
main()
``` | 3 |
|
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,616,473,861 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 187 | 10,444,800 | def main():
n,b,d = input().split()
n = int(n)
b = int(b)
d = int(d)
arr = list(map(int, input().split()))
total = 0
count = 0
for j in arr:
if j <= b:
total += j
if total > d:
count += 1
total = 0
print(count)
main() | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
def main():
n,b,d = input().split()
n = int(n)
b = int(b)
d = int(d)
arr = list(map(int, input().split()))
total = 0
count = 0
for j in arr:
if j <= b:
total += j
if total > d:
count += 1
total = 0
print(count)
main()
``` | 3 |
|
930 | A | Peculiar apple-tree | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=><=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=<<=*i*.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest. | First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000) — number of inflorescences.
Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down. | Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. | [
"3\n1 1\n",
"5\n1 2 2 2\n",
"18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n"
] | [
"1\n",
"3\n",
"4\n"
] | In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | 500 | [
{
"input": "3\n1 1",
"output": "1"
},
{
"input": "5\n1 2 2 2",
"output": "3"
},
{
"input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4",
"output": "4"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "20\n1 1 1 1 1 4 1 2 4 1 2 1 7 1 2 2 9 7 1",
"output": "2"
},
{
"input": "20\n1 2 1 2 2 1 2 4 1 6 2 2 4 3 2 6 2 5 9",
"output": "2"
},
{
"input": "20\n1 1 1 4 2 4 3 1 2 8 3 2 11 13 15 1 12 13 12",
"output": "4"
},
{
"input": "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15",
"output": "4"
},
{
"input": "20\n1 2 3 4 5 6 7 8 9 6 11 12 12 7 13 15 16 11 13",
"output": "8"
},
{
"input": "10\n1 1 1 2 1 3 4 2 1",
"output": "2"
},
{
"input": "30\n1 1 1 2 1 2 1 1 2 1 1 1 2 2 4 3 6 2 3 5 3 4 11 5 3 3 4 7 6",
"output": "4"
},
{
"input": "40\n1 1 1 1 1 1 1 1 1 3 4 3 3 1 3 6 7 4 5 2 4 3 9 1 4 2 5 3 5 9 5 9 10 12 3 7 2 11 1",
"output": "2"
},
{
"input": "50\n1 1 1 1 1 2 3 3 2 1 1 2 3 1 3 1 5 6 4 1 1 2 1 2 1 10 17 2 2 4 12 9 6 6 5 13 1 3 2 8 25 3 22 1 10 13 6 3 2",
"output": "4"
},
{
"input": "10\n1 1 1 1 2 1 3 4 3",
"output": "2"
},
{
"input": "30\n1 2 1 1 1 2 1 4 2 3 9 2 3 2 1 1 4 3 12 4 8 8 3 7 9 1 9 19 1",
"output": "2"
},
{
"input": "40\n1 1 1 2 3 1 2 1 3 7 1 3 4 3 2 3 4 1 2 2 4 1 7 4 1 3 2 1 4 5 3 10 14 11 10 13 8 7 4",
"output": "2"
},
{
"input": "50\n1 2 1 1 1 3 1 3 1 5 3 2 7 3 6 6 3 1 4 2 3 10 8 9 1 4 5 2 8 6 12 9 7 5 7 19 3 15 10 4 12 4 19 5 16 5 3 13 5",
"output": "2"
},
{
"input": "10\n1 1 1 2 3 2 1 2 3",
"output": "2"
},
{
"input": "30\n1 1 1 1 2 1 4 4 2 3 2 1 1 1 1 3 1 1 3 2 3 5 1 2 9 16 2 4 3",
"output": "2"
},
{
"input": "40\n1 1 1 2 1 2 1 2 4 8 1 7 1 6 2 8 2 12 4 11 5 5 15 3 12 11 22 11 13 13 24 6 10 15 3 6 7 1 2",
"output": "2"
},
{
"input": "50\n1 1 1 1 3 4 1 2 3 5 1 2 1 5 1 10 4 11 1 8 8 4 4 12 5 3 4 1 1 2 5 13 13 2 2 10 12 3 19 14 1 1 15 3 23 21 12 3 14",
"output": "4"
},
{
"input": "10\n1 1 1 1 2 4 1 1 3",
"output": "2"
},
{
"input": "30\n1 1 1 1 3 3 2 3 7 4 1 2 4 6 2 8 1 2 13 7 5 15 3 3 8 4 4 18 3",
"output": "2"
},
{
"input": "40\n1 1 1 2 2 1 1 4 6 4 7 7 7 4 4 8 10 7 5 1 5 13 7 8 2 11 18 2 1 20 7 3 12 16 2 22 4 22 14",
"output": "4"
},
{
"input": "50\n1 1 1 2 2 1 3 5 3 1 9 4 4 2 12 15 3 13 8 8 4 13 20 17 19 2 4 3 9 5 17 9 17 1 5 7 6 5 20 11 31 33 32 20 6 25 1 2 6",
"output": "4"
},
{
"input": "10\n1 1 1 3 3 5 6 8 3",
"output": "4"
},
{
"input": "30\n1 2 2 1 5 5 5 1 7 4 10 2 4 11 2 3 10 10 7 13 12 4 10 3 22 25 8 1 1",
"output": "6"
},
{
"input": "40\n1 2 2 2 2 4 2 2 6 9 3 9 9 9 3 5 7 7 2 17 4 4 8 8 25 18 12 27 8 19 26 15 33 26 33 9 24 4 27",
"output": "4"
},
{
"input": "50\n1 1 3 3 4 5 5 2 4 3 9 9 1 5 5 7 5 5 16 1 18 3 6 5 6 13 26 12 23 20 17 21 9 17 19 34 12 24 11 9 32 10 40 42 7 40 11 25 3",
"output": "6"
},
{
"input": "10\n1 2 1 2 5 5 6 6 6",
"output": "2"
},
{
"input": "30\n1 1 3 3 5 6 7 5 7 6 5 4 8 6 10 12 14 9 15 20 6 21 14 24 17 23 23 18 8",
"output": "2"
},
{
"input": "40\n1 2 2 3 1 2 5 6 4 8 11 12 9 5 12 7 4 16 16 15 6 22 17 24 10 8 22 4 27 9 19 23 16 18 28 22 5 35 19",
"output": "4"
},
{
"input": "50\n1 2 3 4 5 5 5 7 1 2 11 5 7 11 11 11 15 3 17 10 6 18 14 14 24 11 10 7 17 18 8 7 19 18 31 27 21 30 34 32 27 39 38 22 32 23 31 48 25",
"output": "2"
},
{
"input": "10\n1 2 2 4 5 5 6 4 7",
"output": "2"
},
{
"input": "30\n1 2 3 3 5 6 3 8 9 10 10 10 11 7 8 8 15 16 13 13 19 12 15 18 18 24 27 25 10",
"output": "6"
},
{
"input": "40\n1 2 3 4 5 6 6 8 7 10 11 3 12 11 15 12 17 15 10 20 16 20 12 20 15 21 20 26 29 23 29 30 23 24 35 33 25 32 36",
"output": "8"
},
{
"input": "50\n1 2 2 2 5 6 7 7 9 10 7 4 5 4 15 15 16 17 10 19 18 16 15 24 20 8 27 16 19 24 23 32 17 23 29 18 35 35 38 35 39 41 42 38 19 46 38 28 29",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 5 5 7 9",
"output": "8"
},
{
"input": "30\n1 2 3 4 5 6 5 3 6 7 8 11 12 13 15 15 13 13 19 10 14 10 15 23 21 9 27 22 28",
"output": "4"
},
{
"input": "40\n1 2 2 3 3 6 5 5 9 7 8 11 13 7 10 10 16 14 18 20 11 19 23 18 20 21 25 16 29 25 27 31 26 34 33 23 36 33 32",
"output": "6"
},
{
"input": "50\n1 2 2 4 5 5 7 6 9 10 11 12 13 7 14 15 14 17 10 14 9 21 23 23 19 26 19 25 11 24 22 27 26 34 35 30 37 31 38 32 40 32 42 44 37 21 40 40 48",
"output": "10"
},
{
"input": "10\n1 2 3 4 3 6 6 6 7",
"output": "4"
},
{
"input": "30\n1 2 2 4 5 6 5 7 9 6 4 12 7 14 12 12 15 17 13 12 8 20 21 15 17 24 21 19 16",
"output": "4"
},
{
"input": "40\n1 2 3 4 4 6 6 4 9 9 10 12 10 12 12 16 8 13 18 14 17 20 21 23 25 22 25 26 29 26 27 27 33 31 33 34 36 29 34",
"output": "10"
},
{
"input": "50\n1 2 3 3 4 3 6 7 8 10 11 10 12 11 11 14 13 8 17 20 21 19 15 18 21 18 17 23 25 28 25 27 29 32 32 34 37 29 30 39 41 35 24 41 37 36 41 35 43",
"output": "10"
},
{
"input": "99\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",
"output": "1"
},
{
"input": "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98",
"output": "99"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "100"
}
] | 1,691,329,477 | 2,147,483,647 | Python 3 | OK | TESTS | 90 | 140 | 25,292,800 | n = int(input())
a = [int(e) for e in input().split()]
d = {1:0}
for k, v in enumerate(a):
d[k+2] = d[v] + 1
d2 = {}
for k, v in d.items():
d2[v] = d2.get(v,0) + 1
s = sum([v%2 for v in d2.values()])
print(s) | Title: Peculiar apple-tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=><=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=<<=*i*.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Input Specification:
First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000) — number of inflorescences.
Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down.
Output Specification:
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
Demo Input:
['3\n1 1\n', '5\n1 2 2 2\n', '18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n']
Demo Output:
['1\n', '3\n', '4\n']
Note:
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it. | ```python
n = int(input())
a = [int(e) for e in input().split()]
d = {1:0}
for k, v in enumerate(a):
d[k+2] = d[v] + 1
d2 = {}
for k, v in d.items():
d2[v] = d2.get(v,0) + 1
s = sum([v%2 for v in d2.values()])
print(s)
``` | 3 |
|
637 | A | Voting for Photos | PROGRAMMING | 1,000 | [
"*special",
"constructive algorithms",
"implementation"
] | null | null | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. | Print the identifier of the photo which won the elections. | [
"5\n1 3 2 2 1\n",
"9\n100 200 300 200 100 300 300 100 200\n"
] | [
"2\n",
"300\n"
] | In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier. | 500 | [
{
"input": "5\n1 3 2 2 1",
"output": "2"
},
{
"input": "9\n100 200 300 200 100 300 300 100 200",
"output": "300"
},
{
"input": "1\n5",
"output": "5"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "5\n1 3 4 2 2",
"output": "2"
},
{
"input": "10\n2 1 2 3 1 5 8 7 4 8",
"output": "2"
},
{
"input": "7\n1 1 2 2 2 3 3",
"output": "2"
},
{
"input": "12\n2 3 1 2 3 3 3 2 1 1 2 1",
"output": "3"
},
{
"input": "15\n7 6 8 4 9 8 7 3 4 6 7 5 4 2 8",
"output": "7"
},
{
"input": "15\n100 200 300 500 300 400 600 300 100 200 400 300 600 200 100",
"output": "300"
},
{
"input": "10\n677171 677171 677171 677171 672280 677171 677171 672280 672280 677171",
"output": "677171"
},
{
"input": "15\n137419 137419 531977 438949 137419 438949 438949 137419 438949 531977 531977 531977 438949 438949 438949",
"output": "438949"
},
{
"input": "20\n474463 517819 640039 640039 640039 640039 474463 474463 474463 640039 640039 474463 474463 425567 474463 517819 640039 474463 517819 517819",
"output": "474463"
},
{
"input": "40\n119631 119631 772776 119631 658661 119631 108862 524470 125132 700668 69196 844949 154577 108862 108862 108862 597344 940938 989698 108862 154577 69196 125132 687080 940938 125132 69196 69196 125132 566152 953083 406319 380068 119631 154577 125132 413984 69196 154577 154577",
"output": "108862"
},
{
"input": "5\n1 1 1000000 1000000 1000000",
"output": "1000000"
},
{
"input": "5\n1000000 1 1 1000000 1",
"output": "1"
},
{
"input": "10\n1 1 1000000 1000000 1000000 1 1000000 1 1 1000000",
"output": "1"
},
{
"input": "8\n1000000 1000000 1 1 1 1000000 1000000 1",
"output": "1000000"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1000000 1",
"output": "1000000"
},
{
"input": "2\n1 1000000",
"output": "1"
},
{
"input": "2\n1000000 1000000",
"output": "1000000"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "4\n1 1000000 1000000 1",
"output": "1000000"
}
] | 1,458,115,535 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 124 | 0 | n = int(input())
photos = {}
best_photo = 0
max_likes = 0
q = list(map(int, input().split()))
for id in q:
try:
photos[id] += 1
except KeyError:
photos[id] = 1
if photos[id] > max_likes:
best_photo = id
max_likes = photos[id]
print(best_photo)
| Title: Voting for Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the total likes to the published photoes.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like.
Output Specification:
Print the identifier of the photo which won the elections.
Demo Input:
['5\n1 3 2 2 1\n', '9\n100 200 300 200 100 300 300 100 200\n']
Demo Output:
['2\n', '300\n']
Note:
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3; - as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier. | ```python
n = int(input())
photos = {}
best_photo = 0
max_likes = 0
q = list(map(int, input().split()))
for id in q:
try:
photos[id] += 1
except KeyError:
photos[id] = 1
if photos[id] > max_likes:
best_photo = id
max_likes = photos[id]
print(best_photo)
``` | 3 |
|
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible. | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output": "5 6"
},
{
"input": "10\n1 1 2 1 1 2 2 1 2 3",
"output": "1 8"
},
{
"input": "10\n5 4 3 2 1 1 2 3 4 5",
"output": "5 6"
},
{
"input": "10\n1 10 100 1000 10000 1 10 100 1000 10000",
"output": "1 6"
},
{
"input": "10\n9 9 9 9 8 9 8 8 8 8",
"output": "1 6"
},
{
"input": "10\n1 11 111 1111 1 11 11 1 1111 1111",
"output": "2 7"
}
] | 1,436,892,636 | 6,036 | Python 3 | OK | TESTS | 49 | 295 | 16,384,000 | def bin_search(n,a):
l = 0
r = len(a)-1
while l<=r:
m = (l+r)//2
if n>a[m][0]:
l = m+1
if n<a[m][0]:
r = m-1
if n == a[m][0]:
return m
return -1
n = int(input())
a = input().split()
def ke(n):
return n[1]
def f(n):
return abs(n[2]-n[3])
cnt = {}
mx = 0
for i in range(n):
a[i] = int(a[i])
if a[i] in cnt:
cnt[a[i]][1] += 1
cnt[a[i]][3] = i
else:
cnt[a[i]] = [a[i],1,i,0]
for m in cnt.values():
if m[1]>mx:
mx = m[1]
v = []
for m in cnt.values():
if m[1]==mx:
v.append(m)
v.sort(key=f)
print(v[0][2]+1,v[0][3]+1)
| Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input Specification:
The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array.
Output Specification:
Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Demo Input:
['5\n1 1 2 2 1\n', '5\n1 2 2 3 1\n', '6\n1 2 2 1 1 2\n']
Demo Output:
['1 5', '2 3', '1 5']
Note:
A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | ```python
def bin_search(n,a):
l = 0
r = len(a)-1
while l<=r:
m = (l+r)//2
if n>a[m][0]:
l = m+1
if n<a[m][0]:
r = m-1
if n == a[m][0]:
return m
return -1
n = int(input())
a = input().split()
def ke(n):
return n[1]
def f(n):
return abs(n[2]-n[3])
cnt = {}
mx = 0
for i in range(n):
a[i] = int(a[i])
if a[i] in cnt:
cnt[a[i]][1] += 1
cnt[a[i]][3] = i
else:
cnt[a[i]] = [a[i],1,i,0]
for m in cnt.values():
if m[1]>mx:
mx = m[1]
v = []
for m in cnt.values():
if m[1]==mx:
v.append(m)
v.sort(key=f)
print(v[0][2]+1,v[0][3]+1)
``` | 3 |
|
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98",
"output": "24"
}
] | 1,647,187,343 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 512,000 | lengthnmOfPbOfGoodRound,lengthrqOfPbOfGoodRound = [int(i) for i in input().split()]
PbOfGoodRound = [int(i) for i in input().split()]
rqOfGoodRound = [int(i) for i in input().split()]
deleted =[]
for i in range(len(PbOfGoodRound)):
while PbOfGoodRound[i]>min(rqOfGoodRound)and len(rqOfGoodRound)>1:
rqOfGoodRound.pop(rqOfGoodRound.index(min(rqOfGoodRound)))
print(rqOfGoodRound)
if PbOfGoodRound[i]<=min(rqOfGoodRound):
deleted.append(i)
if(len(rqOfGoodRound)>0):
rqOfGoodRound.pop(rqOfGoodRound.index(min(rqOfGoodRound)))
for index in sorted(deleted, reverse=True):
del PbOfGoodRound[index]
print(len(PbOfGoodRound)) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n']
Demo Output:
['0\n', '2\n', '3\n']
Note:
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | ```python
lengthnmOfPbOfGoodRound,lengthrqOfPbOfGoodRound = [int(i) for i in input().split()]
PbOfGoodRound = [int(i) for i in input().split()]
rqOfGoodRound = [int(i) for i in input().split()]
deleted =[]
for i in range(len(PbOfGoodRound)):
while PbOfGoodRound[i]>min(rqOfGoodRound)and len(rqOfGoodRound)>1:
rqOfGoodRound.pop(rqOfGoodRound.index(min(rqOfGoodRound)))
print(rqOfGoodRound)
if PbOfGoodRound[i]<=min(rqOfGoodRound):
deleted.append(i)
if(len(rqOfGoodRound)>0):
rqOfGoodRound.pop(rqOfGoodRound.index(min(rqOfGoodRound)))
for index in sorted(deleted, reverse=True):
del PbOfGoodRound[index]
print(len(PbOfGoodRound))
``` | 0 |
|
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,527,232,577 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define F first
#define S second
#define ld long double
#define pb push_back
#define sz size
#define ll long long
using namespace std;
ll mod_pow(ll a,ll b,ll mod){
ll ans=1ll;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
ll a,b,n,x;
int main(){
scanf("%lld%lld%lld%lld",&a,&b,&x,&n);
/**(a^n)*x+b*((a^n)-1)/(a-1);**/
}
/**
0:x
1:a*x+b*(1);
2:a*(a*x+b)+b=(a*a*x)+a*b+b=(a*a*x)+(b*(a+1));
3:a*((a*a*x)+b*(a+1))+b=(a*a*a*x)+a*b*(a+1)+b=(a*a*a*x)+b*(a*(a+1)+1)=(a*a*a*x)+b*((a^2)+a+1);
(a^n)*x+b*(sigma(a^n-1));
(a^n)*x+b*((a^n)-1)/(a-1);
ex:
a=3 b=4 x=1 n=1
a=3 b=4 x=2 n=1
3*1+ 4* (3-1)/2= 7
/////////////////////////////
(2^(n+1))
81-40=41;
1+3+9+27=((3^4)-1/2);
1+4+16+64=(4^4-1/3);
**/
| 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
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long double
#define pb push_back
#define sz size
#define ll long long
using namespace std;
ll mod_pow(ll a,ll b,ll mod){
ll ans=1ll;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
ll a,b,n,x;
int main(){
scanf("%lld%lld%lld%lld",&a,&b,&x,&n);
/**(a^n)*x+b*((a^n)-1)/(a-1);**/
}
/**
0:x
1:a*x+b*(1);
2:a*(a*x+b)+b=(a*a*x)+a*b+b=(a*a*x)+(b*(a+1));
3:a*((a*a*x)+b*(a+1))+b=(a*a*a*x)+a*b*(a+1)+b=(a*a*a*x)+b*(a*(a+1)+1)=(a*a*a*x)+b*((a^2)+a+1);
(a^n)*x+b*(sigma(a^n-1));
(a^n)*x+b*((a^n)-1)/(a-1);
ex:
a=3 b=4 x=1 n=1
a=3 b=4 x=2 n=1
3*1+ 4* (3-1)/2= 7
/////////////////////////////
(2^(n+1))
81-40=41;
1+3+9+27=((3^4)-1/2);
1+4+16+64=(4^4-1/3);
**/
``` | -1 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,689,356,367 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 31 | 0 | n= int (input())
my_list=list(map(int,input().split()))
nprint=""
partOfPrint=""
tprint=""
i=-1
count=0
while my_list.count("nothing")!=len(my_list)-1 :
i+=1
if (str(my_list[i])!="nothing") and (not partOfPrint.__contains__(str(my_list[i]))) :
partOfPrint+=str(my_list[i])+" "
tprint+=str(i+1)+" "
my_list[i]="nothing"
if tprint.count(" ") != 3:
continue
count+=1
partOfPrint=partOfPrint.strip()
tprint=tprint.strip()
nprint+=tprint+"\n"
partOfPrint=""
tprint=""
i=-1
print(f"{count}\n{nprint}" if count>0 else 0)
| Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
n= int (input())
my_list=list(map(int,input().split()))
nprint=""
partOfPrint=""
tprint=""
i=-1
count=0
while my_list.count("nothing")!=len(my_list)-1 :
i+=1
if (str(my_list[i])!="nothing") and (not partOfPrint.__contains__(str(my_list[i]))) :
partOfPrint+=str(my_list[i])+" "
tprint+=str(i+1)+" "
my_list[i]="nothing"
if tprint.count(" ") != 3:
continue
count+=1
partOfPrint=partOfPrint.strip()
tprint=tprint.strip()
nprint+=tprint+"\n"
partOfPrint=""
tprint=""
i=-1
print(f"{count}\n{nprint}" if count>0 else 0)
``` | -1 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\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",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,690,967,181 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 93 | 0 | n = int(input())
ans = 0
for i in range(n):
a, b = input().split()
a = int(a)
b = int(b)
if a+2 <= b:
ans += 1
print(ans)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
n = int(input())
ans = 0
for i in range(n):
a, b = input().split()
a = int(a)
b = int(b)
if a+2 <= b:
ans += 1
print(ans)
``` | 3 |
|
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
"input": "0 0 0 0\n4132",
"output": "0"
},
{
"input": "3163 5778 83 7640\n11141442444",
"output": "64270"
},
{
"input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442",
"output": "420780"
},
{
"input": "0 0 0 0\n1",
"output": "0"
},
{
"input": "1 2 3 4\n4",
"output": "4"
},
{
"input": "2343 7653 1242 5432\n1",
"output": "2343"
},
{
"input": "2343 7653 1242 5432\n2",
"output": "7653"
},
{
"input": "2343 7653 1242 5432\n3",
"output": "1242"
},
{
"input": "2343 7653 1242 5432\n4",
"output": "5432"
},
{
"input": "1 2 3 4\n123412",
"output": "13"
},
{
"input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111",
"output": "2650"
},
{
"input": "1 2 3 4\n11111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "1 2 3 4\n23123231321231231231231231221232123121312321",
"output": "87"
},
{
"input": "1 2 3 4\n1111111111111222222222233333333333444444444444444",
"output": "126"
},
{
"input": "2 3 1 4\n121321232412342112312313213123123412131231231232",
"output": "105"
}
] | 1,694,722,264 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 0 | a = list(map(int, input().split()))
s = input().strip()
print(sum(a[i] * s.count(str(i + 1)) for i in range(4))) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
Input Specification:
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Output Specification:
Print a single integer — the total number of calories that Jury wastes.
Demo Input:
['1 2 3 4\n123214\n', '1 5 3 2\n11221\n']
Demo Output:
['13\n', '13\n']
Note:
none | ```python
a = list(map(int, input().split()))
s = input().strip()
print(sum(a[i] * s.count(str(i + 1)) for i in range(4)))
``` | 3 |
|
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,676,590,774 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | str1 = input()
str2 = input()
pos = 1
for ch in str2:
if str1[pos-1] == ch:
pos += 1
print(pos) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none | ```python
str1 = input()
str2 = input()
pos = 1
for ch in str2:
if str1[pos-1] == ch:
pos += 1
print(pos)
``` | 3 |
|
411 | C | Kicker | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack).
Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the *i*-th player is *a**i*, the attack skill is *b**i*.
Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents.
We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence.
The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team. | The input contain the players' description in four lines. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100) — the defence and the attack skill of the *i*-th player, correspondingly. | If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes). | [
"1 100\n100 1\n99 99\n99 99\n",
"1 1\n2 2\n3 3\n2 2\n",
"3 3\n2 2\n1 1\n2 2\n"
] | [
"Team 1\n",
"Team 2\n",
"Draw\n"
] | Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence.
Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team). | 0 | [
{
"input": "1 100\n100 1\n99 99\n99 99",
"output": "Team 1"
},
{
"input": "1 1\n2 2\n3 3\n2 2",
"output": "Team 2"
},
{
"input": "3 3\n2 2\n1 1\n2 2",
"output": "Draw"
},
{
"input": "80 79\n79 30\n80 81\n40 80",
"output": "Team 2"
},
{
"input": "10 10\n4 9\n8 9\n7 6",
"output": "Team 1"
},
{
"input": "10 2\n9 3\n3 1\n9 4",
"output": "Draw"
},
{
"input": "6 3\n6 10\n2 5\n4 4",
"output": "Team 1"
},
{
"input": "8 7\n1 5\n7 4\n8 8",
"output": "Draw"
},
{
"input": "2 7\n8 4\n4 6\n10 8",
"output": "Draw"
},
{
"input": "8 3\n4 9\n6 1\n5 6",
"output": "Team 1"
},
{
"input": "10 5\n3 1\n1 9\n1 2",
"output": "Draw"
},
{
"input": "6 5\n10 6\n8 1\n3 2",
"output": "Draw"
},
{
"input": "6 2\n7 5\n5 4\n8 6",
"output": "Draw"
},
{
"input": "1 10\n1 10\n1 1\n7 8",
"output": "Draw"
},
{
"input": "16 7\n9 3\n11 2\n11 4",
"output": "Draw"
},
{
"input": "20 17\n14 10\n10 7\n19 18",
"output": "Draw"
},
{
"input": "12 7\n3 17\n4 15\n2 8",
"output": "Draw"
},
{
"input": "8 14\n8 12\n7 20\n14 6",
"output": "Draw"
},
{
"input": "4 4\n4 15\n2 4\n10 12",
"output": "Draw"
},
{
"input": "4 10\n9 9\n9 12\n13 10",
"output": "Team 2"
},
{
"input": "20 20\n18 8\n15 5\n17 20",
"output": "Draw"
},
{
"input": "12 10\n7 3\n10 5\n1 14",
"output": "Draw"
},
{
"input": "8 16\n12 10\n13 18\n8 4",
"output": "Draw"
},
{
"input": "16 15\n19 1\n16 16\n20 9",
"output": "Draw"
},
{
"input": "12 29\n44 8\n18 27\n43 19",
"output": "Draw"
},
{
"input": "28 46\n50 27\n23 50\n21 45",
"output": "Draw"
},
{
"input": "40 6\n9 1\n16 18\n4 23",
"output": "Draw"
},
{
"input": "4 16\n6 28\n12 32\n28 3",
"output": "Draw"
},
{
"input": "16 22\n11 3\n17 5\n12 27",
"output": "Draw"
},
{
"input": "32 32\n10 28\n14 23\n39 5",
"output": "Draw"
},
{
"input": "48 41\n15 47\n11 38\n19 31",
"output": "Team 1"
},
{
"input": "8 9\n11 17\n11 6\n5 9",
"output": "Draw"
},
{
"input": "24 19\n18 44\n8 29\n30 39",
"output": "Draw"
},
{
"input": "22 4\n29 38\n31 43\n47 21",
"output": "Team 2"
},
{
"input": "51 54\n95 28\n42 28\n17 48",
"output": "Team 1"
},
{
"input": "11 64\n92 47\n88 93\n41 26",
"output": "Draw"
},
{
"input": "27 74\n97 22\n87 65\n24 52",
"output": "Draw"
},
{
"input": "43 32\n49 48\n42 33\n60 30",
"output": "Draw"
},
{
"input": "55 50\n54 23\n85 6\n32 60",
"output": "Team 2"
},
{
"input": "19 56\n59 46\n40 70\n67 34",
"output": "Team 2"
},
{
"input": "31 67\n8 13\n86 91\n43 12",
"output": "Team 2"
},
{
"input": "47 77\n13 88\n33 63\n75 38",
"output": "Draw"
},
{
"input": "59 35\n10 14\n88 23\n58 16",
"output": "Draw"
},
{
"input": "63 4\n18 60\n58 76\n44 93",
"output": "Draw"
},
{
"input": "14 47\n47 42\n21 39\n40 7",
"output": "Team 1"
},
{
"input": "67 90\n63 36\n79 56\n25 56",
"output": "Team 1"
},
{
"input": "64 73\n59 46\n8 19\n57 18",
"output": "Team 1"
},
{
"input": "23 80\n62 56\n56 31\n9 50",
"output": "Team 1"
},
{
"input": "86 95\n86 38\n59 66\n44 78",
"output": "Team 1"
},
{
"input": "10 3\n2 5\n1 10\n2 10",
"output": "Draw"
},
{
"input": "62 11\n79 14\n46 36\n91 52",
"output": "Draw"
},
{
"input": "8 4\n9 10\n7 3\n6 5",
"output": "Team 1"
},
{
"input": "21 12\n29 28\n16 4\n10 1",
"output": "Team 1"
},
{
"input": "91 71\n87 45\n28 73\n9 48",
"output": "Team 1"
},
{
"input": "4 1\n4 3\n6 4\n2 8",
"output": "Team 2"
},
{
"input": "11 7\n12 8\n15 14\n14 14",
"output": "Team 2"
},
{
"input": "12 7\n3 15\n20 18\n20 8",
"output": "Team 2"
},
{
"input": "4 7\n24 11\n17 30\n21 4",
"output": "Team 2"
},
{
"input": "21 22\n21 16\n32 14\n39 35",
"output": "Team 2"
},
{
"input": "16 48\n16 49\n10 68\n60 64",
"output": "Team 2"
},
{
"input": "46 33\n12 3\n11 67\n98 77",
"output": "Team 2"
},
{
"input": "19 9\n47 28\n83 41\n76 14",
"output": "Draw"
},
{
"input": "36 68\n65 82\n37 6\n21 60",
"output": "Team 1"
},
{
"input": "70 98\n62 5\n30 50\n66 96",
"output": "Draw"
},
{
"input": "45 69\n91 96\n72 67\n24 30",
"output": "Draw"
},
{
"input": "34 38\n91 17\n2 12\n83 90",
"output": "Draw"
},
{
"input": "30 31\n98 15\n40 62\n10 22",
"output": "Draw"
}
] | 1,405,275,160 | 5,680 | Python 3 | OK | TESTS | 67 | 140 | 0 | p11 = list(map(int, input().split()))
p12 = list(map(int, input().split()))
p21 = list(map(int, input().split()))
p22 = list(map(int, input().split()))
def f(a, b, c, d):
if a[0] > d[1] and b[1] > c[0]:
return 1
if a[0] < d[1] and b[1] < c[0]:
return 2
return 0
c1 = f(p11, p12, p21, p22)
c2 = f(p12, p11, p21, p22)
c3 = f(p11, p12, p22, p21)
c4 = f(p12, p11, p22, p21)
#print(c1, c2, c3, c4)
#false - win 1 true - win 2
if ((c1 == 2 or c3 == 2) and (c2 == 2 or c4 == 2)):
print("Team 2")
elif ((c1 == 1 and c3 == 1) or (c2 == 1 and c4 == 1)):
print("Team 1")
else:
print("Draw")
| Title: Kicker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack).
Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the *i*-th player is *a**i*, the attack skill is *b**i*.
Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents.
We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence.
The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team.
Input Specification:
The input contain the players' description in four lines. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100) — the defence and the attack skill of the *i*-th player, correspondingly.
Output Specification:
If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes).
Demo Input:
['1 100\n100 1\n99 99\n99 99\n', '1 1\n2 2\n3 3\n2 2\n', '3 3\n2 2\n1 1\n2 2\n']
Demo Output:
['Team 1\n', 'Team 2\n', 'Draw\n']
Note:
Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence.
Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team). | ```python
p11 = list(map(int, input().split()))
p12 = list(map(int, input().split()))
p21 = list(map(int, input().split()))
p22 = list(map(int, input().split()))
def f(a, b, c, d):
if a[0] > d[1] and b[1] > c[0]:
return 1
if a[0] < d[1] and b[1] < c[0]:
return 2
return 0
c1 = f(p11, p12, p21, p22)
c2 = f(p12, p11, p21, p22)
c3 = f(p11, p12, p22, p21)
c4 = f(p12, p11, p22, p21)
#print(c1, c2, c3, c4)
#false - win 1 true - win 2
if ((c1 == 2 or c3 == 2) and (c2 == 2 or c4 == 2)):
print("Team 2")
elif ((c1 == 1 and c3 == 1) or (c2 == 1 and c4 == 1)):
print("Team 1")
else:
print("Draw")
``` | 3 |
|
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,663,227,854 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | l=list(map(int,input().split()))
m,n,a=l[0],l[1],l[2]
ans=((m-1)//a+1)*((n-1)//a+1)
print(ans) | 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
l=list(map(int,input().split()))
m,n,a=l[0],l[1],l[2]
ans=((m-1)//a+1)*((n-1)//a+1)
print(ans)
``` | 3.977 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,531,507,346 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | S = input()
str =''
for i in S:
#print(i)
if str == '':
if i == 'h':
str += i
#print(str)
continue
else:
continue
elif str == 'h':
if i == 'e':
str += i
#print(str)
continue
else:
continue
elif str == 'he':
if i == 'l':
str += i
#print(str)
continue
else:
continue
elif str == 'hel':
if i == 'l':
str += i
#print(str)
continue
else:
continue
elif str == 'hell':
if i == 'o':
str += i
#print(str)
continue
else:
continue
#print(str)
if str == 'hello':
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
S = input()
str =''
for i in S:
#print(i)
if str == '':
if i == 'h':
str += i
#print(str)
continue
else:
continue
elif str == 'h':
if i == 'e':
str += i
#print(str)
continue
else:
continue
elif str == 'he':
if i == 'l':
str += i
#print(str)
continue
else:
continue
elif str == 'hel':
if i == 'l':
str += i
#print(str)
continue
else:
continue
elif str == 'hell':
if i == 'o':
str += i
#print(str)
continue
else:
continue
#print(str)
if str == 'hello':
print('YES')
else:
print('NO')
``` | 3.9455 |
388 | A | Fox and Box Accumulation | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 500 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n100 99",
"output": "1"
},
{
"input": "9\n0 1 1 0 2 0 3 45 4",
"output": "3"
},
{
"input": "10\n1 1 1 1 2 2 2 2 2 2",
"output": "4"
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "2"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "11\n71 34 31 71 42 38 64 60 36 76 67",
"output": "1"
},
{
"input": "39\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54",
"output": "1"
},
{
"input": "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46",
"output": "1"
},
{
"input": "87\n52 63 93 90 50 35 67 66 46 89 43 64 33 88 34 80 69 59 75 55 55 68 66 83 46 33 72 36 73 34 54 85 52 87 67 68 47 95 52 78 92 58 71 66 84 61 36 77 69 44 84 70 71 55 43 91 33 65 77 34 43 59 83 70 95 38 92 92 74 53 66 65 81 45 55 89 49 52 43 69 78 41 37 79 63 70 67",
"output": "1"
},
{
"input": "15\n20 69 36 63 40 40 52 42 20 43 59 68 64 49 47",
"output": "1"
},
{
"input": "39\n40 20 49 35 80 18 20 75 39 62 43 59 46 37 58 52 67 16 34 65 32 75 59 42 59 41 68 21 41 61 66 19 34 63 19 63 78 62 24",
"output": "1"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "18"
},
{
"input": "46\n14 13 13 10 13 15 8 8 12 9 11 15 8 10 13 8 12 13 11 8 12 15 12 15 11 13 12 9 13 12 10 8 13 15 9 15 8 13 11 8 9 9 9 8 11 8",
"output": "3"
},
{
"input": "70\n6 1 4 1 1 6 5 2 5 1 1 5 2 1 2 4 1 1 1 2 4 5 2 1 6 6 5 2 1 4 3 1 4 3 6 5 2 1 3 4 4 1 4 5 6 2 1 2 4 4 5 3 6 1 1 2 2 1 5 6 1 6 3 1 4 4 2 3 1 4",
"output": "11"
},
{
"input": "94\n11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11",
"output": "8"
},
{
"input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "46\n14 8 7 4 8 7 8 8 12 9 9 12 9 12 14 8 10 14 14 6 9 11 7 14 14 13 11 4 13 13 11 13 9 10 10 12 10 8 12 10 13 10 7 13 14 6",
"output": "4"
},
{
"input": "74\n4 4 5 5 5 5 5 5 6 6 5 4 4 4 3 3 5 4 5 3 4 4 5 6 3 3 5 4 4 5 4 3 5 5 4 4 3 5 6 4 3 6 6 3 4 5 4 4 3 3 3 6 3 5 6 5 5 5 5 3 6 4 5 4 4 6 6 3 4 5 6 6 6 6",
"output": "11"
},
{
"input": "100\n48 35 44 37 35 42 42 39 49 53 35 55 41 42 42 39 43 49 46 54 48 39 42 53 55 39 56 43 43 38 48 40 54 36 48 55 46 40 41 39 45 56 38 40 47 46 45 46 53 51 38 41 54 35 35 47 42 43 54 54 39 44 49 41 37 49 36 37 37 49 53 44 47 37 55 49 45 40 35 51 44 40 42 35 46 48 53 48 35 38 42 36 54 46 44 47 41 40 41 42",
"output": "2"
},
{
"input": "100\n34 3 37 35 40 44 38 46 13 31 12 23 26 40 26 18 28 36 5 21 2 4 10 29 3 46 38 41 37 28 44 14 39 10 35 17 24 28 38 16 29 6 2 42 47 34 43 2 43 46 7 16 16 43 33 32 20 47 8 48 32 4 45 38 15 7 25 25 19 41 20 35 16 2 31 5 31 25 27 3 45 29 32 36 9 47 39 35 9 21 32 17 21 41 29 48 11 40 5 25",
"output": "3"
},
{
"input": "100\n2 4 5 5 0 5 3 0 3 0 5 3 4 1 0 3 0 5 5 0 4 3 3 3 0 2 1 2 2 4 4 2 4 0 1 3 4 1 4 2 5 3 5 2 3 0 1 2 5 5 2 0 4 2 5 1 0 0 4 0 1 2 0 1 2 4 1 4 5 3 4 5 5 1 0 0 3 1 4 0 4 5 1 3 3 0 4 2 0 4 5 2 3 0 5 1 4 4 1 0",
"output": "21"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "17"
},
{
"input": "100\n1 1 1 2 2 2 2 2 2 1 1 1 2 0 2 2 0 0 0 0 0 2 0 0 2 2 1 0 2 0 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 0 1 2 2 0 2 2 2 2 1 0 1 0 0 0 2 0 2 0 1 1 0 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 0 2 1 0 1 2 0 1 1 2 0 0 1 1 0 1 1",
"output": "34"
},
{
"input": "100\n0 3 1 0 3 2 1 2 2 1 2 1 3 2 1 2 1 3 2 0 0 2 3 0 0 2 1 2 2 3 1 2 2 2 0 3 3 2 0 0 1 0 1 2 3 1 0 3 3 3 0 2 1 3 0 1 3 2 2 2 2 3 3 2 0 2 0 1 0 1 3 0 1 2 0 1 3 2 0 3 1 1 2 3 1 3 1 0 3 0 3 0 2 1 1 1 2 2 0 1",
"output": "26"
},
{
"input": "100\n1 0 2 2 2 2 1 0 1 2 2 2 0 1 0 1 2 1 2 1 0 1 2 2 2 1 0 1 0 2 1 2 0 2 1 1 2 1 1 0 1 2 1 1 2 1 1 0 2 2 0 0 1 2 0 2 0 0 1 1 0 0 2 1 2 1 0 2 2 2 2 2 2 1 2 0 1 2 1 2 1 0 1 0 1 0 1 1 0 2 1 0 0 1 2 2 1 0 0 1",
"output": "34"
},
{
"input": "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4 4 3 3 3 4 4 4 4 3",
"output": "20"
},
{
"input": "100\n8 7 9 10 2 7 8 11 11 4 7 10 2 5 8 9 10 3 9 4 10 5 5 6 3 8 8 9 6 9 5 5 4 11 4 2 11 8 3 5 6 6 11 9 8 11 9 8 3 3 8 9 8 9 4 8 6 11 4 4 4 9 7 5 3 4 11 3 9 11 8 10 3 5 5 7 6 9 4 5 2 11 3 6 2 10 9 4 6 10 5 11 8 10 10 8 9 8 5 3",
"output": "9"
},
{
"input": "5\n4 1 1 1 1",
"output": "2"
}
] | 1,655,262,898 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 46 | 1,945,600 | n = int(input())
a = list(map(int, input().split()))
a.sort()
h = [0] * 101
for i in range(n):
for j in range(101):
if(a[i] >= h[j]):
h[j] += 1
break
c = 101 - h.count(0)
print(c)
| Title: Fox and Box Accumulation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the minimal possible number of piles.
Demo Input:
['3\n0 0 10\n', '5\n0 1 2 3 4\n', '4\n0 0 0 0\n', '9\n0 1 0 2 0 1 1 2 10\n']
Demo Output:
['2\n', '1\n', '4\n', '3\n']
Note:
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
h = [0] * 101
for i in range(n):
for j in range(101):
if(a[i] >= h[j]):
h[j] += 1
break
c = 101 - h.count(0)
print(c)
``` | 3 |
|
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct. | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n2 3\n1 1\n3 2",
"output": "Happy Alex"
},
{
"input": "4\n4 1\n3 2\n2 3\n1 4",
"output": "Happy Alex"
},
{
"input": "2\n2 1\n1 2",
"output": "Happy Alex"
},
{
"input": "3\n3 2\n1 1\n2 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 1\n3 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
}
] | 1,664,956,514 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 717 | 19,353,600 | polje = []
n = int(input())
for par in range(0, n):
a,b = input().split(' ')
polje.append([int(a),int(b)])
polje.sort(key=lambda x:x[1],reverse=False)
check = False
for x in range(0, n-1):
if polje[x][0] > polje[x+1][0]:
check = True
break
else:
continue
if check:
print('Happy Alex')
else:
print('Poor Alex') | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
polje = []
n = int(input())
for par in range(0, n):
a,b = input().split(' ')
polje.append([int(a),int(b)])
polje.sort(key=lambda x:x[1],reverse=False)
check = False
for x in range(0, n-1):
if polje[x][0] > polje[x+1][0]:
check = True
break
else:
continue
if check:
print('Happy Alex')
else:
print('Poor Alex')
``` | 3 |
|
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "19",
"output": "6"
},
{
"input": "40",
"output": "19"
},
{
"input": "77",
"output": "41"
},
{
"input": "222",
"output": "125"
},
{
"input": "987",
"output": "501"
},
{
"input": "1000",
"output": "508"
},
{
"input": "2000",
"output": "958"
},
{
"input": "3000",
"output": "1375"
},
{
"input": "2999",
"output": "1375"
},
{
"input": "2998",
"output": "1375"
},
{
"input": "2997",
"output": "1374"
},
{
"input": "1429",
"output": "706"
},
{
"input": "1673",
"output": "808"
},
{
"input": "1500",
"output": "732"
},
{
"input": "500",
"output": "266"
},
{
"input": "856",
"output": "439"
}
] | 1,590,419,392 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 280 | 1,331,200 | def main():
N=int(input())
ans=0
for j in range(1,N+1):
i=2
num=j
count=0
while(num!=1):
if(num%i==0):
count+=1
while(num%i==0):
num//=i
i+=1
if count==2:
ans+=1
print(ans)
if __name__=='__main__':
main() | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input Specification:
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output Specification:
Output the amount of almost prime numbers between 1 and *n*, inclusive.
Demo Input:
['10\n', '21\n']
Demo Output:
['2\n', '8\n']
Note:
none | ```python
def main():
N=int(input())
ans=0
for j in range(1,N+1):
i=2
num=j
count=0
while(num!=1):
if(num%i==0):
count+=1
while(num%i==0):
num//=i
i+=1
if count==2:
ans+=1
print(ans)
if __name__=='__main__':
main()
``` | 3.92752 |
527 | C | Glass Carving | PROGRAMMING | 1,500 | [
"binary search",
"data structures",
"implementation"
] | null | null | Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.
After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.
Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree? | The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000).
Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance *x* (1<=≤<=*x*<=≤<=*w*<=-<=1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts. | After each cut print on a single line the area of the maximum available glass fragment in mm2. | [
"4 3 4\nH 2\nV 2\nV 3\nV 1\n",
"7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n"
] | [
"8\n4\n4\n2\n",
"28\n16\n12\n6\n4\n"
] | Picture for the first sample test: | 1,500 | [
{
"input": "4 3 4\nH 2\nV 2\nV 3\nV 1",
"output": "8\n4\n4\n2"
},
{
"input": "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1",
"output": "28\n16\n12\n6\n4"
},
{
"input": "2 2 1\nV 1",
"output": "2"
},
{
"input": "2 2 1\nH 1",
"output": "2"
},
{
"input": "2 2 2\nV 1\nH 1",
"output": "2\n1"
},
{
"input": "2 2 2\nH 1\nV 1",
"output": "2\n1"
},
{
"input": "10 10 10\nV 6\nH 8\nV 4\nV 8\nH 2\nH 5\nV 9\nH 7\nH 3\nV 7",
"output": "60\n48\n32\n32\n24\n12\n12\n12\n8\n8"
},
{
"input": "5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3",
"output": "40\n40\n32\n24\n24\n24\n24\n18\n12\n8"
},
{
"input": "15 5 10\nV 13\nV 10\nV 3\nH 2\nV 9\nV 7\nV 2\nH 1\nV 4\nH 3",
"output": "65\n50\n35\n21\n18\n12\n12\n12\n9\n6"
},
{
"input": "2 3 1\nH 1",
"output": "4"
},
{
"input": "200000 200000 1\nH 1",
"output": "39999800000"
},
{
"input": "2 4 1\nH 2",
"output": "4"
}
] | 1,588,176,431 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 204,800 | # -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 11:12:24 2020
@author: Diego
"""
import numpy as np
w,h,n = list(map(int, (input().split())))
v = [0,w]
H = [0,h]
ar = []
for i in range(n):
pos, num = list((input().split()))
num = int(num)
#pos,num = i
if(pos == 'H'):
H.append(num)
H.sort()
h_ = np.max(np.diff(H))
v_ = np.max(np.diff(v))
ar.append(h_ * v_)
else:
v.append(num)
v.sort()
h_ = np.max(np.diff(H))
v_ = np.max(np.diff(v))
ar.append(h_ * v_)
for i in ar:
print(i) | Title: Glass Carving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.
After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.
Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
Input Specification:
The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000).
Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance *x* (1<=≤<=*x*<=≤<=*w*<=-<=1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
Output Specification:
After each cut print on a single line the area of the maximum available glass fragment in mm2.
Demo Input:
['4 3 4\nH 2\nV 2\nV 3\nV 1\n', '7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n']
Demo Output:
['8\n4\n4\n2\n', '28\n16\n12\n6\n4\n']
Note:
Picture for the first sample test: | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 11:12:24 2020
@author: Diego
"""
import numpy as np
w,h,n = list(map(int, (input().split())))
v = [0,w]
H = [0,h]
ar = []
for i in range(n):
pos, num = list((input().split()))
num = int(num)
#pos,num = i
if(pos == 'H'):
H.append(num)
H.sort()
h_ = np.max(np.diff(H))
v_ = np.max(np.diff(v))
ar.append(h_ * v_)
else:
v.append(num)
v.sort()
h_ = np.max(np.diff(H))
v_ = np.max(np.diff(v))
ar.append(h_ * v_)
for i in ar:
print(i)
``` | -1 |
|
319 | C | Kalila and Dimna in the Logging Industry | PROGRAMMING | 2,100 | [
"dp",
"geometry"
] | null | null | Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain saw on the tree number *i*, they can decrease the height of this tree by one unit. Each time that Kalila and Dimna use the chain saw, they need to recharge it. Cost of charging depends on the id of the trees which have been cut completely (a tree is cut completely if its height equal to 0). If the maximum id of a tree which has been cut completely is *i* (the tree that have height *a**i* in the beginning), then the cost of charging the chain saw would be *b**i*. If no tree is cut completely, Kalila and Dimna cannot charge the chain saw. The chainsaw is charged in the beginning. We know that for each *i* < *j*, *a**i*<=<<=*a**j* and *b**i*<=><=*b**j* and also *b**n*<==<=0 and *a*1<==<=1. Kalila and Dimna want to cut all the trees completely, with minimum cost.
They want you to help them! Will you? | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line of input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line of input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (0<=≤<=*b**i*<=≤<=109).
It's guaranteed that *a*1<==<=1, *b**n*<==<=0, *a*1<=<<=*a*2<=<<=...<=<<=*a**n* and *b*1<=><=*b*2<=><=...<=><=*b**n*. | The only line of output must contain the minimum cost of cutting all the trees completely.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5\n1 2 3 4 5\n5 4 3 2 0\n",
"6\n1 2 3 10 20 30\n6 5 4 3 2 0\n"
] | [
"25\n",
"138\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 4 5\n5 4 3 2 0",
"output": "25"
},
{
"input": "6\n1 2 3 10 20 30\n6 5 4 3 2 0",
"output": "138"
}
] | 1,374,664,653 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 156 | 2,048,000 | n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
dp = [-1]*n
dp[-1] = 0
for x in range(n-2, -1, -1):
lo = x+1
hi = n-1
while hi-lo > 10:
m1 = lo + (hi-lo)/3
m2 = m1 + (hi-lo)/3
if A[m1]*B[x]+dp[m1] < A[m2]*B[x]+dp[m2]:
hi = m2
else:
lo = m1
dp[x] = A[lo]*B[x] + dp[lo]
while lo < hi:
lo += 1
dp[x] = min(dp[x], A[lo]*B[x] + dp[lo])
print(dp[0])
| Title: Kalila and Dimna in the Logging Industry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain saw on the tree number *i*, they can decrease the height of this tree by one unit. Each time that Kalila and Dimna use the chain saw, they need to recharge it. Cost of charging depends on the id of the trees which have been cut completely (a tree is cut completely if its height equal to 0). If the maximum id of a tree which has been cut completely is *i* (the tree that have height *a**i* in the beginning), then the cost of charging the chain saw would be *b**i*. If no tree is cut completely, Kalila and Dimna cannot charge the chain saw. The chainsaw is charged in the beginning. We know that for each *i* < *j*, *a**i*<=<<=*a**j* and *b**i*<=><=*b**j* and also *b**n*<==<=0 and *a*1<==<=1. Kalila and Dimna want to cut all the trees completely, with minimum cost.
They want you to help them! Will you?
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line of input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line of input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (0<=≤<=*b**i*<=≤<=109).
It's guaranteed that *a*1<==<=1, *b**n*<==<=0, *a*1<=<<=*a*2<=<<=...<=<<=*a**n* and *b*1<=><=*b*2<=><=...<=><=*b**n*.
Output Specification:
The only line of output must contain the minimum cost of cutting all the trees completely.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['5\n1 2 3 4 5\n5 4 3 2 0\n', '6\n1 2 3 10 20 30\n6 5 4 3 2 0\n']
Demo Output:
['25\n', '138\n']
Note:
none | ```python
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
dp = [-1]*n
dp[-1] = 0
for x in range(n-2, -1, -1):
lo = x+1
hi = n-1
while hi-lo > 10:
m1 = lo + (hi-lo)/3
m2 = m1 + (hi-lo)/3
if A[m1]*B[x]+dp[m1] < A[m2]*B[x]+dp[m2]:
hi = m2
else:
lo = m1
dp[x] = A[lo]*B[x] + dp[lo]
while lo < hi:
lo += 1
dp[x] = min(dp[x], A[lo]*B[x] + dp[lo])
print(dp[0])
``` | -1 |
|
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "20\n5 3 7 2 1 6 4",
"output": "6"
},
{
"input": "10\n5 1 1 1 1 1 5",
"output": "6"
},
{
"input": "50\n10 1 10 1 10 1 10",
"output": "1"
},
{
"input": "77\n11 11 11 11 11 11 10",
"output": "1"
},
{
"input": "1\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n100 100 100 100 100 100 100",
"output": "3"
},
{
"input": "999\n10 20 10 20 30 20 10",
"output": "3"
},
{
"input": "433\n109 58 77 10 39 125 15",
"output": "7"
},
{
"input": "1\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n1 0 1 0 1 0 1",
"output": "1"
},
{
"input": "997\n1 1 0 0 1 0 1",
"output": "1"
},
{
"input": "1000\n1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1000\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "1000\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "1000\n1 0 0 1 0 0 1",
"output": "1"
},
{
"input": "509\n105 23 98 0 7 0 155",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2\n1 1 0 0 0 0 0",
"output": "2"
},
{
"input": "1\n0 0 0 0 0 1 0",
"output": "6"
},
{
"input": "10\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 6 0",
"output": "6"
},
{
"input": "3\n0 1 0 0 0 0 0",
"output": "2"
},
{
"input": "10\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "28\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "100\n5 5 5 5 5 5 5",
"output": "6"
},
{
"input": "4\n1 0 0 0 0 0 1",
"output": "7"
},
{
"input": "2\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "7\n0 0 0 0 0 0 7",
"output": "7"
},
{
"input": "7\n2 1 1 1 1 1 0",
"output": "6"
},
{
"input": "2\n0 0 1 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1 0",
"output": "6"
},
{
"input": "5\n1 1 1 0 0 1 1",
"output": "7"
},
{
"input": "100\n10 20 30 10 10 10 10",
"output": "7"
},
{
"input": "1\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "70\n10 10 10 10 10 10 10",
"output": "7"
},
{
"input": "22\n1 2 3 4 5 6 10",
"output": "7"
},
{
"input": "5\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "2\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 0 0 0 0 0 2",
"output": "7"
},
{
"input": "10\n1 2 2 1 2 1 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "4\n0 1 1 0 0 0 0",
"output": "3"
},
{
"input": "100\n0 0 0 0 0 1 0",
"output": "6"
}
] | 1,622,071,240 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 154 | 0 | n = int(input())
a = list(map(int, input().split()))
i = 0
while n>a[i]:
n-=a[i]
i = (i+1)%7
print(i+1) | Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
Input Specification:
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Output Specification:
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
Demo Input:
['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n']
Demo Output:
['6\n', '1\n']
Note:
Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | ```python
n = int(input())
a = list(map(int, input().split()))
i = 0
while n>a[i]:
n-=a[i]
i = (i+1)%7
print(i+1)
``` | 3 |
|
932 | B | Recursive Queries | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | 1,000 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 1,519,073,012 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 7,065,600 | from functools import reduce, lru_cache
max = int(10e6 + 5)
def gen(l, r, k):
for i in range(l, r+1):
yield 1 if g(i) == k else 0
def main():
q = int(input())
for _ in range(q):
l, r, k = (int(x) for x in input().split())
s = sum(gen(l, r, k))
print(s)
def f(n):
return reduce((lambda x,y: int(x) if int(y) == 0 else int(x)*int(y)), str(n))
@lru_cache(maxsize=max)
def g(n):
if n < 10:
return n
return g(f(n))
if __name__ == "__main__":
main() | Title: Recursive Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*.
Input Specification:
The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9).
Output Specification:
For each query, print a single line containing the answer for that query.
Demo Input:
['4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n', '4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n']
Demo Output:
['1\n4\n0\n8\n', '3\n1\n1\n5\n']
Note:
In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | ```python
from functools import reduce, lru_cache
max = int(10e6 + 5)
def gen(l, r, k):
for i in range(l, r+1):
yield 1 if g(i) == k else 0
def main():
q = int(input())
for _ in range(q):
l, r, k = (int(x) for x in input().split())
s = sum(gen(l, r, k))
print(s)
def f(n):
return reduce((lambda x,y: int(x) if int(y) == 0 else int(x)*int(y)), str(n))
@lru_cache(maxsize=max)
def g(n):
if n < 10:
return n
return g(f(n))
if __name__ == "__main__":
main()
``` | 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,646,479,486 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 154 | 0 | u_1 = u_2 = u_3 = u1 = u2 = u3 = 0
for _ in range(int(input())):
u1, u2, u3 = map(int, input().split())
u_1 += u1
u_2 += u2
u_3 += u3
print("YES" if u_1 == u_2 == u_3 == 0 else "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
u_1 = u_2 = u_3 = u1 = u2 = u3 = 0
for _ in range(int(input())):
u1, u2, u3 = map(int, input().split())
u_1 += u1
u_2 += u2
u_3 += u3
print("YES" if u_1 == u_2 == u_3 == 0 else "NO")
``` | 3.9615 |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,692,273,710 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 389 | 21,094,400 | n = int(input())
l = list(map(int, input().split()))
ans = list()
for i in range(n):
min_, max_ = int(), int()
if i == n-1:
min_ = l[i] - l[i-1]
max_ = l[i] - l[0]
else:
min_ = min(abs(l[i] - l[i-1]), abs(l[i] - l[i+1]))
max_ = max(abs(l[i] - l[0]), abs(l[i] - l[-1]))
ans.append([min_, max_])
for i in ans:
print(f'{i[0]} {i[1]}')
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
n = int(input())
l = list(map(int, input().split()))
ans = list()
for i in range(n):
min_, max_ = int(), int()
if i == n-1:
min_ = l[i] - l[i-1]
max_ = l[i] - l[0]
else:
min_ = min(abs(l[i] - l[i-1]), abs(l[i] - l[i+1]))
max_ = max(abs(l[i] - l[0]), abs(l[i] - l[-1]))
ans.append([min_, max_])
for i in ans:
print(f'{i[0]} {i[1]}')
``` | 3 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,555,478,230 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | num = int(input())
count = 0
ppl = num + 1
y=input()
x = y.split()
for i in range (0,num):
x[i] = int(x[i])
total = sum(x)
for i in range(1,6):
if((total+i) % ppl != 1):
count += 1
print(count)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
num = int(input())
count = 0
ppl = num + 1
y=input()
x = y.split()
for i in range (0,num):
x[i] = int(x[i])
total = sum(x)
for i in range(1,6):
if((total+i) % ppl != 1):
count += 1
print(count)
``` | 3 |
|
688 | A | Opponents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents. | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day. | Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. | [
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] | [
"2\n",
"1\n",
"2\n"
] | In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | 500 | [
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111",
"output": "1"
},
{
"input": "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111",
"output": "1"
},
{
"input": "10 10\n0000100011\n0100001111\n1111111111\n1100011111\n1111111111\n1000111000\n1111000010\n0111001001\n1101010110\n1111111111",
"output": "4"
},
{
"input": "10 10\n1100110010\n0000000001\n1011100111\n1111111111\n1111111111\n1111111111\n1100010110\n1111111111\n1001001010\n1111111111",
"output": "3"
},
{
"input": "10 7\n0000111001\n1111111111\n0110110001\n1111111111\n1111111111\n1000111100\n0110000111",
"output": "2"
},
{
"input": "5 10\n00110\n11000\n10010\n00010\n11110\n01101\n11111\n10001\n11111\n01001",
"output": "6"
},
{
"input": "5 9\n11111\n11101\n11111\n11111\n01010\n01010\n00000\n11111\n00111",
"output": "3"
},
{
"input": "5 10\n11111\n00010\n11010\n11111\n11111\n00100\n11111\n11111\n01000\n11111",
"output": "2"
},
{
"input": "5 9\n11111\n11111\n11111\n11111\n11100\n11111\n11111\n11111\n00000",
"output": "1"
},
{
"input": "5 8\n11111\n10110\n01001\n11111\n01100\n10010\n11111\n11111",
"output": "2"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "100 1\n0011001100100010000011001100000001011101110110010001110001101100110011111101001011011001000010001111",
"output": "1"
},
{
"input": "100 1\n1011011100000101000111110000110111010101110010010011110010001110100011001110110101111100100110000000",
"output": "1"
},
{
"input": "100 1\n1110000011110101010111111100011001100000101101010110100101110000011100110110110101011100110110010011",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "0"
},
{
"input": "1 100\n1\n0\n0\n0\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n0\n0",
"output": "6"
},
{
"input": "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\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\n1\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": "49"
},
{
"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": "0"
},
{
"input": "1 100\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": "100"
},
{
"input": "2 2\n11\n10",
"output": "1"
},
{
"input": "1 1\n0",
"output": "1"
}
] | 1,580,645,391 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 109 | 0 | n,d=map(int,input().split())
m=[]
a=0
for i in range(d):
l=input()[:n]
if "0" in l:
a=a+1
else:
m.append(a)
a=0
if i==d-1:
m.append(a)
print(max(m))
| Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input Specification:
The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day.
Output Specification:
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.
Demo Input:
['2 2\n10\n00\n', '4 1\n0100\n', '4 5\n1101\n1111\n0110\n1011\n1111\n']
Demo Output:
['2\n', '1\n', '2\n']
Note:
In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | ```python
n,d=map(int,input().split())
m=[]
a=0
for i in range(d):
l=input()[:n]
if "0" in l:
a=a+1
else:
m.append(a)
a=0
if i==d-1:
m.append(a)
print(max(m))
``` | 3 |
|
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc",
"output": "abaabaabaacaabaacacacaaaabbacbaacbbbbcabcabbcccaabcc"
},
{
"input": "13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymt\nbvwzpuut\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymth\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdl\nrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypud\nqlvkfkshkxyrfefigtngifxsuhpjgkb\nlhxtkfjrrwcvzuamizotupjqckaq\nenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjz\nxkazwk",
"output": "bvwzpuutclgknjjojyuvdtvclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymthclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdlclgknjjojyuvdtvzxzclgknjjojyuvdtvzxzxradqhmenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjzgvzpnckalbaubfviyhijosiixvxaydxagvymqlhxtkfjrrwcvzuamizotupjqckaqqlvkfkshkxyrfefigtngifxsuhpjgkbrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypudxkazwk"
}
] | 1,456,849,254 | 4,854 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | x=int(input())
y=list()
for i in range(x):
y.append(input())
y.sort()
z=""
for j in range(x):
z+=y[j]
print(z) | Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation.
Input Specification:
The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.
Output Specification:
Print the only string *a* — the lexicographically smallest string concatenation.
Demo Input:
['4\nabba\nabacaba\nbcd\ner\n', '5\nx\nxx\nxxa\nxxaa\nxxaaa\n', '3\nc\ncb\ncba\n']
Demo Output:
['abacabaabbabcder\n', 'xxaaaxxaaxxaxxx\n', 'cbacbc\n']
Note:
none | ```python
x=int(input())
y=list()
for i in range(x):
y.append(input())
y.sort()
z=""
for j in range(x):
z+=y[j]
print(z)
``` | 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,664,696,661 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | from math import ceil
def theatreSquare(input):
n = int(input.split(' ')[0])
m = int(input.split(' ')[1])
a = int(input.split(' ')[2])
global nDimensionCount
global mDimensionCount
if a > n:
nDimensionCount = 1
elif a > m:
mDimensionCount = 1
else:
nDimensionCount = ceil(n / a)
mDimensionCount = ceil(m / a)
return nDimensionCount * mDimensionCount
print(theatreSquare('6 6 4'))
| 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
from math import ceil
def theatreSquare(input):
n = int(input.split(' ')[0])
m = int(input.split(' ')[1])
a = int(input.split(' ')[2])
global nDimensionCount
global mDimensionCount
if a > n:
nDimensionCount = 1
elif a > m:
mDimensionCount = 1
else:
nDimensionCount = ceil(n / a)
mDimensionCount = ceil(m / a)
return nDimensionCount * mDimensionCount
print(theatreSquare('6 6 4'))
``` | 0 |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
"input": "021",
"output": "012"
},
{
"input": "2",
"output": "2"
},
{
"input": "201",
"output": "120"
},
{
"input": "2112120",
"output": "1112220"
},
{
"input": "102",
"output": "012"
},
{
"input": "202",
"output": "202"
},
{
"input": "220201",
"output": "122020"
},
{
"input": "12",
"output": "12"
},
{
"input": "100022202",
"output": "000122202"
},
{
"input": "01",
"output": "01"
},
{
"input": "1",
"output": "1"
}
] | 1,617,576,082 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | x = input()
while '21' in x or '10' in x :
x=x.replace('21','12',1)
x=x.replace('10','01',1)
print(x) | Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$.
Input Specification:
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Output Specification:
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Demo Input:
['100210\n', '11222121\n', '20\n']
Demo Output:
['001120\n', '11112222\n', '20\n']
Note:
none | ```python
x = input()
while '21' in x or '10' in x :
x=x.replace('21','12',1)
x=x.replace('10','01',1)
print(x)
``` | 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,694,405,719 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | x = int(input())
pasos = (x + 4) // 5
print(pasos)
| 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())
pasos = (x + 4) // 5
print(pasos)
``` | 3 |
|
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
"output": "1"
},
{
"input": "10 7\n1101111011",
"output": "2"
},
{
"input": "10 9\n1110000101",
"output": "1"
},
{
"input": "10 9\n1100000001",
"output": "1"
},
{
"input": "20 5\n11111111110111101001",
"output": "4"
},
{
"input": "20 11\n11100000111000011011",
"output": "2"
},
{
"input": "20 19\n10100000000000000001",
"output": "1"
},
{
"input": "50 13\n10011010100010100111010000010000000000010100000101",
"output": "5"
},
{
"input": "50 8\n11010100000011001100001100010001110000101100110011",
"output": "8"
},
{
"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111",
"output": "25"
},
{
"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "20"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111",
"output": "25"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111",
"output": "25"
},
{
"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111",
"output": "34"
},
{
"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111",
"output": "13"
},
{
"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111",
"output": "15"
},
{
"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111",
"output": "12"
},
{
"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111",
"output": "18"
},
{
"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001",
"output": "16"
},
{
"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101",
"output": "10"
},
{
"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111",
"output": "13"
},
{
"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001",
"output": "18"
},
{
"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011",
"output": "12"
},
{
"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001",
"output": "9"
},
{
"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101",
"output": "12"
},
{
"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001",
"output": "7"
},
{
"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001",
"output": "3"
},
{
"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001",
"output": "3"
},
{
"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001",
"output": "3"
},
{
"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "99"
},
{
"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111",
"output": "-1"
},
{
"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111",
"output": "33"
},
{
"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111",
"output": "-1"
},
{
"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111",
"output": "17"
},
{
"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111",
"output": "-1"
},
{
"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011",
"output": "14"
},
{
"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101",
"output": "11"
},
{
"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001",
"output": "-1"
},
{
"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111",
"output": "-1"
},
{
"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101",
"output": "13"
},
{
"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101",
"output": "9"
},
{
"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001",
"output": "-1"
},
{
"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001",
"output": "-1"
},
{
"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001",
"output": "-1"
},
{
"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001",
"output": "3"
},
{
"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "-1"
},
{
"input": "43 30\n1001000001111111010100100100110101011101101",
"output": "2"
},
{
"input": "7 1\n1111111",
"output": "6"
},
{
"input": "9 3\n101000001",
"output": "-1"
},
{
"input": "10 3\n1100000001",
"output": "-1"
},
{
"input": "8 2\n10000101",
"output": "-1"
},
{
"input": "2 1\n11",
"output": "1"
}
] | 1,632,529,461 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 77 | 6,963,200 | # Time complexity: O(n)
# Space complexity: O(n)
# Rationale: For each location with lily, the minimum step to reach is 1 + step
# to reach the previous lily (within the jump range d). To avoid counting for the
# spots without lily, we use a large number for comparison to skip the computation.
n, d = map(int, input().split())
lilies = list(map(int, input()))
dp = [102] * (n + 1)
dp[0] = dp[1] = 0 # dp[0] is not used; dp[1] is 0 because we start from here.
for i in range(2, n + 1): # Loops through the rest of the lilies.
if lilies[i - 1] == 1:
for j in range(max(0, i - d),
i): # Checks the steps on previous lily within jump range.
dp[i] = min(dp[i], dp[j] + 1)
if dp[n] > n: # Here dp[n] is 102.
print(-1)
else:
print(dp[n])
| Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
Input Specification:
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
Output Specification:
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
Demo Input:
['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n']
Demo Output:
['2\n', '-1\n', '3\n', '4\n']
Note:
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | ```python
# Time complexity: O(n)
# Space complexity: O(n)
# Rationale: For each location with lily, the minimum step to reach is 1 + step
# to reach the previous lily (within the jump range d). To avoid counting for the
# spots without lily, we use a large number for comparison to skip the computation.
n, d = map(int, input().split())
lilies = list(map(int, input()))
dp = [102] * (n + 1)
dp[0] = dp[1] = 0 # dp[0] is not used; dp[1] is 0 because we start from here.
for i in range(2, n + 1): # Loops through the rest of the lilies.
if lilies[i - 1] == 1:
for j in range(max(0, i - d),
i): # Checks the steps on previous lily within jump range.
dp[i] = min(dp[i], dp[j] + 1)
if dp[n] > n: # Here dp[n] is 102.
print(-1)
else:
print(dp[n])
``` | 3 |
|
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet. | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,531,025,451 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 233 | 12,595,200 | """
http://codeforces.com/problemset/problem/1004/C
"""
input()
arr = map(int, input().split())
hash_ = {}
cnt = 0
for x in arr:
if x not in hash_:
cnt += len(hash_)
hash_[x] = len(hash_)
else:
cnt += len(hash_) - hash_[x]
hash_[x] += len(hash_) - hash_[x]
print(cnt)
| Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input Specification:
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Output Specification:
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
Demo Input:
['5\n1 5 4 1 3\n', '7\n1 2 1 1 1 3 2\n']
Demo Output:
['9\n', '7\n']
Note:
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | ```python
"""
http://codeforces.com/problemset/problem/1004/C
"""
input()
arr = map(int, input().split())
hash_ = {}
cnt = 0
for x in arr:
if x not in hash_:
cnt += len(hash_)
hash_[x] = len(hash_)
else:
cnt += len(hash_) - hash_[x]
hash_[x] += len(hash_) - hash_[x]
print(cnt)
``` | 3 |