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
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReality\nSoul\nSpace\nMind" }, { "input": "3\nblue\norange\npurple", "output": "3\nTime\nReality\nMind" }, { "input": "2\nyellow\nred", "output": "4\nPower\nSoul\nSpace\nTime" }, { "input": "1\ngreen", "output": "5\nReality\nSpace\nPower\nSoul\nMind" }, { "input": "2\npurple\ngreen", "output": "4\nReality\nMind\nSpace\nSoul" }, { "input": "1\nblue", "output": "5\nPower\nReality\nSoul\nTime\nMind" }, { "input": "2\npurple\nblue", "output": "4\nMind\nSoul\nTime\nReality" }, { "input": "2\ngreen\nblue", "output": "4\nReality\nMind\nPower\nSoul" }, { "input": "3\npurple\ngreen\nblue", "output": "3\nMind\nReality\nSoul" }, { "input": "1\norange", "output": "5\nReality\nTime\nPower\nSpace\nMind" }, { "input": "2\npurple\norange", "output": "4\nReality\nMind\nTime\nSpace" }, { "input": "2\norange\ngreen", "output": "4\nSpace\nMind\nReality\nPower" }, { "input": "3\norange\npurple\ngreen", "output": "3\nReality\nSpace\nMind" }, { "input": "2\norange\nblue", "output": "4\nTime\nMind\nReality\nPower" }, { "input": "3\nblue\ngreen\norange", "output": "3\nPower\nMind\nReality" }, { "input": "4\nblue\norange\ngreen\npurple", "output": "2\nMind\nReality" }, { "input": "1\nred", "output": "5\nTime\nSoul\nMind\nPower\nSpace" }, { "input": "2\nred\npurple", "output": "4\nMind\nSpace\nTime\nSoul" }, { "input": "2\nred\ngreen", "output": "4\nMind\nSpace\nPower\nSoul" }, { "input": "3\nred\npurple\ngreen", "output": "3\nSoul\nSpace\nMind" }, { "input": "2\nblue\nred", "output": "4\nMind\nTime\nPower\nSoul" }, { "input": "3\nred\nblue\npurple", "output": "3\nTime\nMind\nSoul" }, { "input": "3\nred\nblue\ngreen", "output": "3\nSoul\nPower\nMind" }, { "input": "4\npurple\nblue\ngreen\nred", "output": "2\nMind\nSoul" }, { "input": "2\norange\nred", "output": "4\nPower\nMind\nTime\nSpace" }, { "input": "3\nred\norange\npurple", "output": "3\nMind\nSpace\nTime" }, { "input": "3\nred\norange\ngreen", "output": "3\nMind\nSpace\nPower" }, { "input": "4\nred\norange\ngreen\npurple", "output": "2\nSpace\nMind" }, { "input": "3\nblue\norange\nred", "output": "3\nPower\nMind\nTime" }, { "input": "4\norange\nblue\npurple\nred", "output": "2\nTime\nMind" }, { "input": "4\ngreen\norange\nred\nblue", "output": "2\nMind\nPower" }, { "input": "5\npurple\norange\nblue\nred\ngreen", "output": "1\nMind" }, { "input": "1\nyellow", "output": "5\nPower\nSoul\nReality\nSpace\nTime" }, { "input": "2\npurple\nyellow", "output": "4\nTime\nReality\nSpace\nSoul" }, { "input": "2\ngreen\nyellow", "output": "4\nSpace\nReality\nPower\nSoul" }, { "input": "3\npurple\nyellow\ngreen", "output": "3\nSoul\nReality\nSpace" }, { "input": "2\nblue\nyellow", "output": "4\nTime\nReality\nPower\nSoul" }, { "input": "3\nyellow\nblue\npurple", "output": "3\nSoul\nReality\nTime" }, { "input": "3\ngreen\nyellow\nblue", "output": "3\nSoul\nReality\nPower" }, { "input": "4\nyellow\nblue\ngreen\npurple", "output": "2\nReality\nSoul" }, { "input": "2\nyellow\norange", "output": "4\nTime\nSpace\nReality\nPower" }, { "input": "3\nyellow\npurple\norange", "output": "3\nSpace\nReality\nTime" }, { "input": "3\norange\nyellow\ngreen", "output": "3\nSpace\nReality\nPower" }, { "input": "4\ngreen\nyellow\norange\npurple", "output": "2\nSpace\nReality" }, { "input": "3\nyellow\nblue\norange", "output": "3\nTime\nReality\nPower" }, { "input": "4\norange\npurple\nblue\nyellow", "output": "2\nReality\nTime" }, { "input": "4\nblue\norange\nyellow\ngreen", "output": "2\nReality\nPower" }, { "input": "5\ngreen\nyellow\norange\nblue\npurple", "output": "1\nReality" }, { "input": "3\nyellow\npurple\nred", "output": "3\nTime\nSoul\nSpace" }, { "input": "3\nred\ngreen\nyellow", "output": "3\nPower\nSoul\nSpace" }, { "input": "4\nred\npurple\ngreen\nyellow", "output": "2\nSpace\nSoul" }, { "input": "3\nred\nyellow\nblue", "output": "3\nPower\nSoul\nTime" }, { "input": "4\nblue\nyellow\nred\npurple", "output": "2\nTime\nSoul" }, { "input": "4\nblue\nyellow\nred\ngreen", "output": "2\nSoul\nPower" }, { "input": "5\nred\nyellow\ngreen\nblue\npurple", "output": "1\nSoul" }, { "input": "3\nred\nyellow\norange", "output": "3\nPower\nSpace\nTime" }, { "input": "4\norange\ngreen\nyellow\nred", "output": "2\nPower\nSpace" }, { "input": "5\norange\nred\ngreen\nyellow\npurple", "output": "1\nSpace" }, { "input": "4\nyellow\nred\norange\nblue", "output": "2\nTime\nPower" }, { "input": "5\npurple\nblue\norange\nyellow\nred", "output": "1\nTime" }, { "input": "5\norange\nblue\nyellow\nred\ngreen", "output": "1\nPower" } ]
1,654,885,280
2,147,483,647
Python 3
OK
TESTS
64
46
0
dict1={"purple":"Power", "green":"Time", "blue":"Space", "orange":"Soul", "red":"Reality", "yellow":"Mind"} n=int(input()) n_list=[] print(6-n) for i in range(n): g=input() n_list.append(g) for k,v in dict1.items(): if k not in n_list: print(v)
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. Output Specification: In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
```python dict1={"purple":"Power", "green":"Time", "blue":"Space", "orange":"Soul", "red":"Reality", "yellow":"Mind"} n=int(input()) n_list=[] print(6-n) for i in range(n): g=input() n_list.append(g) for k,v in dict1.items(): if k not in n_list: print(v) ```
3
279
B
Books
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation", "two pointers" ]
null
null
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book. Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read.
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Print a single integer — the maximum number of books Valera can read.
[ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ]
[ "3\n", "1\n" ]
none
1,000
[ { "input": "4 5\n3 1 2 1", "output": "3" }, { "input": "3 3\n2 2 3", "output": "1" }, { "input": "1 3\n5", "output": "0" }, { "input": "1 10\n4", "output": "1" }, { "input": "2 10\n6 4", "output": "2" }, { "input": "6 10\n2 3 4 2 1 1", "output": "4" }, { "input": "7 13\n6 8 14 9 4 11 10", "output": "2" }, { "input": "10 15\n10 9 1 1 5 10 5 3 7 2", "output": "3" }, { "input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4", "output": "6" }, { "input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19", "output": "4" }, { "input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52", "output": "3" }, { "input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708", "output": "0" }, { "input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550", "output": "1" } ]
1,687,020,706
2,147,483,647
Python 3
OK
TESTS
38
186
13,824,000
p=lambda:list(map(int,input().split())) n,t=p() l=p() i=j=s=0 for j in range(n): s+=l[j] if s>t: s-=l[i] i+=1 print(n-i)
Title: Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book. Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. Output Specification: Print a single integer — the maximum number of books Valera can read. Demo Input: ['4 5\n3 1 2 1\n', '3 3\n2 2 3\n'] Demo Output: ['3\n', '1\n'] Note: none
```python p=lambda:list(map(int,input().split())) n,t=p() l=p() i=j=s=0 for j in range(n): s+=l[j] if s>t: s-=l[i] i+=1 print(n-i) ```
3
128
A
Statues
PROGRAMMING
1,500
[ "dfs and similar" ]
null
null
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8<=×<=8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
[ ".......A\n........\n........\n........\n........\n........\n........\nM.......\n", ".......A\n........\n........\n........\n........\n........\nSS......\nM.......\n", ".......A\n........\n........\n........\n........\n.S......\nS.......\nMS......\n" ]
[ "WIN\n", "LOSE\n", "LOSE\n" ]
none
1,000
[ { "input": ".SSSSSSA\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\nMSSSSSSS", "output": "WIN" }, { "input": "SSSSSSSA\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", "output": "LOSE" }, { "input": "SSSSSSSA\n......SS\n.......S\n.......S\n.......S\n.......S\n.......S\nM......S", "output": "LOSE" }, { "input": ".......A\nS.S.S.S.\n........\n.S.S.S.S\n........\nS.S.S.S.\n........\nMS.S.S.S", "output": "WIN" }, { "input": "S..SSSSA\n...S.S.S\n.SS.SS.S\nSS....SS\n.S.SSSS.\n...S.S.S\n..S..S..\nMSSSSS.S", "output": "WIN" }, { "input": "SSSSSSSA\nSS.SSSSS\nSSSSSSSS\nSSSSSSSS\nS..SS.SS\nSSSS.SSS\nSSSS.SSS\nM.SSS.SS", "output": "LOSE" }, { "input": ".......A\n....S...\n...S....\n........\nS..S..SS\n.S....S.\nS....S..\nM....S.S", "output": "WIN" }, { "input": "...S.SSA\n.....S..\nSSS....S\n...S...S\n....SSSS\n.S.S...S\n..S....S\nM..SSSSS", "output": "WIN" }, { "input": "S..SS.SA\n.SSS.S.S\nSS.SSS.S\nSSS.S.S.\nSS.SSSSS\nSSSSSSSS\nSSSS.SS.\nM.SSS.S.", "output": "LOSE" }, { "input": "...SSS.A\n.....S..\n..S.S.SS\n.S.S...S\nS.S...S.\n....S...\n........\nM..S.SSS", "output": "WIN" }, { "input": ".S.S..SA\n.S...S.S\nS....S..\n...S....\n.S.SSSSS\nS.....SS\n.S.S.SSS\nM....S.S", "output": "LOSE" }, { "input": "SSSS.SSA\nSSS.SSSS\nSSSSSS.S\nSS.SSS.S\nSS.S.SS.\nSSSS.SS.\nSSSS.SSS\nMSS.SSS.", "output": "LOSE" }, { "input": "SSSS.SSA\nSSSSS.SS\nSSSS.SSS\nSSSSSSSS\nSS.SSSSS\nSSS.SSSS\nSSSSSSSS\nMSSS..SS", "output": "LOSE" }, { "input": "S.S.S..A\n...SSS.S\n.SSSSSS.\nSS.S..SS\nSSSS.SSS\n.S.SSS..\nSS.SSSSS\nMSSSS.S.", "output": "LOSE" }, { "input": "SSSSSSSA\nSS.SSS.S\nSSSSSS.S\nSSSSSSSS\nSSSSSSSS\nSSSSSSS.\nSSSSSSSS\nM.SSSSSS", "output": "LOSE" }, { "input": "...S...A\n........\n..S..S.S\n.S....S.\nS.......\n..S.S..S\n......S.\nM..SS..S", "output": "WIN" }, { "input": "SSSSSSSA\nSSSSSSSS\n.SSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSS.SS\nSSSSSSSS\nMSSSSSSS", "output": "LOSE" }, { "input": "SSSSSSSA\nSSS.SSSS\nSSSSSSSS\nSSS.SSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSS.SS", "output": "LOSE" }, { "input": "S.S..SSA\n...S.S..\n.SS.SSS.\n......S.\n.S...S..\n..S.S..S\n..SS..S.\nM.SS..SS", "output": "WIN" }, { "input": "SSSSSSSA\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", "output": "LOSE" }, { "input": ".....S.A\n...S.S..\n.....S..\n........\n........\n........\n......S.\nM....S..", "output": "WIN" }, { "input": "SSSSS..A\nS.SS.SS.\n.S.SSS.S\n..SSSSS.\n.S..S.S.\n.SS.S..S\nSSS.S...\nM..S..S.", "output": "LOSE" }, { "input": ".SSSS.SA\n.SS.SSS.\n..S.SS..\nSSSS.SS.\nS.S.....\nS.S.SSSS\nS..SS..S\nMS.SS.SS", "output": "LOSE" }, { "input": "SSS..SSA\nSSSSSSSS\n..SS..SS\n.S.S.SSS\n.SSS.SSS\nSSSS.S.S\n...SS..S\nMS..S.SS", "output": "LOSE" }, { "input": "S..SSS.A\nS.S.SSSS\nSSSSSSSS\n...SS...\nS.SSSSSS\nSS..SS.S\nSS..S.S.\nMSS..SSS", "output": "LOSE" }, { "input": "S.SS.SSA\n.S..SSS.\nSSS.SSS.\nSSSS.SSS\nS.SSSSSS\nSSSSSSSS\nSSSSS.SS\nMS.SSSSS", "output": "LOSE" }, { "input": "SSS.SSSA\nSSS....S\nSS...SSS\n..SSS..S\nS..SS...\nSS.SS...\n.S..SSSS\nM.SSSSSS", "output": "LOSE" }, { "input": "SSS.SSSA\nSSSSSSSS\nSSSSSSSS\nSS.SSS.S\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", "output": "LOSE" } ]
1,655,821,173
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
from collections import deque as dq r = 8 c = 8 start = [] end = [] g = [list(input()) for i in range(r)] s = [0 for i in range(r)] for i in range(r): for j in range(c): if g[i][j] == 'M': start = [i, j] a = [] elif g[i][j] == 'A': end = [i, j] a = [] elif g[i][j] == '.': a = [] elif g[i][j] == 'S': a = [1] if i == 0: g[i][j] = a else: for k in range(len(g[i-1][j])): a.append(int(g[i-1][j][k])+1) g[i][j] = a d = dq() d.append([start[0], start[1], 1]) vis = [[-1 for i in range(c)] for j in range(r)] while len(d) > 0: x, y, nb = d.popleft() vis[x][y] = nb row = [1, 0, 0, -1] col = [0, 1, -1, 0] for k in range(4): a = x+row[k] b = y+col[k] if 0 <= a < r and 0 <= b < c: if nb not in g[a][b] and vis[a][b] == -1: vis[a][b] = nb+1 d.append([a, b, nb+1]) x = end[0] y = end[1] if vis[x][y] == -1: print('NO') else: print('YES')
Title: Statues Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8<=×<=8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input Specification: You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output Specification: If Maria wins, print string "WIN". If the statues win, print string "LOSE". Demo Input: ['.......A\n........\n........\n........\n........\n........\n........\nM.......\n', '.......A\n........\n........\n........\n........\n........\nSS......\nM.......\n', '.......A\n........\n........\n........\n........\n.S......\nS.......\nMS......\n'] Demo Output: ['WIN\n', 'LOSE\n', 'LOSE\n'] Note: none
```python from collections import deque as dq r = 8 c = 8 start = [] end = [] g = [list(input()) for i in range(r)] s = [0 for i in range(r)] for i in range(r): for j in range(c): if g[i][j] == 'M': start = [i, j] a = [] elif g[i][j] == 'A': end = [i, j] a = [] elif g[i][j] == '.': a = [] elif g[i][j] == 'S': a = [1] if i == 0: g[i][j] = a else: for k in range(len(g[i-1][j])): a.append(int(g[i-1][j][k])+1) g[i][j] = a d = dq() d.append([start[0], start[1], 1]) vis = [[-1 for i in range(c)] for j in range(r)] while len(d) > 0: x, y, nb = d.popleft() vis[x][y] = nb row = [1, 0, 0, -1] col = [0, 1, -1, 0] for k in range(4): a = x+row[k] b = y+col[k] if 0 <= a < r and 0 <= b < c: if nb not in g[a][b] and vis[a][b] == -1: vis[a][b] = nb+1 d.append([a, b, nb+1]) x = end[0] y = end[1] if vis[x][y] == -1: print('NO') else: print('YES') ```
0
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "output": "vyvvysyooysyo" }, { "input": "L\ngggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\ngggggggggggggggggggggggggggggggggggggggggg", "output": "ffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nxgwurenkxkiau,c,vonei.zltazmnkhqtwuogkgvgckvja,z.rhanuy.ybebmzcfwozkwvuuiolaqlgvvvewnbuinrncgjwjdsfw", "output": "cheitrmlclosi.v.bpmro/x;ysx,mljwyeiphlhbhvlbks.x/tjsmiu/unrn,xvgepxlebiiop;sw;hbbbremniomtmvhkekfdge" }, { "input": "L\nuoz.vmks,wxrb,nwcvdzh.m,hwsios.lvu,ktes,,ythddhm.sh,d,c,cfj.wqam,bowofbyx,jathqayhreqvixvbmgdokofmym", "output": "ipx/b,ld.ectn.mevbfxj/,.jedopd/;bi.lyrd..uyjffj,/dj.f.v.vgk/ews,.npepgnuc.ksyjwsujtrwbocbn,hfplpg,u," }, { "input": "R\noedjyrvuw/rn.v.hdwndbiposiewgsn.pnyf;/tsdohp,hrtd/mx,;coj./billd..mwbneohcikrdes/ucjr,wspthleyp,..f,", "output": "iwshtecyq.eb,c,gsqbsvuoiauwqfab,obtdl.rasigomgers.nzmlxih,.vukks,,nqvbwigxujeswa.yxhemqaorgkwtom,,dm" }, { "input": "R\nvgj;o;ijrtfyck,dthccioltcx,crub;oceooognsuvfx/kgo.fbsudv,yod.erdrxhbeiyltxhnrobbb;ydrgroefcr/f;uvdjd", "output": "cfhliluherdtxjmsrgxxuikrxzmxeyvlixwiiifbaycdz.jfi,dvayscmtis,wesezgvwutkrzgbeivvvltsefeiwdxe.dlycshs" }, { "input": "L\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", "output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }, { "input": "L\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp" }, { "input": "L\n,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": "...................................................................................................." }, { "input": "L\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "R\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" }, { "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" }, { "input": "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "L\nq", "output": "w" }, { "input": "L\no", "output": "p" }, { "input": "L\n,", "output": "." }, { "input": "L\nz", "output": "x" }, { "input": "R\n.", "output": "," }, { "input": "R\no", "output": "i" }, { "input": "R\nw", "output": "q" }, { "input": "R\nx", "output": "z" }, { "input": "R\n,./", "output": "m,." }, { "input": "R\nwertuk;;/", "output": "qweryjll." }, { "input": "L\n..", "output": "//" } ]
1,680,827,767
2,147,483,647
Python 3
OK
TESTS
31
46
0
a = input() b = list(input()) key = list("qwertyuiopasdfghjkl;zxcvbnm,./") if a =="L": d=1 else: d=-1 n=[] for i in range(len(b)): e = b[i] f = key.index(e) n.append(key[f+d]) print(''.join(n))
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input Specification: First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Specification: Print a line that contains the original message. Demo Input: ['R\ns;;upimrrfod;pbr\n'] Demo Output: ['allyouneedislove\n'] Note: none
```python a = input() b = list(input()) key = list("qwertyuiopasdfghjkl;zxcvbnm,./") if a =="L": d=1 else: d=-1 n=[] for i in range(len(b)): e = b[i] f = key.index(e) n.append(key[f+d]) print(''.join(n)) ```
3
242
B
Big Segment
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide.
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.
[ "3\n1 1\n2 2\n3 3\n", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n" ]
[ "-1\n", "3\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "-1" }, { "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3" }, { "input": "4\n1 5\n2 2\n2 4\n2 5", "output": "1" }, { "input": "5\n3 3\n1 3\n2 2\n2 3\n1 2", "output": "2" }, { "input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8", "output": "-1" }, { "input": "3\n2 5\n3 4\n2 3", "output": "1" }, { "input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19", "output": "-1" }, { "input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3", "output": "1" }, { "input": "1\n1 100000", "output": "1" }, { "input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5", "output": "6" }, { "input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19", "output": "-1" }, { "input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8", "output": "-1" }, { "input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6", "output": "37" }, { "input": "1\n999999999 1000000000", "output": "1" }, { "input": "3\n1 20\n2 22\n3 18", "output": "-1" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "2\n100001 100008\n100005 100006", "output": "1" }, { "input": "1\n1000000 10000000", "output": "1" }, { "input": "3\n3 6\n2 4\n1 5", "output": "-1" }, { "input": "2\n3 5\n1 2", "output": "-1" } ]
1,666,331,909
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
36
2,000
9,523,200
n = int(input()) pieces = [] for i in range(n): pieces.append([int(i) for i in input().split()]) raw_pieces = pieces[:] pieces.sort() for (s, f) in pieces: if s > pieces[0][0]: break for (s2, f2) in pieces: if s <= s2 <= f2 <= f: continue break else: print(raw_pieces.index([s, f]) + 1) exit(0) print(-1)
Title: Big Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide. Output Specification: Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input. Demo Input: ['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n'] Demo Output: ['-1\n', '3\n'] Note: none
```python n = int(input()) pieces = [] for i in range(n): pieces.append([int(i) for i in input().split()]) raw_pieces = pieces[:] pieces.sort() for (s, f) in pieces: if s > pieces[0][0]: break for (s2, f2) in pieces: if s <= s2 <= f2 <= f: continue break else: print(raw_pieces.index([s, f]) + 1) exit(0) print(-1) ```
0
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,636,282,910
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
18,534,400
def main(): n, q = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) queries = [] array = [0]*(n+1) for i in range(q): li, ri = list(map(int, input().strip().split())) for i in range(li, ri+1): array[i] += 1 a.sort(reverse = True) array.sort(reverse = True) solution = 0 for i in range(0, n): solution += (a[i]*array[i]) print(str(solution)) if __name__ == '__main__': main()
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python def main(): n, q = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) queries = [] array = [0]*(n+1) for i in range(q): li, ri = list(map(int, input().strip().split())) for i in range(li, ri+1): array[i] += 1 a.sort(reverse = True) array.sort(reverse = True) solution = 0 for i in range(0, n): solution += (a[i]*array[i]) print(str(solution)) if __name__ == '__main__': main() ```
0
369
C
Valera and Elections
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired. There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located. Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road. It's guaranteed that the graph structure of the city is a tree.
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.
[ "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n" ]
[ "1\n5 \n", "1\n3 \n", "4\n5 4 3 2 \n" ]
none
1,500
[ { "input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "output": "1\n5 " }, { "input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "output": "1\n3 " }, { "input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "output": "4\n5 4 3 2 " }, { "input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "output": "1\n2 " }, { "input": "2\n1 2 1", "output": "0" }, { "input": "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2", "output": "3\n8 6 3 " }, { "input": "2\n2 1 1", "output": "0" }, { "input": "2\n1 2 2", "output": "1\n2 " }, { "input": "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1", "output": "0" }, { "input": "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2", "output": "2\n5 2 " }, { "input": "10\n1 9 1\n3 2 2\n1 2 2\n4 7 2\n3 5 2\n4 3 2\n10 3 2\n7 8 2\n3 6 1", "output": "3\n8 10 5 " }, { "input": "10\n7 9 2\n2 6 2\n7 4 1\n5 4 2\n3 2 1\n8 5 2\n4 3 2\n7 10 1\n1 2 2", "output": "3\n9 8 6 " }, { "input": "10\n3 9 1\n2 10 2\n1 7 1\n3 4 1\n7 8 2\n1 2 1\n5 3 1\n5 6 2\n2 3 2", "output": "3\n6 10 8 " }, { "input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 1\n7 5 1\n6 4 1\n5 3 1\n4 2 1", "output": "2\n7 8 " }, { "input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 2\n7 5 2\n6 4 2\n5 3 2\n4 2 2", "output": "2\n3 2 " }, { "input": "4\n1 2 2\n2 3 1\n2 4 2", "output": "1\n4 " } ]
1,542,481,763
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
373
5,427,200
a = int(input()) nodesx = [] nodesy = [] nodesz = [] out = [] for i in range(a-1): tmp = list(map(int, input().split())) nodesx.append(tmp[0]) nodesy.append(tmp[1]) nodesz.append(tmp[2]) summ = 0 for i in range(len(nodesy)): if nodesy[i] not in nodesx: start = i current = i flag = False while True: # print(curren) if nodesz[current] == 3: break elif nodesz[current] == 2 and flag == False: flag = True summ += 1 out.append(nodesy[start]) nodesz[current] = 3 if nodesx[current] == 1: break current = nodesy.index(nodesx[current]) print(summ) for item in out: print(item,end=' ')
Title: Valera and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired. There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located. Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road. It's guaranteed that the graph structure of the city is a tree. Output Specification: In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them. Demo Input: ['5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n', '5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n', '5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n'] Demo Output: ['1\n5 \n', '1\n3 \n', '4\n5 4 3 2 \n'] Note: none
```python a = int(input()) nodesx = [] nodesy = [] nodesz = [] out = [] for i in range(a-1): tmp = list(map(int, input().split())) nodesx.append(tmp[0]) nodesy.append(tmp[1]) nodesz.append(tmp[2]) summ = 0 for i in range(len(nodesy)): if nodesy[i] not in nodesx: start = i current = i flag = False while True: # print(curren) if nodesz[current] == 3: break elif nodesz[current] == 2 and flag == False: flag = True summ += 1 out.append(nodesy[start]) nodesz[current] = 3 if nodesx[current] == 1: break current = nodesy.index(nodesx[current]) print(summ) for item in out: print(item,end=' ') ```
-1
760
A
Petr and a calendar
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
[ "1 7\n", "1 1\n", "11 6\n" ]
[ "6\n", "5\n", "5\n" ]
The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
500
[ { "input": "1 7", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "2 1", "output": "4" }, { "input": "8 6", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "1 2", "output": "5" }, { "input": "1 3", "output": "5" }, { "input": "1 4", "output": "5" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "6" }, { "input": "2 1", "output": "4" }, { "input": "2 2", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "2 4", "output": "5" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "3 1", "output": "5" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "5" }, { "input": "3 4", "output": "5" }, { "input": "3 5", "output": "5" }, { "input": "3 6", "output": "6" }, { "input": "3 7", "output": "6" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "5" }, { "input": "4 3", "output": "5" }, { "input": "4 4", "output": "5" }, { "input": "4 5", "output": "5" }, { "input": "4 6", "output": "5" }, { "input": "4 7", "output": "6" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "5" }, { "input": "5 3", "output": "5" }, { "input": "5 4", "output": "5" }, { "input": "5 5", "output": "5" }, { "input": "5 6", "output": "6" }, { "input": "5 7", "output": "6" }, { "input": "6 1", "output": "5" }, { "input": "6 2", "output": "5" }, { "input": "6 3", "output": "5" }, { "input": "6 4", "output": "5" }, { "input": "6 5", "output": "5" }, { "input": "6 6", "output": "5" }, { "input": "6 7", "output": "6" }, { "input": "7 1", "output": "5" }, { "input": "7 2", "output": "5" }, { "input": "7 3", "output": "5" }, { "input": "7 4", "output": "5" }, { "input": "7 5", "output": "5" }, { "input": "7 6", "output": "6" }, { "input": "7 7", "output": "6" }, { "input": "8 1", "output": "5" }, { "input": "8 2", "output": "5" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "5" }, { "input": "8 5", "output": "5" }, { "input": "8 6", "output": "6" }, { "input": "8 7", "output": "6" }, { "input": "9 1", "output": "5" }, { "input": "9 2", "output": "5" }, { "input": "9 3", "output": "5" }, { "input": "9 4", "output": "5" }, { "input": "9 5", "output": "5" }, { "input": "9 6", "output": "5" }, { "input": "9 7", "output": "6" }, { "input": "10 1", "output": "5" }, { "input": "10 2", "output": "5" }, { "input": "10 3", "output": "5" }, { "input": "10 4", "output": "5" }, { "input": "10 5", "output": "5" }, { "input": "10 6", "output": "6" }, { "input": "10 7", "output": "6" }, { "input": "11 1", "output": "5" }, { "input": "11 2", "output": "5" }, { "input": "11 3", "output": "5" }, { "input": "11 4", "output": "5" }, { "input": "11 5", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "11 7", "output": "6" }, { "input": "12 1", "output": "5" }, { "input": "12 2", "output": "5" }, { "input": "12 3", "output": "5" }, { "input": "12 4", "output": "5" }, { "input": "12 5", "output": "5" }, { "input": "12 6", "output": "6" }, { "input": "12 7", "output": "6" }, { "input": "1 4", "output": "5" }, { "input": "1 5", "output": "5" }, { "input": "9 7", "output": "6" }, { "input": "2 6", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "2 2", "output": "5" }, { "input": "4 7", "output": "6" }, { "input": "12 6", "output": "6" }, { "input": "12 3", "output": "5" }, { "input": "3 6", "output": "6" }, { "input": "9 6", "output": "5" }, { "input": "7 6", "output": "6" }, { "input": "11 7", "output": "6" }, { "input": "6 6", "output": "5" } ]
1,594,001,788
2,147,483,647
Python 3
OK
TESTS
104
108
6,758,400
import math m, d = map(int, input().split()) a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] print(math.ceil((a[m-1]+d-1)/7))
Title: Petr and a calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap. Input Specification: The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). Output Specification: Print single integer: the number of columns the table should have. Demo Input: ['1 7\n', '1 1\n', '11 6\n'] Demo Output: ['6\n', '5\n', '5\n'] Note: The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
```python import math m, d = map(int, input().split()) a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] print(math.ceil((a[m-1]+d-1)/7)) ```
3
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", "output": "39" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI", "output": "1" }, { "input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC", "output": "85" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ", "output": "18" }, { "input": "PKLKBWTXVJ", "output": "11" }, { "input": "CFHFPTGMOKXVLJJZJDQW", "output": "12" }, { "input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX", "output": "9" }, { "input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY", "output": "4" }, { "input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD", "output": "101" }, { "input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC", "output": "76" }, { "input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC", "output": "45" }, { "input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT", "output": "48" }, { "input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX", "output": "47" }, { "input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA", "output": "65" }, { "input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS", "output": "28" }, { "input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW", "output": "35" }, { "input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL", "output": "30" }, { "input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL", "output": "19" }, { "input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB", "output": "30" }, { "input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB", "output": "34" }, { "input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR", "output": "17" }, { "input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT", "output": "15" }, { "input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB", "output": "9" }, { "input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW", "output": "5" }, { "input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA", "output": "4" }, { "input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE", "output": "5" }, { "input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA", "output": "5" }, { "input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO", "output": "3" }, { "input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY", "output": "3" }, { "input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY", "output": "2" }, { "input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE", "output": "2" }, { "input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII", "output": "2" }, { "input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE", "output": "2" }, { "input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU", "output": "1" }, { "input": "ABBABBB", "output": "4" }, { "input": "ABCD", "output": "4" }, { "input": "XXYC", "output": "3" }, { "input": "YYY", "output": "1" }, { "input": "ABABBBBBBB", "output": "8" }, { "input": "YYYY", "output": "1" }, { "input": "YYYYY", "output": "1" }, { "input": "AXXX", "output": "4" }, { "input": "YYYYYYY", "output": "1" }, { "input": "BYYBBB", "output": "4" }, { "input": "YYYYYYYYY", "output": "1" }, { "input": "CAAAAA", "output": "2" }, { "input": "CCCACCCC", "output": "5" }, { "input": "ABABBBACFEYUKOTTTT", "output": "5" }, { "input": "AABBYYYYYYYY", "output": "3" }, { "input": "BYBACYC", "output": "2" }, { "input": "Y", "output": "1" }, { "input": "ABBBBBB", "output": "7" }, { "input": "BACDYDI", "output": "3" }, { "input": "XEXXXXXXXXXXXXXXX", "output": "16" }, { "input": "TTYTT", "output": "3" }, { "input": "AAYBC", "output": "3" }, { "input": "ABABBBACFEYUKOTTTTT", "output": "6" }, { "input": "YYAYY", "output": "1" }, { "input": "YZZY", "output": "3" }, { "input": "YY", "output": "1" }, { "input": "ZZYZZ", "output": "3" }, { "input": "YBBBY", "output": "4" }, { "input": "BBBACCCCCCC", "output": "8" }, { "input": "YBBBBY", "output": "5" }, { "input": "YYYYYYYYYY", "output": "1" }, { "input": "ABABBBBBBBBBBBB", "output": "13" } ]
1,585,643,922
2,147,483,647
PyPy 3
OK
TESTS
70
156
0
l=['A','U','O','I','E','Y'] s=input() c=0 m=0 for i in s: if(i in l): m=max(m,c) c=0 else: c=c+1 m=max(c,m) print(m+1)
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'. Input Specification: The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. Output Specification: Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. Demo Input: ['ABABBBACFEYUKOTT\n', 'AAA\n'] Demo Output: ['4', '1'] Note: none
```python l=['A','U','O','I','E','Y'] s=input() c=0 m=0 for i in s: if(i in l): m=max(m,c) c=0 else: c=c+1 m=max(c,m) print(m+1) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,479,674,929
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n=int(input()) i=n d,e,f=0,0,0 while(i!=0): a,b,c=input().split() a,b,c=int(a),int(b),int(c) d=a+d e=b+d f=c+f i=i-1 if(d==0 and e==0 and f==0): print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input()) i=n d,e,f=0,0,0 while(i!=0): a,b,c=input().split() a,b,c=int(a),int(b),int(c) d=a+d e=b+d f=c+f i=i-1 if(d==0 and e==0 and f==0): print("YES") else: print("NO") ```
0
955
B
Not simply beatiful strings
PROGRAMMING
1,400
[ "implementation" ]
null
null
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters.
Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case.
[ "ababa\n", "zzcxx\n", "yeee\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
1,000
[ { "input": "ababa", "output": "Yes" }, { "input": "zzcxx", "output": "Yes" }, { "input": "yeee", "output": "No" }, { "input": "a", "output": "No" }, { "input": "bbab", "output": "No" }, { "input": "abcd", "output": "Yes" }, { "input": "abc", "output": "No" }, { "input": "abcdaaaa", "output": "Yes" }, { "input": "aaaaaaaaaaaaaaa", "output": "No" }, { "input": "adb", "output": "No" }, { "input": "dcccbad", "output": "Yes" }, { "input": "bcbccccccca", "output": "Yes" }, { "input": "abcdefgh", "output": "No" }, { "input": "aabcdef", "output": "No" }, { "input": "aabc", "output": "Yes" }, { "input": "ssab", "output": "Yes" }, { "input": "ccdd", "output": "Yes" }, { "input": "abcc", "output": "Yes" }, { "input": "ab", "output": "No" }, { "input": "abcde", "output": "No" }, { "input": "aa", "output": "No" }, { "input": "aaabbb", "output": "Yes" }, { "input": "bbbba", "output": "No" }, { "input": "abbbc", "output": "Yes" }, { "input": "baabaa", "output": "Yes" }, { "input": "abacabadde", "output": "No" }, { "input": "aabbcc", "output": "Yes" }, { "input": "abbc", "output": "Yes" }, { "input": "aaaaaaabbbbbbcder", "output": "No" }, { "input": "aabb", "output": "Yes" }, { "input": "aabbccddee", "output": "No" }, { "input": "abca", "output": "Yes" }, { "input": "aaabbbccc", "output": "Yes" } ]
1,521,823,735
835
Python 3
OK
TESTS
56
155
7,270,400
s = input() l = list(set(s)) ans = 1 if (len(l)>4) or (len(l)<=1): ans = 0 else: if len(l)==2: c1=0 c0=0 for i in range(len(s)): if s[i]==l[0]: c0+=1 else: c1+=1 if (c1<2) or (c0<2): ans = 0 if (len(l)==3): c1 = 0 c2 = 0 c0 = 0 for i in range(len(s)): if s[i]==l[0]: c0+=1 if s[i]==l[1]: c1+=1 if s[i]==l[2]: c2+=1 if (c1+c2+c0)<4: ans = 0 if (ans==0): print('No') else: print('Yes')
Title: Not simply beatiful strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string. Input Specification: The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. Output Specification: Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case. Demo Input: ['ababa\n', 'zzcxx\n', 'yeee\n'] Demo Output: ['Yes\n', 'Yes\n', 'No\n'] Note: In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
```python s = input() l = list(set(s)) ans = 1 if (len(l)>4) or (len(l)<=1): ans = 0 else: if len(l)==2: c1=0 c0=0 for i in range(len(s)): if s[i]==l[0]: c0+=1 else: c1+=1 if (c1<2) or (c0<2): ans = 0 if (len(l)==3): c1 = 0 c2 = 0 c0 = 0 for i in range(len(s)): if s[i]==l[0]: c0+=1 if s[i]==l[1]: c1+=1 if s[i]==l[2]: c2+=1 if (c1+c2+c0)<4: ans = 0 if (ans==0): print('No') else: print('Yes') ```
3
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,683,485,437
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
k,r=list(map(int,input().split())) ls=[] for i in range(1,10): if (k*i)%10==0: print(i) break if k%10==0: print(k//10) else: k=k%10 for i in range(10): ls.append(k*i) for i in ls: if (i-r)%10==0: print(ls.index(i))
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python k,r=list(map(int,input().split())) ls=[] for i in range(1,10): if (k*i)%10==0: print(i) break if k%10==0: print(k//10) else: k=k%10 for i in range(10): ls.append(k*i) for i in ls: if (i-r)%10==0: print(ls.index(i)) ```
0
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected?
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428", "output": "25720377\n661369649" }, { "input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482", "output": "819602309\n796067435" }, { "input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780", "output": "374054998\n902899520" }, { "input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990", "output": "939116221\n323703261" }, { "input": "3\n77 77 77\n77 77\n77", "output": "77\n77" }, { "input": "3\n84 30 9\n9 84\n9", "output": "30\n84" }, { "input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3", "output": "5\n5" }, { "input": "4\n1 5 7 8\n1 5 7\n1 5", "output": "8\n7" } ]
1,630,538,507
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
9,420,800
cantidad_digitos = (input()) cantidad_digitos = int(cantidad_digitos) lista_u = (input()).split(" ") lista_d = (input()).split(" ") lista_t = (input()).split(" ") pe = 0 se = 0 m = 0 n = 0 f = 0 x = 0 y = 0 z = 0 i = 0 j = 0 h = 0 a = 0 b = 0 c = 0 diccionario_l_u = {} diccionario_l_d = {} #Contador de repeticiones de la primera lista while m < cantidad_digitos: while n < cantidad_digitos: if lista_u[m] == lista_u[n]: f += 1 n += 1 diccionario_l_u[lista_u[m]] = f f = 0 n = 0 m += 1 #Contador de repeticiones de la Segunda lista while x < cantidad_digitos-1: while y < cantidad_digitos-1: if lista_d[x] == lista_d[y]: z += 1 y += 1 diccionario_l_d[lista_d[x]] = z z = 0 y = 0 x += 1 #Ver error en primera parte while i < cantidad_digitos: while j < cantidad_digitos-1: if lista_u[i] == lista_d[j]: h += 1 j += 1 if h == 0: pe = lista_u[i] elif h >= 1: if h != int(diccionario_l_u[lista_u[i]]): pe = lista_u[i] i += 1 h = 0 j = 0 #Ver error en segunda parte while a < cantidad_digitos-1: while b < cantidad_digitos-2: if lista_d[a] == lista_t[b]: c += 1 b += 1 if c == 0: se = lista_d[a] elif c >= 1: if c != int(diccionario_l_d[lista_d[a]]): se = lista_d[a] a += 1 c = 0 b = 0 print(pe) print(se)
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected? Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. Output Specification: Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. Demo Input: ['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n'] Demo Output: ['8\n123\n', '1\n3\n'] Note: In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
```python cantidad_digitos = (input()) cantidad_digitos = int(cantidad_digitos) lista_u = (input()).split(" ") lista_d = (input()).split(" ") lista_t = (input()).split(" ") pe = 0 se = 0 m = 0 n = 0 f = 0 x = 0 y = 0 z = 0 i = 0 j = 0 h = 0 a = 0 b = 0 c = 0 diccionario_l_u = {} diccionario_l_d = {} #Contador de repeticiones de la primera lista while m < cantidad_digitos: while n < cantidad_digitos: if lista_u[m] == lista_u[n]: f += 1 n += 1 diccionario_l_u[lista_u[m]] = f f = 0 n = 0 m += 1 #Contador de repeticiones de la Segunda lista while x < cantidad_digitos-1: while y < cantidad_digitos-1: if lista_d[x] == lista_d[y]: z += 1 y += 1 diccionario_l_d[lista_d[x]] = z z = 0 y = 0 x += 1 #Ver error en primera parte while i < cantidad_digitos: while j < cantidad_digitos-1: if lista_u[i] == lista_d[j]: h += 1 j += 1 if h == 0: pe = lista_u[i] elif h >= 1: if h != int(diccionario_l_u[lista_u[i]]): pe = lista_u[i] i += 1 h = 0 j = 0 #Ver error en segunda parte while a < cantidad_digitos-1: while b < cantidad_digitos-2: if lista_d[a] == lista_t[b]: c += 1 b += 1 if c == 0: se = lista_d[a] elif c >= 1: if c != int(diccionario_l_d[lista_d[a]]): se = lista_d[a] a += 1 c = 0 b = 0 print(pe) print(se) ```
0
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input": "18 8", "output": "888888888888888888" }, { "input": "1 5", "output": "5" }, { "input": "1 10", "output": "-1" }, { "input": "100 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "10 2", "output": "2222222222" }, { "input": "18 10", "output": "111111111111111110" }, { "input": "1 9", "output": "9" }, { "input": "7 6", "output": "6666666" }, { "input": "4 4", "output": "4444" }, { "input": "14 7", "output": "77777777777777" }, { "input": "3 8", "output": "888" }, { "input": "1 3", "output": "3" }, { "input": "2 8", "output": "88" }, { "input": "3 8", "output": "888" }, { "input": "4 3", "output": "3333" }, { "input": "5 9", "output": "99999" }, { "input": "4 8", "output": "8888" }, { "input": "3 4", "output": "444" }, { "input": "9 4", "output": "444444444" }, { "input": "8 10", "output": "11111110" }, { "input": "1 6", "output": "6" }, { "input": "20 3", "output": "33333333333333333333" }, { "input": "15 10", "output": "111111111111110" }, { "input": "31 4", "output": "4444444444444444444444444444444" }, { "input": "18 9", "output": "999999999999999999" }, { "input": "72 4", "output": "444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "76 8", "output": "8888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "12 5", "output": "555555555555" }, { "input": "54 5", "output": "555555555555555555555555555555555555555555555555555555" }, { "input": "96 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "15 9", "output": "999999999999999" }, { "input": "100 2", "output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "99 3", "output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "98 4", "output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "97 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "100 6", "output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "98 8", "output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "97 9", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "3 10", "output": "110" }, { "input": "2 4", "output": "44" }, { "input": "2 10", "output": "10" }, { "input": "10 10", "output": "1111111110" }, { "input": "4 10", "output": "1110" }, { "input": "25 10", "output": "1111111111111111111111110" }, { "input": "50 10", "output": "11111111111111111111111111111111111111111111111110" }, { "input": "5 10", "output": "11110" }, { "input": "99 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "1 2", "output": "2" }, { "input": "20 10", "output": "11111111111111111110" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "89 5", "output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "6 10", "output": "111110" }, { "input": "3 8", "output": "888" }, { "input": "1 9", "output": "9" }, { "input": "1 4", "output": "4" }, { "input": "100 7", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" } ]
1,679,653,403
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
0
n,t=map(int,input().split()) for i in range(1000000000000000): if len(str(i*t))==n: print(i*t) break
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. Input Specification: The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. Output Specification: Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. Demo Input: ['3 2\n'] Demo Output: ['712'] Note: none
```python n,t=map(int,input().split()) for i in range(1000000000000000): if len(str(i*t))==n: print(i*t) break ```
0
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "4 3\n1 2 3 4", "output": "-1" }, { "input": "5 3\n2 1 1 1 1", "output": "1" }, { "input": "5 3\n1 1 1 1 1", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 1\n2 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 2\n2 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 2\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 3\n3 2 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "-1" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10", "output": "19" } ]
1,651,391,876
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
n, k = [int(i) for i in input().split()] res = [int(x) for x in input().split()] counter = 0 while len(res) != res.count(res[0]) and counter < len(res): cur = res[k - 1] res.pop(0) res.append(cur) counter += 1 if counter == 3 and len(res) != res.count(res[0]): print(-1) else: print(counter)
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. Output Specification: Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Demo Input: ['3 2\n3 1 1\n', '3 1\n3 1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
```python n, k = [int(i) for i in input().split()] res = [int(x) for x in input().split()] counter = 0 while len(res) != res.count(res[0]) and counter < len(res): cur = res[k - 1] res.pop(0) res.append(cur) counter += 1 if counter == 3 and len(res) != res.count(res[0]): print(-1) else: print(counter) ```
0
851
A
Arpa and a research in Mexican wave
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits. Arpa wants to know how many spectators are standing at time *t*.
The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=&lt;<=*n*<=+<=*k*).
Print single integer: how many spectators are standing at time *t*.
[ "10 5 3\n", "10 5 7\n", "10 5 12\n" ]
[ "3\n", "5\n", "3\n" ]
In the following a sitting spectator is represented as -, a standing spectator is represented as ^. - At *t* = 0  ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1  ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2  ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3  ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4  ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5  ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6  -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7  --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8  ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9  ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0.
500
[ { "input": "10 5 3", "output": "3" }, { "input": "10 5 7", "output": "5" }, { "input": "10 5 12", "output": "3" }, { "input": "840585600 770678331 788528791", "output": "770678331" }, { "input": "25462281 23343504 8024619", "output": "8024619" }, { "input": "723717988 205757169 291917494", "output": "205757169" }, { "input": "27462087 20831796 15492397", "output": "15492397" }, { "input": "966696824 346707476 1196846860", "output": "116557440" }, { "input": "290274403 41153108 327683325", "output": "3744186" }, { "input": "170963478 151220598 222269210", "output": "99914866" }, { "input": "14264008 309456 11132789", "output": "309456" }, { "input": "886869816 281212106 52891064", "output": "52891064" }, { "input": "330543750 243917820 205522400", "output": "205522400" }, { "input": "457658451 18625039 157624558", "output": "18625039" }, { "input": "385908940 143313325 509731380", "output": "19490885" }, { "input": "241227633 220621961 10025257", "output": "10025257" }, { "input": "474139818 268918981 388282504", "output": "268918981" }, { "input": "25963410 3071034 820199", "output": "820199" }, { "input": "656346757 647995766 75748423", "output": "75748423" }, { "input": "588568132 411878522 521753621", "output": "411878522" }, { "input": "735788762 355228487 139602545", "output": "139602545" }, { "input": "860798593 463398487 506871376", "output": "463398487" }, { "input": "362624055 110824996 194551217", "output": "110824996" }, { "input": "211691721 195866131 313244576", "output": "94313276" }, { "input": "45661815 26072719 9643822", "output": "9643822" }, { "input": "757183104 590795077 709609355", "output": "590795077" }, { "input": "418386749 1915035 197248338", "output": "1915035" }, { "input": "763782282 297277890 246562421", "output": "246562421" }, { "input": "893323188 617630677 607049638", "output": "607049638" }, { "input": "506708261 356545583 296093684", "output": "296093684" }, { "input": "984295813 427551190 84113823", "output": "84113823" }, { "input": "774984967 61373612 96603505", "output": "61373612" }, { "input": "774578969 342441237 91492393", "output": "91492393" }, { "input": "76495801 8780305 56447339", "output": "8780305" }, { "input": "48538385 582843 16805978", "output": "582843" }, { "input": "325794610 238970909 553089099", "output": "11676420" }, { "input": "834925315 316928679 711068031", "output": "316928679" }, { "input": "932182199 454838315 267066713", "output": "267066713" }, { "input": "627793782 552043394 67061810", "output": "67061810" }, { "input": "24317170 17881607 218412", "output": "218412" }, { "input": "1000000000 1000 1", "output": "1" }, { "input": "1000000000 1000 2", "output": "2" }, { "input": "1000000000 1 1000", "output": "1" }, { "input": "100 100 100", "output": "100" }, { "input": "100 100 99", "output": "99" }, { "input": "100 100 101", "output": "99" }, { "input": "100 100 199", "output": "1" }, { "input": "1000000000 1000000000 1999999999", "output": "1" }, { "input": "10 5 5", "output": "5" }, { "input": "5 3 5", "output": "3" }, { "input": "10 3 3", "output": "3" }, { "input": "10 5 6", "output": "5" }, { "input": "3 2 4", "output": "1" }, { "input": "10 5 14", "output": "1" }, { "input": "6 1 4", "output": "1" }, { "input": "10 10 19", "output": "1" }, { "input": "10 4 11", "output": "3" }, { "input": "2 2 3", "output": "1" }, { "input": "10 5 11", "output": "4" }, { "input": "600 200 700", "output": "100" }, { "input": "2000 1000 2001", "output": "999" }, { "input": "1000 1000 1001", "output": "999" }, { "input": "5 4 6", "output": "3" }, { "input": "2 1 2", "output": "1" }, { "input": "10 3 10", "output": "3" }, { "input": "15 10 10", "output": "10" }, { "input": "10 5 13", "output": "2" }, { "input": "2 2 2", "output": "2" }, { "input": "5 5 6", "output": "4" }, { "input": "10 6 12", "output": "4" }, { "input": "7 5 8", "output": "4" }, { "input": "10 4 9", "output": "4" }, { "input": "9 2 6", "output": "2" }, { "input": "5 2 6", "output": "1" }, { "input": "6 2 6", "output": "2" }, { "input": "5 5 8", "output": "2" }, { "input": "3 3 5", "output": "1" }, { "input": "10 2 5", "output": "2" }, { "input": "5 3 7", "output": "1" }, { "input": "5 4 8", "output": "1" }, { "input": "10 6 11", "output": "5" }, { "input": "5 3 6", "output": "2" }, { "input": "10 6 14", "output": "2" }, { "input": "10 10 10", "output": "10" }, { "input": "1000000000 1 1000000000", "output": "1" }, { "input": "20 4 22", "output": "2" }, { "input": "5 4 4", "output": "4" }, { "input": "4 3 6", "output": "1" }, { "input": "12 8 18", "output": "2" }, { "input": "10 5 10", "output": "5" }, { "input": "100 50 149", "output": "1" }, { "input": "4 4 4", "output": "4" }, { "input": "7 6 9", "output": "4" }, { "input": "16 10 21", "output": "5" }, { "input": "10 2 11", "output": "1" }, { "input": "600 200 500", "output": "200" }, { "input": "100 30 102", "output": "28" }, { "input": "10 10 18", "output": "2" }, { "input": "15 3 10", "output": "3" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "5 5 5", "output": "5" }, { "input": "10 3 12", "output": "1" }, { "input": "747 457 789", "output": "415" }, { "input": "5 4 7", "output": "2" }, { "input": "15 5 11", "output": "5" }, { "input": "3 2 2", "output": "2" }, { "input": "7 6 8", "output": "5" }, { "input": "7 4 8", "output": "3" }, { "input": "10 4 13", "output": "1" }, { "input": "10 3 9", "output": "3" }, { "input": "20 2 21", "output": "1" }, { "input": "6 5 9", "output": "2" }, { "input": "10 9 18", "output": "1" }, { "input": "12 4 9", "output": "4" }, { "input": "10 7 15", "output": "2" }, { "input": "999999999 999999998 1500000000", "output": "499999997" }, { "input": "20 5 20", "output": "5" }, { "input": "4745 4574 4757", "output": "4562" }, { "input": "10 7 12", "output": "5" }, { "input": "17 15 18", "output": "14" }, { "input": "3 1 3", "output": "1" }, { "input": "100 3 7", "output": "3" }, { "input": "6 2 7", "output": "1" }, { "input": "8 5 10", "output": "3" }, { "input": "3 3 3", "output": "3" }, { "input": "9 5 10", "output": "4" }, { "input": "10 6 13", "output": "3" }, { "input": "13 10 14", "output": "9" }, { "input": "13 12 15", "output": "10" }, { "input": "10 4 12", "output": "2" }, { "input": "41 3 3", "output": "3" }, { "input": "1000000000 1000000000 1400000000", "output": "600000000" }, { "input": "10 3 11", "output": "2" }, { "input": "12 7 18", "output": "1" }, { "input": "15 3 17", "output": "1" }, { "input": "10 2 8", "output": "2" }, { "input": "1000000000 1000 1000000999", "output": "1" }, { "input": "5 5 9", "output": "1" }, { "input": "100 3 6", "output": "3" }, { "input": "100 5 50", "output": "5" }, { "input": "10000 10 10000", "output": "10" }, { "input": "1 1 1", "output": "1" }, { "input": "6 4 4", "output": "4" }, { "input": "9979797 555554 10101010", "output": "434341" }, { "input": "13 5 12", "output": "5" }, { "input": "9 4 10", "output": "3" }, { "input": "7 5 10", "output": "2" }, { "input": "100000000 10000000 100005000", "output": "9995000" }, { "input": "100000 50000 100001", "output": "49999" }, { "input": "15 10 20", "output": "5" }, { "input": "4 4 5", "output": "3" }, { "input": "5 3 3", "output": "3" }, { "input": "30 5 30", "output": "5" }, { "input": "200000 10 200005", "output": "5" }, { "input": "10 9 12", "output": "7" }, { "input": "10 6 15", "output": "1" }, { "input": "1000000000 10 1000000000", "output": "10" }, { "input": "7 5 11", "output": "1" }, { "input": "9 4 4", "output": "4" }, { "input": "14 3 15", "output": "2" }, { "input": "1000000000 100000000 1000000000", "output": "100000000" }, { "input": "40 10 22", "output": "10" }, { "input": "50 10 51", "output": "9" }, { "input": "999999997 999999995 1999999991", "output": "1" }, { "input": "92 79 144", "output": "27" }, { "input": "8 4 4", "output": "4" } ]
1,664,890,796
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,764,800
q,w=map(int,input().split()) if q==w or w==0: a=0 else: a=1 if w==0: print(a,0) elif w<=q//3: print(a,w*2) else: print(a,q-w)
Title: Arpa and a research in Mexican wave Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits. Arpa wants to know how many spectators are standing at time *t*. Input Specification: The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=&lt;<=*n*<=+<=*k*). Output Specification: Print single integer: how many spectators are standing at time *t*. Demo Input: ['10 5 3\n', '10 5 7\n', '10 5 12\n'] Demo Output: ['3\n', '5\n', '3\n'] Note: In the following a sitting spectator is represented as -, a standing spectator is represented as ^. - At *t* = 0  ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1  ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2  ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3  ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4  ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5  ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6  -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7  --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8  ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9  ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0.
```python q,w=map(int,input().split()) if q==w or w==0: a=0 else: a=1 if w==0: print(a,0) elif w<=q//3: print(a,w*2) else: print(a,q-w) ```
-1
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,610,458,255
2,147,483,647
Python 3
OK
TESTS
32
77
0
s,v1,v2,t1,t2=map(int,input().split()) first=s*v1+2*t1 second=s*v2+2*t2 if first > second: print ("Second") if first < second: print("First") if first ==second: print("Friendship")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s,v1,v2,t1,t2=map(int,input().split()) first=s*v1+2*t1 second=s*v2+2*t2 if first > second: print ("Second") if first < second: print("First") if first ==second: print("Friendship") ```
3
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { "input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "output": "46 0" }, { "input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "output": "700 0" }, { "input": "1 0\n- 526403222", "output": "0 1" }, { "input": "1 897986543\n- 371188251", "output": "526798292 0" }, { "input": "1 0\n+ 1", "output": "1 0" }, { "input": "1 0\n- 1", "output": "0 1" }, { "input": "1 10\n+ 10", "output": "20 0" }, { "input": "1 3\n- 5", "output": "3 1" }, { "input": "1 0\n- 5", "output": "0 1" }, { "input": "1 0\n+ 5", "output": "5 0" } ]
1,603,927,446
2,147,483,647
PyPy 3
OK
TESTS
34
156
1,433,600
def solve(test): ans = 0 n, x = map(int, input().split()) for i in range(n): c = input().split() if c[0] == '+': x += int(c[1]) elif int(c[1]) > x: ans += 1 else: x -= int(c[1]) print(x, ans) t = 1 #t = int(input()) for _ in range(t): solve(_ + 1)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. Input Specification: The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. Output Specification: Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. Demo Input: ['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n'] Demo Output: ['22 1\n', '3 2\n'] Note: Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
```python def solve(test): ans = 0 n, x = map(int, input().split()) for i in range(n): c = input().split() if c[0] == '+': x += int(c[1]) elif int(c[1]) > x: ans += 1 else: x -= int(c[1]) print(x, ans) t = 1 #t = int(input()) for _ in range(t): solve(_ + 1) ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
1,690,380,223
2,147,483,647
Python 3
OK
TESTS
59
46
0
import math as m a,b=map(int,input().split()) c=min(a,b) print(m.factorial(c))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python import math as m a,b=map(int,input().split()) c=min(a,b) print(m.factorial(c)) ```
3
489
B
BerSU Ball
PROGRAMMING
1,200
[ "dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers" ]
null
null
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&amp;girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill. Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill.
Print a single number — the required maximum possible number of pairs.
[ "4\n1 4 6 2\n5\n5 1 5 7 9\n", "4\n1 2 3 4\n4\n10 11 12 13\n", "5\n1 1 1 1 1\n3\n1 2 3\n" ]
[ "3\n", "0\n", "2\n" ]
none
1,000
[ { "input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3" }, { "input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0" }, { "input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 10\n1\n9", "output": "1" }, { "input": "4\n4 5 4 4\n5\n5 3 4 2 4", "output": "4" }, { "input": "1\n2\n1\n1", "output": "1" }, { "input": "1\n3\n2\n3 2", "output": "1" }, { "input": "1\n4\n3\n4 4 4", "output": "1" }, { "input": "1\n2\n4\n3 1 4 2", "output": "1" }, { "input": "1\n4\n5\n2 5 5 3 1", "output": "1" }, { "input": "2\n2 2\n1\n2", "output": "1" }, { "input": "2\n4 2\n2\n4 4", "output": "1" }, { "input": "2\n4 1\n3\n2 3 2", "output": "2" }, { "input": "2\n4 3\n4\n5 5 5 6", "output": "1" }, { "input": "2\n5 7\n5\n4 6 7 2 5", "output": "2" }, { "input": "3\n1 2 3\n1\n1", "output": "1" }, { "input": "3\n5 4 5\n2\n2 1", "output": "0" }, { "input": "3\n6 3 4\n3\n4 5 2", "output": "3" }, { "input": "3\n7 7 7\n4\n2 7 2 4", "output": "1" }, { "input": "3\n1 3 3\n5\n1 3 4 1 2", "output": "3" }, { "input": "4\n1 2 1 3\n1\n4", "output": "1" }, { "input": "4\n4 4 6 6\n2\n2 1", "output": "0" }, { "input": "4\n3 1 1 1\n3\n1 6 7", "output": "1" }, { "input": "4\n2 5 1 2\n4\n2 3 3 1", "output": "3" }, { "input": "4\n9 1 7 1\n5\n9 9 9 8 4", "output": "2" }, { "input": "5\n1 6 5 5 6\n1\n2", "output": "1" }, { "input": "5\n5 2 4 5 6\n2\n7 4", "output": "2" }, { "input": "5\n4 1 3 1 4\n3\n6 3 6", "output": "1" }, { "input": "5\n5 2 3 1 4\n4\n1 3 1 7", "output": "3" }, { "input": "5\n9 8 10 9 10\n5\n2 1 5 4 6", "output": "0" }, { "input": "1\n48\n100\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6", "output": "1" }, { "input": "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\n1\n58", "output": "0" }, { "input": "10\n20 87 3 39 20 20 8 40 70 51\n100\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96", "output": "6" }, { "input": "100\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\n10\n66 74 40 67 28 82 99 57 93 64", "output": "9" }, { "input": "100\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\n100\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1", "output": "76" }, { "input": "4\n1 6 9 15\n2\n5 8", "output": "2" }, { "input": "2\n2 4\n2\n3 1", "output": "2" }, { "input": "3\n2 3 5\n3\n3 4 6", "output": "3" }, { "input": "3\n1 3 4\n3\n2 1 5", "output": "3" }, { "input": "2\n5 5\n4\n1 1 1 5", "output": "1" }, { "input": "2\n3 2\n2\n3 4", "output": "2" }, { "input": "2\n3 1\n2\n2 4", "output": "2" }, { "input": "2\n2 3\n2\n2 1", "output": "2" }, { "input": "2\n10 12\n2\n11 9", "output": "2" }, { "input": "3\n1 2 3\n3\n3 2 1", "output": "3" }, { "input": "2\n1 3\n2\n2 1", "output": "2" }, { "input": "2\n4 5\n2\n5 3", "output": "2" }, { "input": "2\n7 5\n2\n6 8", "output": "2" }, { "input": "4\n4 3 2 1\n4\n1 2 3 4", "output": "4" }, { "input": "2\n2 3\n2\n3 1", "output": "2" }, { "input": "2\n2 4\n3\n3 1 8", "output": "2" }, { "input": "3\n3 1 1\n3\n2 4 4", "output": "2" }, { "input": "2\n5 3\n2\n4 6", "output": "2" }, { "input": "4\n1 1 3 3\n4\n2 2 1 1", "output": "4" }, { "input": "3\n3 2 1\n3\n2 4 3", "output": "3" }, { "input": "5\n1 2 3 4 5\n5\n2 3 4 5 1", "output": "5" }, { "input": "3\n3 2 1\n3\n1 2 3", "output": "3" }, { "input": "2\n5 4\n2\n4 6", "output": "2" }, { "input": "4\n3 3 5 5\n4\n4 4 2 2", "output": "4" }, { "input": "3\n2 7 5\n3\n2 4 8", "output": "3" }, { "input": "100\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\n100\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5", "output": "100" }, { "input": "1\n3\n2\n2 3", "output": "1" }, { "input": "2\n5 6\n3\n1 5 100", "output": "1" }, { "input": "2\n2 7\n2\n6 8", "output": "1" }, { "input": "4\n4 10 15 17\n4\n3 12 16 16", "output": "3" }, { "input": "2\n2 3\n2\n1 2", "output": "2" } ]
1,685,192,467
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) def mod(n): if n<=0: return -1*n else: return n a.sort() b.sort() count=0 for i in range(n): if mod(a[i]-b[0])<=1: count+=1 b.pop(0) print(count)
Title: BerSU Ball Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&amp;girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill. Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth line contains sequence *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=100), where *b**j* is the *j*-th girl's dancing skill. Output Specification: Print a single number — the required maximum possible number of pairs. Demo Input: ['4\n1 4 6 2\n5\n5 1 5 7 9\n', '4\n1 2 3 4\n4\n10 11 12 13\n', '5\n1 1 1 1 1\n3\n1 2 3\n'] Demo Output: ['3\n', '0\n', '2\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) def mod(n): if n<=0: return -1*n else: return n a.sort() b.sort() count=0 for i in range(n): if mod(a[i]-b[0])<=1: count+=1 b.pop(0) print(count) ```
0
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,683,477,112
2,147,483,647
Python 3
OK
TESTS
43
92
0
a = (input()) b = (input()) res = int(a)+int(b) a = a.replace("0",'') b = b.replace("0",'') res = str(res) res = res.replace("0",'') res = int(res) a = int(a) b = int(b) if res == (a+b): print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a = (input()) b = (input()) res = int(a)+int(b) a = a.replace("0",'') b = b.replace("0",'') res = str(res) res = res.replace("0",'') res = int(res) a = int(a) b = int(b) if res == (a+b): print("YES") else: print("NO") ```
3.977
675
A
Infinite Sequence
PROGRAMMING
1,100
[ "math" ]
null
null
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
500
[ { "input": "1 7 3", "output": "YES" }, { "input": "10 10 0", "output": "YES" }, { "input": "1 -4 5", "output": "NO" }, { "input": "0 60 50", "output": "NO" }, { "input": "1 -4 -5", "output": "YES" }, { "input": "0 1 0", "output": "NO" }, { "input": "10 10 42", "output": "YES" }, { "input": "-1000000000 1000000000 -1", "output": "NO" }, { "input": "10 16 4", "output": "NO" }, { "input": "-1000000000 1000000000 5", "output": "YES" }, { "input": "1000000000 -1000000000 5", "output": "NO" }, { "input": "1000000000 -1000000000 0", "output": "NO" }, { "input": "1000000000 1000000000 0", "output": "YES" }, { "input": "115078364 -899474523 -1", "output": "YES" }, { "input": "-245436499 416383245 992", "output": "YES" }, { "input": "-719636354 536952440 2", "output": "YES" }, { "input": "-198350539 963391024 68337739", "output": "YES" }, { "input": "-652811055 875986516 1091", "output": "YES" }, { "input": "119057893 -516914539 -39748277", "output": "YES" }, { "input": "989140430 731276607 -36837689", "output": "YES" }, { "input": "677168390 494583489 -985071853", "output": "NO" }, { "input": "58090193 777423708 395693923", "output": "NO" }, { "input": "479823846 -403424770 -653472589", "output": "NO" }, { "input": "-52536829 -132023273 -736287999", "output": "NO" }, { "input": "-198893776 740026818 -547885271", "output": "NO" }, { "input": "-2 -2 -2", "output": "YES" }, { "input": "-2 -2 -1", "output": "YES" }, { "input": "-2 -2 0", "output": "YES" }, { "input": "-2 -2 1", "output": "YES" }, { "input": "-2 -2 2", "output": "YES" }, { "input": "-2 -1 -2", "output": "NO" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "-2 -1 0", "output": "NO" }, { "input": "-2 -1 1", "output": "YES" }, { "input": "-2 -1 2", "output": "NO" }, { "input": "-2 0 -2", "output": "NO" }, { "input": "-2 0 -1", "output": "NO" }, { "input": "-2 0 0", "output": "NO" }, { "input": "-2 0 1", "output": "YES" }, { "input": "-2 0 2", "output": "YES" }, { "input": "-2 1 -2", "output": "NO" }, { "input": "-2 1 -1", "output": "NO" }, { "input": "-2 1 0", "output": "NO" }, { "input": "-2 1 1", "output": "YES" }, { "input": "-2 1 2", "output": "NO" }, { "input": "-2 2 -2", "output": "NO" }, { "input": "-2 2 -1", "output": "NO" }, { "input": "-2 2 0", "output": "NO" }, { "input": "-2 2 1", "output": "YES" }, { "input": "-2 2 2", "output": "YES" }, { "input": "-1 -2 -2", "output": "NO" }, { "input": "-1 -2 -1", "output": "YES" }, { "input": "-1 -2 0", "output": "NO" }, { "input": "-1 -2 1", "output": "NO" }, { "input": "-1 -2 2", "output": "NO" }, { "input": "-1 -1 -2", "output": "YES" }, { "input": "-1 -1 -1", "output": "YES" }, { "input": "-1 -1 0", "output": "YES" }, { "input": "-1 -1 1", "output": "YES" }, { "input": "-1 -1 2", "output": "YES" }, { "input": "-1 0 -2", "output": "NO" }, { "input": "-1 0 -1", "output": "NO" }, { "input": "-1 0 0", "output": "NO" }, { "input": "-1 0 1", "output": "YES" }, { "input": "-1 0 2", "output": "NO" }, { "input": "-1 1 -2", "output": "NO" }, { "input": "-1 1 -1", "output": "NO" }, { "input": "-1 1 0", "output": "NO" }, { "input": "-1 1 1", "output": "YES" }, { "input": "-1 1 2", "output": "YES" }, { "input": "-1 2 -2", "output": "NO" }, { "input": "-1 2 -1", "output": "NO" }, { "input": "-1 2 0", "output": "NO" }, { "input": "-1 2 1", "output": "YES" }, { "input": "-1 2 2", "output": "NO" }, { "input": "0 -2 -2", "output": "YES" }, { "input": "0 -2 -1", "output": "YES" }, { "input": "0 -2 0", "output": "NO" }, { "input": "0 -2 1", "output": "NO" }, { "input": "0 -2 2", "output": "NO" }, { "input": "0 -1 -2", "output": "NO" }, { "input": "0 -1 -1", "output": "YES" }, { "input": "0 -1 0", "output": "NO" }, { "input": "0 -1 1", "output": "NO" }, { "input": "0 -1 2", "output": "NO" }, { "input": "0 0 -2", "output": "YES" }, { "input": "0 0 -1", "output": "YES" }, { "input": "0 0 0", "output": "YES" }, { "input": "0 0 1", "output": "YES" }, { "input": "0 0 2", "output": "YES" }, { "input": "0 1 -2", "output": "NO" }, { "input": "0 1 -1", "output": "NO" }, { "input": "0 1 0", "output": "NO" }, { "input": "0 1 1", "output": "YES" }, { "input": "0 1 2", "output": "NO" }, { "input": "0 2 -2", "output": "NO" }, { "input": "0 2 -1", "output": "NO" }, { "input": "0 2 0", "output": "NO" }, { "input": "0 2 1", "output": "YES" }, { "input": "0 2 2", "output": "YES" }, { "input": "1 -2 -2", "output": "NO" }, { "input": "1 -2 -1", "output": "YES" }, { "input": "1 -2 0", "output": "NO" }, { "input": "1 -2 1", "output": "NO" }, { "input": "1 -2 2", "output": "NO" }, { "input": "1 -1 -2", "output": "YES" }, { "input": "1 -1 -1", "output": "YES" }, { "input": "1 -1 0", "output": "NO" }, { "input": "1 -1 1", "output": "NO" }, { "input": "1 -1 2", "output": "NO" }, { "input": "1 0 -2", "output": "NO" }, { "input": "1 0 -1", "output": "YES" }, { "input": "1 0 0", "output": "NO" }, { "input": "1 0 1", "output": "NO" }, { "input": "1 0 2", "output": "NO" }, { "input": "1 1 -2", "output": "YES" }, { "input": "1 1 -1", "output": "YES" }, { "input": "1 1 0", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "1 1 2", "output": "YES" }, { "input": "1 2 -2", "output": "NO" }, { "input": "1 2 -1", "output": "NO" }, { "input": "1 2 0", "output": "NO" }, { "input": "1 2 1", "output": "YES" }, { "input": "1 2 2", "output": "NO" }, { "input": "2 -2 -2", "output": "YES" }, { "input": "2 -2 -1", "output": "YES" }, { "input": "2 -2 0", "output": "NO" }, { "input": "2 -2 1", "output": "NO" }, { "input": "2 -2 2", "output": "NO" }, { "input": "2 -1 -2", "output": "NO" }, { "input": "2 -1 -1", "output": "YES" }, { "input": "2 -1 0", "output": "NO" }, { "input": "2 -1 1", "output": "NO" }, { "input": "2 -1 2", "output": "NO" }, { "input": "2 0 -2", "output": "YES" }, { "input": "2 0 -1", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "2 0 1", "output": "NO" }, { "input": "2 0 2", "output": "NO" }, { "input": "2 1 -2", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "2 1 0", "output": "NO" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input": "2 2 -2", "output": "YES" }, { "input": "2 2 -1", "output": "YES" }, { "input": "2 2 0", "output": "YES" }, { "input": "2 2 1", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "-1000000000 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 2", "output": "YES" }, { "input": "1000000000 -1000000000 -1", "output": "YES" }, { "input": "5 2 3", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "3 2 1", "output": "NO" }, { "input": "0 -5 -3", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "0 10 1", "output": "YES" }, { "input": "15 5 -5", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "20 10 0", "output": "NO" }, { "input": "20 15 5", "output": "NO" }, { "input": "1 6 1", "output": "YES" }, { "input": "1000000000 0 -1000000000", "output": "YES" }, { "input": "1 1 -5", "output": "YES" }, { "input": "4 6 1", "output": "YES" }, { "input": "-5 -10 -5", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "10 9 -1", "output": "YES" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "1 13 3", "output": "YES" }, { "input": "2 3 0", "output": "NO" }, { "input": "1 1 -1", "output": "YES" }, { "input": "5 -10 -5", "output": "YES" }, { "input": "5 3 1", "output": "NO" }, { "input": "1 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 1000000000", "output": "YES" } ]
1,494,305,032
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a , b , c= map(int,input().split()) if(c!=0 and (b-a)//c==(b-a)/c and (b-a)//c>=0): print('YES') elif c==0 and a==b : ptiny('YES') else : print('NO')
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. Input Specification: The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. Output Specification: If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). Demo Input: ['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
```python a , b , c= map(int,input().split()) if(c!=0 and (b-a)//c==(b-a)/c and (b-a)//c>=0): print('YES') elif c==0 and a==b : ptiny('YES') else : print('NO') ```
-1
805
B
3-palindrome
PROGRAMMING
1,000
[ "constructive algorithms" ]
null
null
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Print the string that satisfies all the constraints. If there are multiple answers, print any of them.
[ "2\n", "3\n" ]
[ "aa\n", "bba\n" ]
A palindrome is a sequence of characters which reads the same backward and forward.
1,000
[ { "input": "2", "output": "aa" }, { "input": "3", "output": "aab" }, { "input": "38", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "47", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "59", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "67", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "77", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "89", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "98", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "109", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "117", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "1", "output": "a" }, { "input": "200000", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "100000", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "143670", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "104217", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "17879", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "131809", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "140873", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "77859", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "153022", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "179227", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "182801", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "5188", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "86539", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "12802", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "120289", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "132866", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "133377", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "31775", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "160397", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "161415", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "163623", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "22942", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "134767", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "52257", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "64905", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "183758", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "60131", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "146883", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "6", "output": "aabbaa" }, { "input": "4", "output": "aabb" } ]
1,667,442,057
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
n=int(input()) if n==3: print('bba') else: for i in range(n//2): if i%2==0: print('aa',end='') else: print('bb',end='') if n%2!=0: print('a')
Title: 3-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. Output Specification: Print the string that satisfies all the constraints. If there are multiple answers, print any of them. Demo Input: ['2\n', '3\n'] Demo Output: ['aa\n', 'bba\n'] Note: A palindrome is a sequence of characters which reads the same backward and forward.
```python n=int(input()) if n==3: print('bba') else: for i in range(n//2): if i%2==0: print('aa',end='') else: print('bb',end='') if n%2!=0: print('a') ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,656,961,687
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
n = int(input()) a = input() ch = [] ch+=a.split() res = [] for i in range(0, len(ch)): ch[i] = int(ch[i]) for i in range(0, len(ch)): if ch[i]%2!=0 and 0<=len(res)<1: for i in range(0, len(ch)): if ch[i] %2 == 0: res.insert(i, ch[i]) break if ch[i]%2 == 0 and 0<=len(res)<1: for i in range(0, len(ch)): if ch[i] %2 != 0: res.insert(i, ch[i]) break print(*res)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n = int(input()) a = input() ch = [] ch+=a.split() res = [] for i in range(0, len(ch)): ch[i] = int(ch[i]) for i in range(0, len(ch)): if ch[i]%2!=0 and 0<=len(res)<1: for i in range(0, len(ch)): if ch[i] %2 == 0: res.insert(i, ch[i]) break if ch[i]%2 == 0 and 0<=len(res)<1: for i in range(0, len(ch)): if ch[i] %2 != 0: res.insert(i, ch[i]) break print(*res) ```
0
606
A
Magic Spheres
PROGRAMMING
1,200
[ "implementation" ]
null
null
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)?
The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that he needs to get.
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
[ "4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.
500
[ { "input": "4 4 0\n2 1 2", "output": "Yes" }, { "input": "5 6 1\n2 7 2", "output": "No" }, { "input": "3 3 3\n2 2 2", "output": "Yes" }, { "input": "0 0 0\n0 0 0", "output": "Yes" }, { "input": "0 0 0\n0 0 1", "output": "No" }, { "input": "0 1 0\n0 0 0", "output": "Yes" }, { "input": "1 0 0\n1 0 0", "output": "Yes" }, { "input": "2 2 1\n1 1 2", "output": "No" }, { "input": "1 3 1\n2 1 1", "output": "Yes" }, { "input": "1000000 1000000 1000000\n1000000 1000000 1000000", "output": "Yes" }, { "input": "1000000 500000 500000\n0 750000 750000", "output": "Yes" }, { "input": "500000 1000000 500000\n750001 0 750000", "output": "No" }, { "input": "499999 500000 1000000\n750000 750000 0", "output": "No" }, { "input": "500000 500000 0\n0 0 500000", "output": "Yes" }, { "input": "0 500001 499999\n500000 0 0", "output": "No" }, { "input": "1000000 500000 1000000\n500000 1000000 500000", "output": "Yes" }, { "input": "1000000 1000000 499999\n500000 500000 1000000", "output": "No" }, { "input": "500000 1000000 1000000\n1000000 500001 500000", "output": "No" }, { "input": "1000000 500000 500000\n0 1000000 500000", "output": "Yes" }, { "input": "500000 500000 1000000\n500001 1000000 0", "output": "No" }, { "input": "500000 999999 500000\n1000000 0 500000", "output": "No" }, { "input": "4 0 3\n2 2 1", "output": "Yes" }, { "input": "0 2 4\n2 0 2", "output": "Yes" }, { "input": "3 1 0\n1 1 1", "output": "Yes" }, { "input": "4 4 1\n1 3 2", "output": "Yes" }, { "input": "1 2 4\n2 1 3", "output": "No" }, { "input": "1 1 0\n0 0 1", "output": "No" }, { "input": "4 0 0\n0 1 1", "output": "Yes" }, { "input": "0 3 0\n1 0 1", "output": "No" }, { "input": "0 0 3\n1 0 1", "output": "Yes" }, { "input": "1 12 1\n4 0 4", "output": "Yes" }, { "input": "4 0 4\n1 2 1", "output": "Yes" }, { "input": "4 4 0\n1 1 3", "output": "No" }, { "input": "0 9 0\n2 2 2", "output": "No" }, { "input": "0 10 0\n2 2 2", "output": "Yes" }, { "input": "9 0 9\n0 8 0", "output": "Yes" }, { "input": "0 9 9\n9 0 0", "output": "No" }, { "input": "9 10 0\n0 0 9", "output": "Yes" }, { "input": "10 0 9\n0 10 0", "output": "No" }, { "input": "0 10 10\n10 0 0", "output": "Yes" }, { "input": "10 10 0\n0 0 11", "output": "No" }, { "input": "307075 152060 414033\n381653 222949 123101", "output": "No" }, { "input": "569950 228830 153718\n162186 357079 229352", "output": "No" }, { "input": "149416 303568 749016\n238307 493997 190377", "output": "No" }, { "input": "438332 298094 225324\n194220 400244 245231", "output": "No" }, { "input": "293792 300060 511272\n400687 382150 133304", "output": "No" }, { "input": "295449 518151 368838\n382897 137148 471892", "output": "No" }, { "input": "191789 291147 691092\n324321 416045 176232", "output": "Yes" }, { "input": "286845 704749 266526\n392296 104421 461239", "output": "Yes" }, { "input": "135522 188282 377041\n245719 212473 108265", "output": "Yes" }, { "input": "404239 359124 133292\n180069 184791 332544", "output": "No" }, { "input": "191906 624432 244408\n340002 367217 205432", "output": "No" }, { "input": "275980 429361 101824\n274288 302579 166062", "output": "No" }, { "input": "136092 364927 395302\n149173 343146 390922", "output": "No" }, { "input": "613852 334661 146012\n363786 326286 275233", "output": "No" }, { "input": "348369 104625 525203\n285621 215396 366411", "output": "No" }, { "input": "225307 153572 114545\n154753 153282 149967", "output": "Yes" }, { "input": "438576 124465 629784\n375118 276028 390116", "output": "Yes" }, { "input": "447521 327510 158732\n395759 178458 259139", "output": "Yes" }, { "input": "8 5 5\n5 5 5", "output": "Yes" }, { "input": "100 100 100\n1 1 1", "output": "Yes" }, { "input": "100 100 100\n0 0 0", "output": "Yes" }, { "input": "3 2 3\n2 3 2", "output": "No" }, { "input": "5 4 3\n2 2 2", "output": "Yes" }, { "input": "14 9 8\n12 5 10", "output": "Yes" }, { "input": "10 10 10\n1 1 1", "output": "Yes" }, { "input": "6 3 3\n3 3 3", "output": "Yes" }, { "input": "10 0 4\n2 4 2", "output": "Yes" }, { "input": "100 100 100\n2 2 2", "output": "Yes" }, { "input": "4 6 0\n2 1 2", "output": "Yes" }, { "input": "4 6 3\n4 2 3", "output": "Yes" }, { "input": "5 5 5\n1 1 1", "output": "Yes" }, { "input": "41 17 34\n0 19 24", "output": "Yes" }, { "input": "8 8 8\n3 3 3", "output": "Yes" }, { "input": "7 7 1\n1 1 2", "output": "Yes" }, { "input": "6 6 0\n2 2 2", "output": "Yes" }, { "input": "5 5 5\n2 2 2", "output": "Yes" }, { "input": "400 400 400\n1 1 1", "output": "Yes" }, { "input": "4 4 4\n2 2 2", "output": "Yes" } ]
1,473,604,425
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
61
0
a = list(map( int , input().split())) b = list(map( int , input().split())) z = 0 for i in range(3): z += max((a[i]-b[i])/2,0) if b[i] > a[i]: z -= b[i] - a[i] print('Yes' if z >= 0 else 'No')
Title: Magic Spheres Time Limit: None seconds Memory Limit: None megabytes Problem Description: Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)? Input Specification: The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that he needs to get. Output Specification: If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". Demo Input: ['4 4 0\n2 1 2\n', '5 6 1\n2 7 2\n', '3 3 3\n2 2 2\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n'] Note: In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.
```python a = list(map( int , input().split())) b = list(map( int , input().split())) z = 0 for i in range(3): z += max((a[i]-b[i])/2,0) if b[i] > a[i]: z -= b[i] - a[i] print('Yes' if z >= 0 else 'No') ```
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,696,160,479
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
str = list(input()) n = len(str) hello = "hello" counter = 0 for i in range(0,n): if(counter < 5 and str[i] == hello[counter]): counter += 1 if(counter >= 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 str = list(input()) n = len(str) hello = "hello" counter = 0 for i in range(0,n): if(counter < 5 and str[i] == hello[counter]): counter += 1 if(counter >= 5): print("YES") else: print("NO") ```
3.969
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,691,910,138
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
class Solution: def needed_flagstones(n: int, m: int, a: int) -> int: flagstone_count = (m * n) / (a * a) if flagstone_count != int(flagstone_count): flagstone_count += 1 return flagstone_count
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 class Solution: def needed_flagstones(n: int, m: int, a: int) -> int: flagstone_count = (m * n) / (a * a) if flagstone_count != int(flagstone_count): flagstone_count += 1 return flagstone_count ```
0
166
A
Rank List
PROGRAMMING
1,100
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
500
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "output": "1" }, { "input": "3 2\n3 3\n3 3\n3 3", "output": "3" }, { "input": "4 3\n10 3\n6 10\n5 2\n5 2", "output": "2" }, { "input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "output": "3" }, { "input": "3 1\n2 1\n1 1\n1 2", "output": "1" }, { "input": "1 1\n28 28", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10", "output": "1" }, { "input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "50" }, { "input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2", "output": "13" }, { "input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2", "output": "1" }, { "input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6", "output": "1" }, { "input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1", "output": "3" }, { "input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "20" }, { "input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2", "output": "6" }, { "input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "30" }, { "input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1", "output": "13" }, { "input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14", "output": "1" }, { "input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30", "output": "2" }, { "input": "2 1\n50 50\n50 50", "output": "2" }, { "input": "2 2\n50 50\n50 50", "output": "2" }, { "input": "2 1\n50 50\n50 49", "output": "1" }, { "input": "2 2\n50 50\n50 49", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50", "output": "50" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49", "output": "49" }, { "input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "1" }, { "input": "4 3\n1 1\n1 2\n2 1\n2 2", "output": "1" }, { "input": "4 2\n1 2\n1 3\n1 5\n1 2", "output": "2" }, { "input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3", "output": "1" }, { "input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1", "output": "2" }, { "input": "3 1\n1 1\n1 2\n1 3", "output": "1" }, { "input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "4" }, { "input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5", "output": "2" }, { "input": "4 1\n1 1\n1 1\n1 2\n1 3", "output": "2" } ]
1,672,165,516
2,147,483,647
Python 3
OK
TESTS
46
92
0
a,b = map(int,input().split()) mat = [] for i in range(a) : arr = list(map(int,input().split())) mat.append(arr) mat = sorted(mat, key = lambda x : (-x[0],x[1])) print(mat.count(mat[b-1]))
Title: Rank List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. Output Specification: In the only line print the sought number of teams that got the *k*-th place in the final results' table. Demo Input: ['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n'] Demo Output: ['3\n', '4\n'] Note: The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
```python a,b = map(int,input().split()) mat = [] for i in range(a) : arr = list(map(int,input().split())) mat.append(arr) mat = sorted(mat, key = lambda x : (-x[0],x[1])) print(mat.count(mat[b-1])) ```
3
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed?
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": "2" }, { "input": "1\n-1", "output": "1" }, { "input": "2\n2\n-1", "output": "2" }, { "input": "2\n-1\n-1", "output": "1" }, { "input": "3\n2\n-1\n1", "output": "3" }, { "input": "3\n-1\n-1\n-1", "output": "1" }, { "input": "5\n4\n5\n1\n-1\n4", "output": "3" }, { "input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7", "output": "4" }, { "input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4", "output": "5" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1", "output": "2" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1", "output": "1" }, { "input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11", "output": "12" }, { "input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2", "output": "11" }, { "input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6", "output": "6" }, { "input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1", "output": "3" }, { "input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1", "output": "2" }, { "input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1", "output": "3" }, { "input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8", "output": "5" }, { "input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10", "output": "6" }, { "input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1", "output": "4" }, { "input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9", "output": "4" }, { "input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8", "output": "3" }, { "input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11", "output": "7" }, { "input": "7\n7\n6\n-1\n-1\n4\n4\n-1", "output": "3" }, { "input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34", "output": "6" }, { "input": "5\n2\n3\n4\n5\n-1", "output": "5" } ]
1,679,928,139
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
38
310
10,547,200
def dfs(deep, father, son): answer = [] if(not son[father]): return [deep-1] for i in son[father]: answer += dfs(deep+1, i, son) return answer n = int(input()) son = [[] for i in range(n+1)] for i in range(1, n+1): a = int(input()) if(a == -1): son[0].append(i) else: son[a].append(i) answer = dfs(1, 0, son) print(max(answer))
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. Output Specification: Print a single integer denoting the minimum number of groups that will be formed in the party. Demo Input: ['5\n-1\n1\n2\n1\n-1\n'] Demo Output: ['3\n'] Note: For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
```python def dfs(deep, father, son): answer = [] if(not son[father]): return [deep-1] for i in son[father]: answer += dfs(deep+1, i, son) return answer n = int(input()) son = [[] for i in range(n+1)] for i in range(1, n+1): a = int(input()) if(a == -1): son[0].append(i) else: son[a].append(i) answer = dfs(1, 0, son) print(max(answer)) ```
-1
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "output": "YES" }, { "input": "10 10\n7 6 4 2 5 10 8 3 9 1", "output": "NO" }, { "input": "12312 0", "output": "YES" }, { "input": "9817239 1\n6323187", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "5 4\n4 2 5 1", "output": "NO" }, { "input": "5 3\n4 3 5", "output": "NO" }, { "input": "500 3\n18 62 445", "output": "YES" }, { "input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362", "output": "NO" }, { "input": "500 8\n365 313 338 410 482 417 325 384", "output": "YES" }, { "input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000", "output": "NO" }, { "input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230", "output": "NO" }, { "input": "10 1\n1", "output": "NO" }, { "input": "10 4\n1 2 4 5", "output": "NO" }, { "input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16", "output": "NO" }, { "input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46", "output": "NO" }, { "input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10", "output": "YES" }, { "input": "10 5\n1 3 5 7 9", "output": "NO" }, { "input": "100 7\n2 3 5 6 8 9 100", "output": "NO" }, { "input": "100 3\n98 99 100", "output": "NO" }, { "input": "100 3\n97 98 99", "output": "NO" }, { "input": "100 3\n96 98 99", "output": "YES" }, { "input": "10 6\n2 3 5 6 8 9", "output": "YES" }, { "input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60", "output": "NO" }, { "input": "10 3\n1 4 6", "output": "NO" }, { "input": "8 3\n2 3 4", "output": "NO" }, { "input": "100 3\n4 5 6", "output": "NO" }, { "input": "10 2\n10 1", "output": "NO" }, { "input": "10 1\n10", "output": "NO" }, { "input": "4 2\n2 3", "output": "YES" }, { "input": "2 1\n1", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "4 3\n2 3 4", "output": "NO" }, { "input": "5 3\n4 2 3", "output": "NO" } ]
1,384,615,909
709
Python 3
RUNTIME_ERROR
TESTS
7
499
204,800
n,m=list(map(int, input().split(' '))) f1 = False f = True if m!=0: a=list(map(int, input().split(' '))) f1 = True else: f = False a = sorted(a) if f1 == True: for i in range(1,len(a)+1): if (i in a and i+1 in a and i+2 in a) or (1 in a) or (n in a): f = False break if f == True: print('YES') else: print('NO')
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). Output Specification: Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". Demo Input: ['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n'] Demo Output: ['NO', 'YES'] Note: none
```python n,m=list(map(int, input().split(' '))) f1 = False f = True if m!=0: a=list(map(int, input().split(' '))) f1 = True else: f = False a = sorted(a) if f1 == True: for i in range(1,len(a)+1): if (i in a and i+1 in a and i+2 in a) or (1 in a) or (n in a): f = False break if f == True: print('YES') else: print('NO') ```
-1
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "input": "eihdi", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "edhii", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto", "output": "YES" }, { "input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm", "output": "YES" }, { "input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv", "output": "YES" }, { "input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs", "output": "YES" }, { "input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji", "output": "YES" }, { "input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn", "output": "YES" }, { "input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx", "output": "YES" }, { "input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy", "output": "YES" }, { "input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc", "output": "YES" }, { "input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef", "output": "NO" }, { "input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa", "output": "YES" }, { "input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg", "output": "YES" }, { "input": "oagjghsidigeh", "output": "NO" }, { "input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz", "output": "YES" }, { "input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi", "output": "YES" }, { "input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx", "output": "YES" }, { "input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq", "output": "YES" } ]
1,655,393,901
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
0
a=input() for i in range((len(a))-4): if a[i]=='h' and a[i+1]=='e' and a[i+2] =='i' and a[i+3]=='d' and a[i+4]=='i': print('NO') quit() print('YES')
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... Input Specification: The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). Output Specification: Output YES if the string *s* contains heidi as a subsequence and NO otherwise. Demo Input: ['abcheaibcdi\n', 'hiedi\n'] Demo Output: ['YES', 'NO'] Note: A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
```python a=input() for i in range((len(a))-4): if a[i]=='h' and a[i+1]=='e' and a[i+2] =='i' and a[i+3]=='d' and a[i+4]=='i': print('NO') quit() print('YES') ```
0
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
1,586,771,668
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
307,200
''' def count(a): s = 'bear' c = 0 n = 0 if(len(a)<len(s)): return -1 for i in range(0,len(a)-3): if(s == a[i:i+4]): k = i - n k = (len(a[i+4:]))*k c += k+(len(a)-i+1) n = i return c-4 def main(): s = input() print(count(s)) main() ''' def checkDistance(nums): prev = -1 for i in range(0,len(nums)): if nums[i] == 1: if(prev != -1 and i-prev<6): return "NO" prev = i return "YES" def main(): test = int(input()) for i in range(0,test): n = int(input()) nums = [int(j) for j in input().split()] print(checkDistance(nums)) main()
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python ''' def count(a): s = 'bear' c = 0 n = 0 if(len(a)<len(s)): return -1 for i in range(0,len(a)-3): if(s == a[i:i+4]): k = i - n k = (len(a[i+4:]))*k c += k+(len(a)-i+1) n = i return c-4 def main(): s = input() print(count(s)) main() ''' def checkDistance(nums): prev = -1 for i in range(0,len(nums)): if nums[i] == 1: if(prev != -1 and i-prev<6): return "NO" prev = i return "YES" def main(): test = int(input()) for i in range(0,test): n = int(input()) nums = [int(j) for j in input().split()] print(checkDistance(nums)) main() ```
-1
911
B
Two Cakes
PROGRAMMING
1,200
[ "binary search", "brute force", "implementation" ]
null
null
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake. Help Ivan to calculate this number *x*!
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
[ "5 2 3\n", "4 7 10\n" ]
[ "1\n", "3\n" ]
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
0
[ { "input": "5 2 3", "output": "1" }, { "input": "4 7 10", "output": "3" }, { "input": "100 100 100", "output": "2" }, { "input": "10 100 3", "output": "3" }, { "input": "2 9 29", "output": "9" }, { "input": "4 6 10", "output": "3" }, { "input": "3 70 58", "output": "35" }, { "input": "5 7 10", "output": "3" }, { "input": "5 30 22", "output": "10" }, { "input": "5 5 6", "output": "2" }, { "input": "2 4 3", "output": "3" }, { "input": "10 10 31", "output": "3" }, { "input": "2 1 1", "output": "1" }, { "input": "10 98 99", "output": "19" }, { "input": "4 10 16", "output": "5" }, { "input": "11 4 8", "output": "1" }, { "input": "5 10 14", "output": "4" }, { "input": "6 7 35", "output": "7" }, { "input": "5 6 7", "output": "2" }, { "input": "4 15 3", "output": "3" }, { "input": "7 48 77", "output": "16" }, { "input": "4 4 10", "output": "3" }, { "input": "4 7 20", "output": "6" }, { "input": "5 2 8", "output": "2" }, { "input": "3 2 3", "output": "1" }, { "input": "14 95 1", "output": "1" }, { "input": "99 82 53", "output": "1" }, { "input": "10 71 27", "output": "9" }, { "input": "5 7 8", "output": "2" }, { "input": "11 77 77", "output": "12" }, { "input": "10 5 28", "output": "3" }, { "input": "7 3 12", "output": "2" }, { "input": "10 15 17", "output": "3" }, { "input": "7 7 7", "output": "1" }, { "input": "4 11 18", "output": "6" }, { "input": "3 3 4", "output": "2" }, { "input": "9 2 10", "output": "1" }, { "input": "100 90 20", "output": "1" }, { "input": "3 2 2", "output": "1" }, { "input": "12 45 60", "output": "8" }, { "input": "3 94 79", "output": "47" }, { "input": "41 67 34", "output": "2" }, { "input": "9 3 23", "output": "2" }, { "input": "10 20 57", "output": "7" }, { "input": "55 27 30", "output": "1" }, { "input": "100 100 10", "output": "1" }, { "input": "20 8 70", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "4 9 15", "output": "5" }, { "input": "3 1 3", "output": "1" }, { "input": "2 94 94", "output": "94" }, { "input": "5 3 11", "output": "2" }, { "input": "4 3 2", "output": "1" }, { "input": "12 12 100", "output": "9" }, { "input": "6 75 91", "output": "25" }, { "input": "3 4 3", "output": "2" }, { "input": "3 2 5", "output": "2" }, { "input": "6 5 15", "output": "3" }, { "input": "4 3 6", "output": "2" }, { "input": "3 9 9", "output": "4" }, { "input": "26 93 76", "output": "6" }, { "input": "41 34 67", "output": "2" }, { "input": "6 12 6", "output": "3" }, { "input": "5 20 8", "output": "5" }, { "input": "2 1 3", "output": "1" }, { "input": "35 66 99", "output": "4" }, { "input": "30 7 91", "output": "3" }, { "input": "5 22 30", "output": "10" }, { "input": "8 19 71", "output": "10" }, { "input": "3 5 6", "output": "3" }, { "input": "5 3 8", "output": "2" }, { "input": "2 4 2", "output": "2" }, { "input": "4 3 7", "output": "2" }, { "input": "5 20 10", "output": "5" }, { "input": "5 100 50", "output": "25" }, { "input": "6 3 10", "output": "2" }, { "input": "2 90 95", "output": "90" }, { "input": "4 8 6", "output": "3" }, { "input": "6 10 3", "output": "2" }, { "input": "3 3 5", "output": "2" }, { "input": "5 33 33", "output": "11" }, { "input": "5 5 8", "output": "2" }, { "input": "19 24 34", "output": "3" }, { "input": "5 5 12", "output": "3" }, { "input": "8 7 10", "output": "2" }, { "input": "5 56 35", "output": "17" }, { "input": "4 3 5", "output": "1" }, { "input": "18 100 50", "output": "8" }, { "input": "5 6 8", "output": "2" }, { "input": "5 98 100", "output": "33" }, { "input": "6 5 8", "output": "2" }, { "input": "3 40 80", "output": "40" }, { "input": "4 8 11", "output": "4" }, { "input": "66 100 99", "output": "3" }, { "input": "17 100 79", "output": "10" }, { "input": "3 2 10", "output": "2" }, { "input": "99 100 99", "output": "2" }, { "input": "21 100 5", "output": "5" }, { "input": "3 10 2", "output": "2" }, { "input": "4 100 63", "output": "33" }, { "input": "2 2 10", "output": "2" }, { "input": "5 94 79", "output": "31" }, { "input": "4 12 5", "output": "4" }, { "input": "5 5 40", "output": "5" }, { "input": "99 99 99", "output": "1" }, { "input": "8 97 44", "output": "16" }, { "input": "11 4 10", "output": "1" }, { "input": "6 3 3", "output": "1" }, { "input": "7 3 4", "output": "1" }, { "input": "8 4 4", "output": "1" }, { "input": "9 4 5", "output": "1" }, { "input": "12 6 6", "output": "1" }, { "input": "4 48 89", "output": "29" }, { "input": "8 3 6", "output": "1" }, { "input": "4 6 3", "output": "2" }, { "input": "5 5 1", "output": "1" }, { "input": "11 6 5", "output": "1" }, { "input": "4 5 4", "output": "2" }, { "input": "6 6 4", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "4 1 3", "output": "1" }, { "input": "3 3 1", "output": "1" }, { "input": "9 4 6", "output": "1" }, { "input": "6 5 6", "output": "1" }, { "input": "2 2 3", "output": "2" }, { "input": "4 5 1", "output": "1" }, { "input": "13 6 7", "output": "1" }, { "input": "14 7 7", "output": "1" }, { "input": "12 97 13", "output": "8" }, { "input": "4 2 9", "output": "2" }, { "input": "10 20 59", "output": "7" }, { "input": "12 34 56", "output": "7" }, { "input": "4 5 9", "output": "3" }, { "input": "2 2 2", "output": "2" }, { "input": "4 66 41", "output": "22" } ]
1,597,165,829
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
20,172,800
n, a, b = list(map(int, input().split())) for i in range(1,101,1): if a//i + b//i < n: print(i-1) break
Title: Two Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake. Help Ivan to calculate this number *x*! Input Specification: The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Specification: Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. Demo Input: ['5 2 3\n', '4 7 10\n'] Demo Output: ['1\n', '3\n'] Note: In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
```python n, a, b = list(map(int, input().split())) for i in range(1,101,1): if a//i + b//i < n: print(i-1) break ```
0
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "4 3\n1 2 3 4", "output": "-1" }, { "input": "5 3\n2 1 1 1 1", "output": "1" }, { "input": "5 3\n1 1 1 1 1", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 1\n2 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 2\n2 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 2\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 3\n3 2 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "-1" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10", "output": "19" } ]
1,631,200,098
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; #define endl '\n' #define sp " " //const double pi = acos(-1); long long mod = 1e9 + 7; //int dp[100000007]; //long long f[100001]; /*long long pow(long long a, long long b, long long MOD) {long long x=1,y=a; while(b > 0){if(b%2 == 1){x=(x*y);if(x>MOD) x%=MOD;}y = (y*y);if(y>MOD) y%=MOD;b /= 2;}return x;} long long InverseEuler(long long n, long long MOD) {return pow(n,MOD-2,MOD);} */ long long multicases(bool q) { if(q == 0) return 1; else {long long x;cin >> x;return x;} } void test_case() { int n,ans = 0,k;cin >> n >> k; set<int>l1; vector<int>l(n);for(int &e : l) {cin >> e;l1.insert(e);} int sz = l1.size(); int k1 = l[k - 1]; for(int i = k ; i < l.size();i++) { if(l[i] != k1) {cout << -1;return;} } while(sz != 1) { l.push_back(k1); if(l.at(0) != k1) sz--; l.erase(l.begin()); ans++; } cout << ans; } int main() { #ifndef ONLINE_JUDGE std::ios_base::sync_with_stdio(0); std::cin.tie(nullptr),std::cout.tie(nullptr); #endif long long t = multicases(0); //cin.ignore(); while(t--) {test_case();} return 0; }
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. Output Specification: Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Demo Input: ['3 2\n3 1 1\n', '3 1\n3 1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
```python #include<bits/stdc++.h> using namespace std; #define endl '\n' #define sp " " //const double pi = acos(-1); long long mod = 1e9 + 7; //int dp[100000007]; //long long f[100001]; /*long long pow(long long a, long long b, long long MOD) {long long x=1,y=a; while(b > 0){if(b%2 == 1){x=(x*y);if(x>MOD) x%=MOD;}y = (y*y);if(y>MOD) y%=MOD;b /= 2;}return x;} long long InverseEuler(long long n, long long MOD) {return pow(n,MOD-2,MOD);} */ long long multicases(bool q) { if(q == 0) return 1; else {long long x;cin >> x;return x;} } void test_case() { int n,ans = 0,k;cin >> n >> k; set<int>l1; vector<int>l(n);for(int &e : l) {cin >> e;l1.insert(e);} int sz = l1.size(); int k1 = l[k - 1]; for(int i = k ; i < l.size();i++) { if(l[i] != k1) {cout << -1;return;} } while(sz != 1) { l.push_back(k1); if(l.at(0) != k1) sz--; l.erase(l.begin()); ans++; } cout << ans; } int main() { #ifndef ONLINE_JUDGE std::ios_base::sync_with_stdio(0); std::cin.tie(nullptr),std::cout.tie(nullptr); #endif long long t = multicases(0); //cin.ignore(); while(t--) {test_case();} return 0; } ```
-1
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,686,844,061
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
n=input() x=0 y=0 i=0 while True: if n[i]=='0': y=0 x+=1 i+=1 if x>7: print("YES") break if i==len(n)-1: print("NO") break else: x=0 y+=1 i+=1 if y>7: print("YES") break if i==len(n)-1: print("NO") break
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python n=input() x=0 y=0 i=0 while True: if n[i]=='0': y=0 x+=1 i+=1 if x>7: print("YES") break if i==len(n)-1: print("NO") break else: x=0 y+=1 i+=1 if y>7: print("YES") break if i==len(n)-1: print("NO") break ```
0
121
A
Lucky Sum
PROGRAMMING
1,100
[ "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2 7\n", "7 7\n" ]
[ "33\n", "7\n" ]
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
500
[ { "input": "2 7", "output": "33" }, { "input": "7 7", "output": "7" }, { "input": "1 9", "output": "125" }, { "input": "4 7", "output": "25" }, { "input": "12 47", "output": "1593" }, { "input": "6 77", "output": "4012" }, { "input": "1 100", "output": "14247" }, { "input": "1000000000 1000000000", "output": "4444444444" }, { "input": "77 77", "output": "77" }, { "input": "69 788", "output": "452195" }, { "input": "474 747", "output": "202794" }, { "input": "4 77777", "output": "4070145675" }, { "input": "1 1000000", "output": "1394675359387" }, { "input": "47 744447", "output": "381286992761" }, { "input": "47444 1000000000", "output": "1394672348253941136" }, { "input": "48 854888", "output": "749733199853" }, { "input": "854444 985555", "output": "582719941728" }, { "input": "774744 774747", "output": "3098985" }, { "input": "654 987654", "output": "1339803940266" }, { "input": "477777 1000000000", "output": "1394672167300009765" }, { "input": "77777 777777777", "output": "407018021649898097" }, { "input": "963 85555574", "output": "7526978888069560" }, { "input": "47 7444", "output": "38125896" }, { "input": "1 1000000000", "output": "1394672350065645019" }, { "input": "474 999888555", "output": "1394177038954402791" }, { "input": "777 1000000000", "output": "1394672350065239125" }, { "input": "7 777777774", "output": "407018023386632646" }, { "input": "369 852", "output": "606732" }, { "input": "47 47", "output": "47" }, { "input": "747 748", "output": "1521" }, { "input": "77777440 77777444", "output": "388887220" }, { "input": "987545885 999875584", "output": "54798666661186800" }, { "input": "2 777777776", "output": "407018024942188226" }, { "input": "1 1", "output": "4" }, { "input": "1 2", "output": "8" }, { "input": "999999999 1000000000", "output": "8888888888" }, { "input": "777777777 1000000000", "output": "987654325123456789" }, { "input": "777777778 1000000000", "output": "987654324345679012" }, { "input": "5 6", "output": "14" }, { "input": "49 49", "output": "74" }, { "input": "6 6", "output": "7" }, { "input": "3 4", "output": "8" } ]
1,587,839,159
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
14
2,000
3,276,800
# cook your dish here from sys import stdin, stdout import math from itertools import permutations, combinations from itertools import combinations_with_replacement from collections import defaultdict from bisect import bisect_right def L(): return list(map(int, stdin.readline().split())) def In(): return map(int, stdin.readline().split()) def I(): return int(stdin.readline()) P = 1000000007 arr = [4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777, 4444, 4447, 4474, 4477, 4744, 4747, 4774, 4777, 7444, 7447, 7474, 7477, 7744, 7747, 7774, 7777, 44444, 44447, 44474, 44477, 44744, 44747, 44774, 44777, 47444, 47447, 47474, 47477, 47744, 47747, 47774, 47777, 74444, 74447, 74474, 74477, 74744, 74747, 74774, 74777, 77444, 77447, 77474, 77477, 77744, 77747, 77774, 77777, 444444, 444447, 444474, 444477, 444744, 444747, 444774, 444777, 447444, 447447, 447474, 447477, 447744, 447747, 447774, 447777, 474444, 474447, 474474, 474477, 474744, 474747, 474774, 474777, 477444, 477447, 477474, 477477, 477744, 477747, 477774, 477777, 744444, 744447, 744474, 744477, 744744, 744747, 744774, 744777, 747444, 747447, 747474, 747477, 747744, 747747, 747774, 747777, 774444, 774447, 774474, 774477, 774744, 774747, 774774, 774777, 777444, 777447, 777474, 777477, 777744, 777747, 777774, 777777, 4444444, 4444447, 4444474, 4444477, 4444744, 4444747, 4444774, 4444777, 4447444, 4447447, 4447474, 4447477, 4447744, 4447747, 4447774, 4447777, 4474444, 4474447, 4474474, 4474477, 4474744, 4474747, 4474774, 4474777, 4477444, 4477447, 4477474, 4477477, 4477744, 4477747, 4477774, 4477777, 4744444, 4744447, 4744474, 4744477, 4744744, 4744747, 4744774, 4744777, 4747444, 4747447, 4747474, 4747477, 4747744, 4747747, 4747774, 4747777, 4774444, 4774447, 4774474, 4774477, 4774744, 4774747, 4774774, 4774777, 4777444, 4777447, 4777474, 4777477, 4777744, 4777747, 4777774, 4777777, 7444444, 7444447, 7444474, 7444477, 7444744, 7444747, 7444774, 7444777, 7447444, 7447447, 7447474, 7447477, 7447744, 7447747, 7447774, 7447777, 7474444, 7474447, 7474474, 7474477, 7474744, 7474747, 7474774, 7474777, 7477444, 7477447, 7477474, 7477477, 7477744, 7477747, 7477774, 7477777, 7744444, 7744447, 7744474, 7744477, 7744744, 7744747, 7744774, 7744777, 7747444, 7747447, 7747474, 7747477, 7747744, 7747747, 7747774, 7747777, 7774444, 7774447, 7774474, 7774477, 7774744, 7774747, 7774774, 7774777, 7777444, 7777447, 7777474, 7777477, 7777744, 7777747, 7777774, 7777777, 44444444, 44444447, 44444474, 44444477, 44444744, 44444747, 44444774, 44444777, 44447444, 44447447, 44447474, 44447477, 44447744, 44447747, 44447774, 44447777, 44474444, 44474447, 44474474, 44474477, 44474744, 44474747, 44474774, 44474777, 44477444, 44477447, 44477474, 44477477, 44477744, 44477747, 44477774, 44477777, 44744444, 44744447, 44744474, 44744477, 44744744, 44744747, 44744774, 44744777, 44747444, 44747447, 44747474, 44747477, 44747744, 44747747, 44747774, 44747777, 44774444, 44774447, 44774474, 44774477, 44774744, 44774747, 44774774, 44774777, 44777444, 44777447, 44777474, 44777477, 44777744, 44777747, 44777774, 44777777, 47444444, 47444447, 47444474, 47444477, 47444744, 47444747, 47444774, 47444777, 47447444, 47447447, 47447474, 47447477, 47447744, 47447747, 47447774, 47447777, 47474444, 47474447, 47474474, 47474477, 47474744, 47474747, 47474774, 47474777, 47477444, 47477447, 47477474, 47477477, 47477744, 47477747, 47477774, 47477777, 47744444, 47744447, 47744474, 47744477, 47744744, 47744747, 47744774, 47744777, 47747444, 47747447, 47747474, 47747477, 47747744, 47747747, 47747774, 47747777, 47774444, 47774447, 47774474, 47774477, 47774744, 47774747, 47774774, 47774777, 47777444, 47777447, 47777474, 47777477, 47777744, 47777747, 47777774, 47777777, 74444444, 74444447, 74444474, 74444477, 74444744, 74444747, 74444774, 74444777, 74447444, 74447447, 74447474, 74447477, 74447744, 74447747, 74447774, 74447777, 74474444, 74474447, 74474474, 74474477, 74474744, 74474747, 74474774, 74474777, 74477444, 74477447, 74477474, 74477477, 74477744, 74477747, 74477774, 74477777, 74744444, 74744447, 74744474, 74744477, 74744744, 74744747, 74744774, 74744777, 74747444, 74747447, 74747474, 74747477, 74747744, 74747747, 74747774, 74747777, 74774444, 74774447, 74774474, 74774477, 74774744, 74774747, 74774774, 74774777, 74777444, 74777447, 74777474, 74777477, 74777744, 74777747, 74777774, 74777777, 77444444, 77444447, 77444474, 77444477, 77444744, 77444747, 77444774, 77444777, 77447444, 77447447, 77447474, 77447477, 77447744, 77447747, 77447774, 77447777, 77474444, 77474447, 77474474, 77474477, 77474744, 77474747, 77474774, 77474777, 77477444, 77477447, 77477474, 77477477, 77477744, 77477747, 77477774, 77477777, 77744444, 77744447, 77744474, 77744477, 77744744, 77744747, 77744774, 77744777, 77747444, 77747447, 77747474, 77747477, 77747744, 77747747, 77747774, 77747777, 77774444, 77774447, 77774474, 77774477, 77774744, 77774747, 77774774, 77774777, 77777444, 77777447, 77777474, 77777477, 77777744, 77777747, 77777774, 77777777, 444444444, 444444447, 444444474, 444444477, 444444744, 444444747, 444444774, 444444777, 444447444, 444447447, 444447474, 444447477, 444447744, 444447747, 444447774, 444447777, 444474444, 444474447, 444474474, 444474477, 444474744, 444474747, 444474774, 444474777, 444477444, 444477447, 444477474, 444477477, 444477744, 444477747, 444477774, 444477777, 444744444, 444744447, 444744474, 444744477, 444744744, 444744747, 444744774, 444744777, 444747444, 444747447, 444747474, 444747477, 444747744, 444747747, 444747774, 444747777, 444774444, 444774447, 444774474, 444774477, 444774744, 444774747, 444774774, 444774777, 444777444, 444777447, 444777474, 444777477, 444777744, 444777747, 444777774, 444777777, 447444444, 447444447, 447444474, 447444477, 447444744, 447444747, 447444774, 447444777, 447447444, 447447447, 447447474, 447447477, 447447744, 447447747, 447447774, 447447777, 447474444, 447474447, 447474474, 447474477, 447474744, 447474747, 447474774, 447474777, 447477444, 447477447, 447477474, 447477477, 447477744, 447477747, 447477774, 447477777, 447744444, 447744447, 447744474, 447744477, 447744744, 447744747, 447744774, 447744777, 447747444, 447747447, 447747474, 447747477, 447747744, 447747747, 447747774, 447747777, 447774444, 447774447, 447774474, 447774477, 447774744, 447774747, 447774774, 447774777, 447777444, 447777447, 447777474, 447777477, 447777744, 447777747, 447777774, 447777777, 474444444, 474444447, 474444474, 474444477, 474444744, 474444747, 474444774, 474444777, 474447444, 474447447, 474447474, 474447477, 474447744, 474447747, 474447774, 474447777, 474474444, 474474447, 474474474, 474474477, 474474744, 474474747, 474474774, 474474777, 474477444, 474477447, 474477474, 474477477, 474477744, 474477747, 474477774, 474477777, 474744444, 474744447, 474744474, 474744477, 474744744, 474744747, 474744774, 474744777, 474747444, 474747447, 474747474, 474747477, 474747744, 474747747, 474747774, 474747777, 474774444, 474774447, 474774474, 474774477, 474774744, 474774747, 474774774, 474774777, 474777444, 474777447, 474777474, 474777477, 474777744, 474777747, 474777774, 474777777, 477444444, 477444447, 477444474, 477444477, 477444744, 477444747, 477444774, 477444777, 477447444, 477447447, 477447474, 477447477, 477447744, 477447747, 477447774, 477447777, 477474444, 477474447, 477474474, 477474477, 477474744, 477474747, 477474774, 477474777, 477477444, 477477447, 477477474, 477477477, 477477744, 477477747, 477477774, 477477777, 477744444, 477744447, 477744474, 477744477, 477744744, 477744747, 477744774, 477744777, 477747444, 477747447, 477747474, 477747477, 477747744, 477747747, 477747774, 477747777, 477774444, 477774447, 477774474, 477774477, 477774744, 477774747, 477774774, 477774777, 477777444, 477777447, 477777474, 477777477, 477777744, 477777747, 477777774, 477777777, 744444444, 744444447, 744444474, 744444477, 744444744, 744444747, 744444774, 744444777, 744447444, 744447447, 744447474, 744447477, 744447744, 744447747, 744447774, 744447777, 744474444, 744474447, 744474474, 744474477, 744474744, 744474747, 744474774, 744474777, 744477444, 744477447, 744477474, 744477477, 744477744, 744477747, 744477774, 744477777, 744744444, 744744447, 744744474, 744744477, 744744744, 744744747, 744744774, 744744777, 744747444, 744747447, 744747474, 744747477, 744747744, 744747747, 744747774, 744747777, 744774444, 744774447, 744774474, 744774477, 744774744, 744774747, 744774774, 744774777, 744777444, 744777447, 744777474, 744777477, 744777744, 744777747, 744777774, 744777777, 747444444, 747444447, 747444474, 747444477, 747444744, 747444747, 747444774, 747444777, 747447444, 747447447, 747447474, 747447477, 747447744, 747447747, 747447774, 747447777, 747474444, 747474447, 747474474, 747474477, 747474744, 747474747, 747474774, 747474777, 747477444, 747477447, 747477474, 747477477, 747477744, 747477747, 747477774, 747477777, 747744444, 747744447, 747744474, 747744477, 747744744, 747744747, 747744774, 747744777, 747747444, 747747447, 747747474, 747747477, 747747744, 747747747, 747747774, 747747777, 747774444, 747774447, 747774474, 747774477, 747774744, 747774747, 747774774, 747774777, 747777444, 747777447, 747777474, 747777477, 747777744, 747777747, 747777774, 747777777, 774444444, 774444447, 774444474, 774444477, 774444744, 774444747, 774444774, 774444777, 774447444, 774447447, 774447474, 774447477, 774447744, 774447747, 774447774, 774447777, 774474444, 774474447, 774474474, 774474477, 774474744, 774474747, 774474774, 774474777, 774477444, 774477447, 774477474, 774477477, 774477744, 774477747, 774477774, 774477777, 774744444, 774744447, 774744474, 774744477, 774744744, 774744747, 774744774, 774744777, 774747444, 774747447, 774747474, 774747477, 774747744, 774747747, 774747774, 774747777, 774774444, 774774447, 774774474, 774774477, 774774744, 774774747, 774774774, 774774777, 774777444, 774777447, 774777474, 774777477, 774777744, 774777747, 774777774, 774777777, 777444444, 777444447, 777444474, 777444477, 777444744, 777444747, 777444774, 777444777, 777447444, 777447447, 777447474, 777447477, 777447744, 777447747, 777447774, 777447777, 777474444, 777474447, 777474474, 777474477, 777474744, 777474747, 777474774, 777474777, 777477444, 777477447, 777477474, 777477477, 777477744, 777477747, 777477774, 777477777, 777744444, 777744447, 777744474, 777744477, 777744744, 777744747, 777744774, 777744777, 777747444, 777747447, 777747474, 777747477, 777747744, 777747747, 777747774, 777747777, 777774444, 777774447, 777774474, 777774477, 777774744, 777774747, 777774774, 777774777, 777777444, 777777447, 777777474, 777777477, 777777744, 777777747, 777777774, 777777777, 4444444444, 4444444447, 4444444474, 4444444477, 4444444744, 4444444747, 4444444774, 4444444777, 4444447444, 4444447447, 4444447474, 4444447477, 4444447744, 4444447747, 4444447774, 4444447777, 4444474444, 4444474447, 4444474474, 4444474477, 4444474744, 4444474747, 4444474774, 4444474777, 4444477444, 4444477447, 4444477474, 4444477477, 4444477744, 4444477747, 4444477774, 4444477777, 4444744444, 4444744447, 4444744474, 4444744477, 4444744744, 4444744747, 4444744774, 4444744777, 4444747444, 4444747447, 4444747474, 4444747477, 4444747744, 4444747747, 4444747774, 4444747777, 4444774444, 4444774447, 4444774474, 4444774477, 4444774744, 4444774747, 4444774774, 4444774777, 4444777444, 4444777447, 4444777474, 4444777477, 4444777744, 4444777747, 4444777774, 4444777777, 4447444444, 4447444447, 4447444474, 4447444477, 4447444744, 4447444747, 4447444774, 4447444777, 4447447444, 4447447447, 4447447474, 4447447477, 4447447744, 4447447747, 4447447774, 4447447777, 4447474444, 4447474447, 4447474474, 4447474477, 4447474744, 4447474747, 4447474774, 4447474777, 4447477444, 4447477447, 4447477474, 4447477477, 4447477744, 4447477747, 4447477774, 4447477777, 4447744444, 4447744447, 4447744474, 4447744477, 4447744744, 4447744747, 4447744774, 4447744777, 4447747444, 4447747447, 4447747474, 4447747477, 4447747744, 4447747747, 4447747774, 4447747777, 4447774444, 4447774447, 4447774474, 4447774477, 4447774744, 4447774747, 4447774774, 4447774777, 4447777444, 4447777447, 4447777474, 4447777477, 4447777744, 4447777747, 4447777774, 4447777777, 4474444444, 4474444447, 4474444474, 4474444477, 4474444744, 4474444747, 4474444774, 4474444777, 4474447444, 4474447447, 4474447474, 4474447477, 4474447744, 4474447747, 4474447774, 4474447777, 4474474444, 4474474447, 4474474474, 4474474477, 4474474744, 4474474747, 4474474774, 4474474777, 4474477444, 4474477447, 4474477474, 4474477477, 4474477744, 4474477747, 4474477774, 4474477777, 4474744444, 4474744447, 4474744474, 4474744477, 4474744744, 4474744747, 4474744774, 4474744777, 4474747444, 4474747447, 4474747474, 4474747477, 4474747744, 4474747747, 4474747774, 4474747777, 4474774444, 4474774447, 4474774474, 4474774477, 4474774744, 4474774747, 4474774774, 4474774777, 4474777444, 4474777447, 4474777474, 4474777477, 4474777744, 4474777747, 4474777774, 4474777777, 4477444444, 4477444447, 4477444474, 4477444477, 4477444744, 4477444747, 4477444774, 4477444777, 4477447444, 4477447447, 4477447474, 4477447477, 4477447744, 4477447747, 4477447774, 4477447777, 4477474444, 4477474447, 4477474474, 4477474477, 4477474744, 4477474747, 4477474774, 4477474777, 4477477444, 4477477447, 4477477474, 4477477477, 4477477744, 4477477747, 4477477774, 4477477777, 4477744444, 4477744447, 4477744474, 4477744477, 4477744744, 4477744747, 4477744774, 4477744777, 4477747444, 4477747447, 4477747474, 4477747477, 4477747744, 4477747747, 4477747774, 4477747777, 4477774444, 4477774447, 4477774474, 4477774477, 4477774744, 4477774747, 4477774774, 4477774777, 4477777444, 4477777447, 4477777474, 4477777477, 4477777744, 4477777747, 4477777774, 4477777777, 4744444444, 4744444447, 4744444474, 4744444477, 4744444744, 4744444747, 4744444774, 4744444777, 4744447444, 4744447447, 4744447474, 4744447477, 4744447744, 4744447747, 4744447774, 4744447777, 4744474444, 4744474447, 4744474474, 4744474477, 4744474744, 4744474747, 4744474774, 4744474777, 4744477444, 4744477447, 4744477474, 4744477477, 4744477744, 4744477747, 4744477774, 4744477777, 4744744444, 4744744447, 4744744474, 4744744477, 4744744744, 4744744747, 4744744774, 4744744777, 4744747444, 4744747447, 4744747474, 4744747477, 4744747744, 4744747747, 4744747774, 4744747777, 4744774444, 4744774447, 4744774474, 4744774477, 4744774744, 4744774747, 4744774774, 4744774777, 4744777444, 4744777447, 4744777474, 4744777477, 4744777744, 4744777747, 4744777774, 4744777777, 4747444444, 4747444447, 4747444474, 4747444477, 4747444744, 4747444747, 4747444774, 4747444777, 4747447444, 4747447447, 4747447474, 4747447477, 4747447744, 4747447747, 4747447774, 4747447777, 4747474444, 4747474447, 4747474474, 4747474477, 4747474744, 4747474747, 4747474774, 4747474777, 4747477444, 4747477447, 4747477474, 4747477477, 4747477744, 4747477747, 4747477774, 4747477777, 4747744444, 4747744447, 4747744474, 4747744477, 4747744744, 4747744747, 4747744774, 4747744777, 4747747444, 4747747447, 4747747474, 4747747477, 4747747744, 4747747747, 4747747774, 4747747777, 4747774444, 4747774447, 4747774474, 4747774477, 4747774744, 4747774747, 4747774774, 4747774777, 4747777444, 4747777447, 4747777474, 4747777477, 4747777744, 4747777747, 4747777774, 4747777777, 4774444444, 4774444447, 4774444474, 4774444477, 4774444744, 4774444747, 4774444774, 4774444777, 4774447444, 4774447447, 4774447474, 4774447477, 4774447744, 4774447747, 4774447774, 4774447777, 4774474444, 4774474447, 4774474474, 4774474477, 4774474744, 4774474747, 4774474774, 4774474777, 4774477444, 4774477447, 4774477474, 4774477477, 4774477744, 4774477747, 4774477774, 4774477777, 4774744444, 4774744447, 4774744474, 4774744477, 4774744744, 4774744747, 4774744774, 4774744777, 4774747444, 4774747447, 4774747474, 4774747477, 4774747744, 4774747747, 4774747774, 4774747777, 4774774444, 4774774447, 4774774474, 4774774477, 4774774744, 4774774747, 4774774774, 4774774777, 4774777444, 4774777447, 4774777474, 4774777477, 4774777744, 4774777747, 4774777774, 4774777777, 4777444444, 4777444447, 4777444474, 4777444477, 4777444744, 4777444747, 4777444774, 4777444777, 4777447444, 4777447447, 4777447474, 4777447477, 4777447744, 4777447747, 4777447774, 4777447777, 4777474444, 4777474447, 4777474474, 4777474477, 4777474744, 4777474747, 4777474774, 4777474777, 4777477444, 4777477447, 4777477474, 4777477477, 4777477744, 4777477747, 4777477774, 4777477777, 4777744444, 4777744447, 4777744474, 4777744477, 4777744744, 4777744747, 4777744774, 4777744777, 4777747444, 4777747447, 4777747474, 4777747477, 4777747744, 4777747747, 4777747774, 4777747777, 4777774444, 4777774447, 4777774474, 4777774477, 4777774744, 4777774747, 4777774774, 4777774777, 4777777444, 4777777447, 4777777474, 4777777477, 4777777744, 4777777747, 4777777774, 4777777777, 7444444444, 7444444447, 7444444474, 7444444477, 7444444744, 7444444747, 7444444774, 7444444777, 7444447444, 7444447447, 7444447474, 7444447477, 7444447744, 7444447747, 7444447774, 7444447777, 7444474444, 7444474447, 7444474474, 7444474477, 7444474744, 7444474747, 7444474774, 7444474777, 7444477444, 7444477447, 7444477474, 7444477477, 7444477744, 7444477747, 7444477774, 7444477777, 7444744444, 7444744447, 7444744474, 7444744477, 7444744744, 7444744747, 7444744774, 7444744777, 7444747444, 7444747447, 7444747474, 7444747477, 7444747744, 7444747747, 7444747774, 7444747777, 7444774444, 7444774447, 7444774474, 7444774477, 7444774744, 7444774747, 7444774774, 7444774777, 7444777444, 7444777447, 7444777474, 7444777477, 7444777744, 7444777747, 7444777774, 7444777777, 7447444444, 7447444447, 7447444474, 7447444477, 7447444744, 7447444747, 7447444774, 7447444777, 7447447444, 7447447447, 7447447474, 7447447477, 7447447744, 7447447747, 7447447774, 7447447777, 7447474444, 7447474447, 7447474474, 7447474477, 7447474744, 7447474747, 7447474774, 7447474777, 7447477444, 7447477447, 7447477474, 7447477477, 7447477744, 7447477747, 7447477774, 7447477777, 7447744444, 7447744447, 7447744474, 7447744477, 7447744744, 7447744747, 7447744774, 7447744777, 7447747444, 7447747447, 7447747474, 7447747477, 7447747744, 7447747747, 7447747774, 7447747777, 7447774444, 7447774447, 7447774474, 7447774477, 7447774744, 7447774747, 7447774774, 7447774777, 7447777444, 7447777447, 7447777474, 7447777477, 7447777744, 7447777747, 7447777774, 7447777777, 7474444444, 7474444447, 7474444474, 7474444477, 7474444744, 7474444747, 7474444774, 7474444777, 7474447444, 7474447447, 7474447474, 7474447477, 7474447744, 7474447747, 7474447774, 7474447777, 7474474444, 7474474447, 7474474474, 7474474477, 7474474744, 7474474747, 7474474774, 7474474777, 7474477444, 7474477447, 7474477474, 7474477477, 7474477744, 7474477747, 7474477774, 7474477777, 7474744444, 7474744447, 7474744474, 7474744477, 7474744744, 7474744747, 7474744774, 7474744777, 7474747444, 7474747447, 7474747474, 7474747477, 7474747744, 7474747747, 7474747774, 7474747777, 7474774444, 7474774447, 7474774474, 7474774477, 7474774744, 7474774747, 7474774774, 7474774777, 7474777444, 7474777447, 7474777474, 7474777477, 7474777744, 7474777747, 7474777774, 7474777777, 7477444444, 7477444447, 7477444474, 7477444477, 7477444744, 7477444747, 7477444774, 7477444777, 7477447444, 7477447447, 7477447474, 7477447477, 7477447744, 7477447747, 7477447774, 7477447777, 7477474444, 7477474447, 7477474474, 7477474477, 7477474744, 7477474747, 7477474774, 7477474777, 7477477444, 7477477447, 7477477474, 7477477477, 7477477744, 7477477747, 7477477774, 7477477777, 7477744444, 7477744447, 7477744474, 7477744477, 7477744744, 7477744747, 7477744774, 7477744777, 7477747444, 7477747447, 7477747474, 7477747477, 7477747744, 7477747747, 7477747774, 7477747777, 7477774444, 7477774447, 7477774474, 7477774477, 7477774744, 7477774747, 7477774774, 7477774777, 7477777444, 7477777447, 7477777474, 7477777477, 7477777744, 7477777747, 7477777774, 7477777777, 7744444444, 7744444447, 7744444474, 7744444477, 7744444744, 7744444747, 7744444774, 7744444777, 7744447444, 7744447447, 7744447474, 7744447477, 7744447744, 7744447747, 7744447774, 7744447777, 7744474444, 7744474447, 7744474474, 7744474477, 7744474744, 7744474747, 7744474774, 7744474777, 7744477444, 7744477447, 7744477474, 7744477477, 7744477744, 7744477747, 7744477774, 7744477777, 7744744444, 7744744447, 7744744474, 7744744477, 7744744744, 7744744747, 7744744774, 7744744777, 7744747444, 7744747447, 7744747474, 7744747477, 7744747744, 7744747747, 7744747774, 7744747777, 7744774444, 7744774447, 7744774474, 7744774477, 7744774744, 7744774747, 7744774774, 7744774777, 7744777444, 7744777447, 7744777474, 7744777477, 7744777744, 7744777747, 7744777774, 7744777777, 7747444444, 7747444447, 7747444474, 7747444477, 7747444744, 7747444747, 7747444774, 7747444777, 7747447444, 7747447447, 7747447474, 7747447477, 7747447744, 7747447747, 7747447774, 7747447777, 7747474444, 7747474447, 7747474474, 7747474477, 7747474744, 7747474747, 7747474774, 7747474777, 7747477444, 7747477447, 7747477474, 7747477477, 7747477744, 7747477747, 7747477774, 7747477777, 7747744444, 7747744447, 7747744474, 7747744477, 7747744744, 7747744747, 7747744774, 7747744777, 7747747444, 7747747447, 7747747474, 7747747477, 7747747744, 7747747747, 7747747774, 7747747777, 7747774444, 7747774447, 7747774474, 7747774477, 7747774744, 7747774747, 7747774774, 7747774777, 7747777444, 7747777447, 7747777474, 7747777477, 7747777744, 7747777747, 7747777774, 7747777777, 7774444444, 7774444447, 7774444474, 7774444477, 7774444744, 7774444747, 7774444774, 7774444777, 7774447444, 7774447447, 7774447474, 7774447477, 7774447744, 7774447747, 7774447774, 7774447777, 7774474444, 7774474447, 7774474474, 7774474477, 7774474744, 7774474747, 7774474774, 7774474777, 7774477444, 7774477447, 7774477474, 7774477477, 7774477744, 7774477747, 7774477774, 7774477777, 7774744444, 7774744447, 7774744474, 7774744477, 7774744744, 7774744747, 7774744774, 7774744777, 7774747444, 7774747447, 7774747474, 7774747477, 7774747744, 7774747747, 7774747774, 7774747777, 7774774444, 7774774447, 7774774474, 7774774477, 7774774744, 7774774747, 7774774774, 7774774777, 7774777444, 7774777447, 7774777474, 7774777477, 7774777744, 7774777747, 7774777774, 7774777777, 7777444444, 7777444447, 7777444474, 7777444477, 7777444744, 7777444747, 7777444774, 7777444777, 7777447444, 7777447447, 7777447474, 7777447477, 7777447744, 7777447747, 7777447774, 7777447777, 7777474444, 7777474447, 7777474474, 7777474477, 7777474744, 7777474747, 7777474774, 7777474777, 7777477444, 7777477447, 7777477474, 7777477477, 7777477744, 7777477747, 7777477774, 7777477777, 7777744444, 7777744447, 7777744474, 7777744477, 7777744744, 7777744747, 7777744774, 7777744777, 7777747444, 7777747447, 7777747474, 7777747477, 7777747744, 7777747747, 7777747774, 7777747777, 7777774444, 7777774447, 7777774474, 7777774477, 7777774744, 7777774747, 7777774774, 7777774777, 7777777444, 7777777447, 7777777474, 7777777477, 7777777744, 7777777747, 7777777774, 7777777777, 44444444444, 44444444447, 44444444474, 44444444477, 44444444744, 44444444747, 44444444774, 44444444777, 44444447444, 44444447447, 44444447474, 44444447477, 44444447744, 44444447747, 44444447774, 44444447777, 44444474444, 44444474447, 44444474474, 44444474477, 44444474744, 44444474747, 44444474774, 44444474777, 44444477444, 44444477447, 44444477474, 44444477477, 44444477744, 44444477747, 44444477774, 44444477777, 44444744444, 44444744447, 44444744474, 44444744477, 44444744744, 44444744747, 44444744774, 44444744777, 44444747444, 44444747447, 44444747474, 44444747477, 44444747744, 44444747747, 44444747774, 44444747777, 44444774444, 44444774447, 44444774474, 44444774477, 44444774744, 44444774747, 44444774774, 44444774777, 44444777444, 44444777447, 44444777474, 44444777477, 44444777744, 44444777747, 44444777774, 44444777777, 44447444444, 44447444447, 44447444474, 44447444477, 44447444744, 44447444747, 44447444774, 44447444777, 44447447444, 44447447447, 44447447474, 44447447477, 44447447744, 44447447747, 44447447774, 44447447777, 44447474444, 44447474447, 44447474474, 44447474477, 44447474744, 44447474747, 44447474774, 44447474777, 44447477444, 44447477447, 44447477474, 44447477477, 44447477744, 44447477747, 44447477774, 44447477777, 44447744444, 44447744447, 44447744474, 44447744477, 44447744744, 44447744747, 44447744774, 44447744777, 44447747444, 44447747447, 44447747474, 44447747477, 44447747744, 44447747747, 44447747774, 44447747777, 44447774444, 44447774447, 44447774474, 44447774477, 44447774744, 44447774747, 44447774774, 44447774777, 44447777444, 44447777447, 44447777474, 44447777477, 44447777744, 44447777747, 44447777774, 44447777777, 44474444444, 44474444447, 44474444474, 44474444477, 44474444744, 44474444747, 44474444774, 44474444777, 44474447444, 44474447447, 44474447474, 44474447477, 44474447744, 44474447747, 44474447774, 44474447777, 44474474444, 44474474447, 44474474474, 44474474477, 44474474744, 44474474747, 44474474774, 44474474777, 44474477444, 44474477447, 44474477474, 44474477477, 44474477744, 44474477747, 44474477774, 44474477777, 44474744444, 44474744447, 44474744474, 44474744477, 44474744744, 44474744747, 44474744774, 44474744777, 44474747444, 44474747447, 44474747474, 44474747477, 44474747744, 44474747747, 44474747774, 44474747777, 44474774444, 44474774447, 44474774474, 44474774477, 44474774744, 44474774747, 44474774774, 44474774777, 44474777444, 44474777447, 44474777474, 44474777477, 44474777744, 44474777747, 44474777774, 44474777777, 44477444444, 44477444447, 44477444474, 44477444477, 44477444744, 44477444747, 44477444774, 44477444777, 44477447444, 44477447447, 44477447474, 44477447477, 44477447744, 44477447747, 44477447774, 44477447777, 44477474444, 44477474447, 44477474474, 44477474477, 44477474744, 44477474747, 44477474774, 44477474777, 44477477444, 44477477447, 44477477474, 44477477477, 44477477744, 44477477747, 44477477774, 44477477777, 44477744444, 44477744447, 44477744474, 44477744477, 44477744744, 44477744747, 44477744774, 44477744777, 44477747444, 44477747447, 44477747474, 44477747477, 44477747744, 44477747747, 44477747774, 44477747777, 44477774444, 44477774447, 44477774474, 44477774477, 44477774744, 44477774747, 44477774774, 44477774777, 44477777444, 44477777447, 44477777474, 44477777477, 44477777744, 44477777747, 44477777774, 44477777777, 44744444444, 44744444447, 44744444474, 44744444477, 44744444744, 44744444747, 44744444774, 44744444777, 44744447444, 44744447447, 44744447474, 44744447477, 44744447744, 44744447747, 44744447774, 44744447777, 44744474444, 44744474447, 44744474474, 44744474477, 44744474744, 44744474747, 44744474774, 44744474777, 44744477444, 44744477447, 44744477474, 44744477477, 44744477744, 44744477747, 44744477774, 44744477777, 44744744444, 44744744447, 44744744474, 44744744477, 44744744744, 44744744747, 44744744774, 44744744777, 44744747444, 44744747447, 44744747474, 44744747477, 44744747744, 44744747747, 44744747774, 44744747777, 44744774444, 44744774447, 44744774474, 44744774477, 44744774744, 44744774747, 44744774774, 44744774777, 44744777444, 44744777447, 44744777474, 44744777477, 44744777744, 44744777747, 44744777774, 44744777777, 44747444444, 44747444447, 44747444474, 44747444477, 44747444744, 44747444747, 44747444774, 44747444777, 44747447444, 44747447447, 44747447474, 44747447477, 44747447744, 44747447747, 44747447774, 44747447777, 44747474444, 44747474447, 44747474474, 44747474477, 44747474744, 44747474747, 44747474774, 44747474777, 44747477444, 44747477447, 44747477474, 44747477477, 44747477744, 44747477747, 44747477774, 44747477777, 44747744444, 44747744447, 44747744474, 44747744477, 44747744744, 44747744747, 44747744774, 44747744777, 44747747444, 44747747447, 44747747474, 44747747477, 44747747744, 44747747747, 44747747774, 44747747777, 44747774444, 44747774447, 44747774474, 44747774477, 44747774744, 44747774747, 44747774774, 44747774777, 44747777444, 44747777447, 44747777474, 44747777477, 44747777744, 44747777747, 44747777774, 44747777777, 44774444444, 44774444447, 44774444474, 44774444477, 44774444744, 44774444747, 44774444774, 44774444777, 44774447444, 44774447447, 44774447474, 44774447477, 44774447744, 44774447747, 44774447774, 44774447777, 44774474444, 44774474447, 44774474474, 44774474477, 44774474744, 44774474747, 44774474774, 44774474777, 44774477444, 44774477447, 44774477474, 44774477477, 44774477744, 44774477747, 44774477774, 44774477777, 44774744444, 44774744447, 44774744474, 44774744477, 44774744744, 44774744747, 44774744774, 44774744777, 44774747444, 44774747447, 44774747474, 44774747477, 44774747744, 44774747747, 44774747774, 44774747777, 44774774444, 44774774447, 44774774474, 44774774477, 44774774744, 44774774747, 44774774774, 44774774777, 44774777444, 44774777447, 44774777474, 44774777477, 44774777744, 44774777747, 44774777774, 44774777777, 44777444444, 44777444447, 44777444474, 44777444477, 44777444744, 44777444747, 44777444774, 44777444777, 44777447444, 44777447447, 44777447474, 44777447477, 44777447744, 44777447747, 44777447774, 44777447777, 44777474444, 44777474447, 44777474474, 44777474477, 44777474744, 44777474747, 44777474774, 44777474777, 44777477444, 44777477447, 44777477474, 44777477477, 44777477744, 44777477747, 44777477774, 44777477777, 44777744444, 44777744447, 44777744474, 44777744477, 44777744744, 44777744747, 44777744774, 44777744777, 44777747444, 44777747447, 44777747474, 44777747477, 44777747744, 44777747747, 44777747774, 44777747777, 44777774444, 44777774447, 44777774474, 44777774477, 44777774744, 44777774747, 44777774774, 44777774777, 44777777444, 44777777447, 44777777474, 44777777477, 44777777744, 44777777747, 44777777774, 44777777777, 47444444444, 47444444447, 47444444474, 47444444477, 47444444744, 47444444747, 47444444774, 47444444777, 47444447444, 47444447447, 47444447474, 47444447477, 47444447744, 47444447747, 47444447774, 47444447777, 47444474444, 47444474447, 47444474474, 47444474477, 47444474744, 47444474747, 47444474774, 47444474777, 47444477444, 47444477447, 47444477474, 47444477477, 47444477744, 47444477747, 47444477774, 47444477777, 47444744444, 47444744447, 47444744474, 47444744477, 47444744744, 47444744747, 47444744774, 47444744777, 47444747444, 47444747447, 47444747474, 47444747477, 47444747744, 47444747747, 47444747774, 47444747777, 47444774444, 47444774447, 47444774474, 47444774477, 47444774744, 47444774747, 47444774774, 47444774777, 47444777444, 47444777447, 47444777474, 47444777477, 47444777744, 47444777747, 47444777774, 47444777777, 47447444444, 47447444447, 47447444474, 47447444477, 47447444744, 47447444747, 47447444774, 47447444777, 47447447444, 47447447447, 47447447474, 47447447477, 47447447744, 47447447747, 47447447774, 47447447777, 47447474444, 47447474447, 47447474474, 47447474477, 47447474744, 47447474747, 47447474774, 47447474777, 47447477444, 47447477447, 47447477474, 47447477477, 47447477744, 47447477747, 47447477774, 47447477777, 47447744444, 47447744447, 47447744474, 47447744477, 47447744744, 47447744747, 47447744774, 47447744777, 47447747444, 47447747447, 47447747474, 47447747477, 47447747744, 47447747747, 47447747774, 47447747777, 47447774444, 47447774447, 47447774474, 47447774477, 47447774744, 47447774747, 47447774774, 47447774777, 47447777444, 47447777447, 47447777474, 47447777477, 47447777744, 47447777747, 47447777774, 47447777777, 47474444444, 47474444447, 47474444474, 47474444477, 47474444744, 47474444747, 47474444774, 47474444777, 47474447444, 47474447447, 47474447474, 47474447477, 47474447744, 47474447747, 47474447774, 47474447777, 47474474444, 47474474447, 47474474474, 47474474477, 47474474744, 47474474747, 47474474774, 47474474777, 47474477444, 47474477447, 47474477474, 47474477477, 47474477744, 47474477747, 47474477774, 47474477777, 47474744444, 47474744447, 47474744474, 47474744477, 47474744744, 47474744747, 47474744774, 47474744777, 47474747444, 47474747447, 47474747474, 47474747477, 47474747744, 47474747747, 47474747774, 47474747777, 47474774444, 47474774447, 47474774474, 47474774477, 47474774744, 47474774747, 47474774774, 47474774777, 47474777444, 47474777447, 47474777474, 47474777477, 47474777744, 47474777747, 47474777774, 47474777777, 47477444444, 47477444447, 47477444474, 47477444477, 47477444744, 47477444747, 47477444774, 47477444777, 47477447444, 47477447447, 47477447474, 47477447477, 47477447744, 47477447747, 47477447774, 47477447777, 47477474444, 47477474447, 47477474474, 47477474477, 47477474744, 47477474747, 47477474774, 47477474777, 47477477444, 47477477447, 47477477474, 47477477477, 47477477744, 47477477747, 47477477774, 47477477777, 47477744444, 47477744447, 47477744474, 47477744477, 47477744744, 47477744747, 47477744774, 47477744777, 47477747444, 47477747447, 47477747474, 47477747477, 47477747744, 47477747747, 47477747774, 47477747777, 47477774444, 47477774447, 47477774474, 47477774477, 47477774744, 47477774747, 47477774774, 47477774777, 47477777444, 47477777447, 47477777474, 47477777477, 47477777744, 47477777747, 47477777774, 47477777777, 47744444444, 47744444447, 47744444474, 47744444477, 47744444744, 47744444747, 47744444774, 47744444777, 47744447444, 47744447447, 47744447474, 47744447477, 47744447744, 47744447747, 47744447774, 47744447777, 47744474444, 47744474447, 47744474474, 47744474477, 47744474744, 47744474747, 47744474774, 47744474777, 47744477444, 47744477447, 47744477474, 47744477477, 47744477744, 47744477747, 47744477774, 47744477777, 47744744444, 47744744447, 47744744474, 47744744477, 47744744744, 47744744747, 47744744774, 47744744777, 47744747444, 47744747447, 47744747474, 47744747477, 47744747744, 47744747747, 47744747774, 47744747777, 47744774444, 47744774447, 47744774474, 47744774477, 47744774744, 47744774747, 47744774774, 47744774777, 47744777444, 47744777447, 47744777474, 47744777477, 47744777744, 47744777747, 47744777774, 47744777777, 47747444444, 47747444447, 47747444474, 47747444477, 47747444744, 47747444747, 47747444774, 47747444777, 47747447444, 47747447447, 47747447474, 47747447477, 47747447744, 47747447747, 47747447774, 47747447777, 47747474444, 47747474447, 47747474474, 47747474477, 47747474744, 47747474747, 47747474774, 47747474777, 47747477444, 47747477447, 47747477474, 47747477477, 47747477744, 47747477747, 47747477774, 47747477777, 47747744444, 47747744447, 47747744474, 47747744477, 47747744744, 47747744747, 47747744774, 47747744777, 47747747444, 47747747447, 47747747474, 47747747477, 47747747744, 47747747747, 47747747774, 47747747777, 47747774444, 47747774447, 47747774474, 47747774477, 47747774744, 47747774747, 47747774774, 47747774777, 47747777444, 47747777447, 47747777474, 47747777477, 47747777744, 47747777747, 47747777774, 47747777777, 47774444444, 47774444447, 47774444474, 47774444477, 47774444744, 47774444747, 47774444774, 47774444777, 47774447444, 47774447447, 47774447474, 47774447477, 47774447744, 47774447747, 47774447774, 47774447777, 47774474444, 47774474447, 47774474474, 47774474477, 47774474744, 47774474747, 47774474774, 47774474777, 47774477444, 47774477447, 47774477474, 47774477477, 47774477744, 47774477747, 47774477774, 47774477777, 47774744444, 47774744447, 47774744474, 47774744477, 47774744744, 47774744747, 47774744774, 47774744777, 47774747444, 47774747447, 47774747474, 47774747477, 47774747744, 47774747747, 47774747774, 47774747777, 47774774444, 47774774447, 47774774474, 47774774477, 47774774744, 47774774747, 47774774774, 47774774777, 47774777444, 47774777447, 47774777474, 47774777477, 47774777744, 47774777747, 47774777774, 47774777777, 47777444444, 47777444447, 47777444474, 47777444477, 47777444744, 47777444747, 47777444774, 47777444777, 47777447444, 47777447447, 47777447474, 47777447477, 47777447744, 47777447747, 47777447774, 47777447777, 47777474444, 47777474447, 47777474474, 47777474477, 47777474744, 47777474747, 47777474774, 47777474777, 47777477444, 47777477447, 47777477474, 47777477477, 47777477744, 47777477747, 47777477774, 47777477777, 47777744444, 47777744447, 47777744474, 47777744477, 47777744744, 47777744747, 47777744774, 47777744777, 47777747444, 47777747447, 47777747474, 47777747477, 47777747744, 47777747747, 47777747774, 47777747777, 47777774444, 47777774447, 47777774474, 47777774477, 47777774744, 47777774747, 47777774774, 47777774777, 47777777444, 47777777447, 47777777474, 47777777477, 47777777744, 47777777747, 47777777774, 47777777777, 74444444444, 74444444447, 74444444474, 74444444477, 74444444744, 74444444747, 74444444774, 74444444777, 74444447444, 74444447447, 74444447474, 74444447477, 74444447744, 74444447747, 74444447774, 74444447777, 74444474444, 74444474447, 74444474474, 74444474477, 74444474744, 74444474747, 74444474774, 74444474777, 74444477444, 74444477447, 74444477474, 74444477477, 74444477744, 74444477747, 74444477774, 74444477777, 74444744444, 74444744447, 74444744474, 74444744477, 74444744744, 74444744747, 74444744774, 74444744777, 74444747444, 74444747447, 74444747474, 74444747477, 74444747744, 74444747747, 74444747774, 74444747777, 74444774444, 74444774447, 74444774474, 74444774477, 74444774744, 74444774747, 74444774774, 74444774777, 74444777444, 74444777447, 74444777474, 74444777477, 74444777744, 74444777747, 74444777774, 74444777777, 74447444444, 74447444447, 74447444474, 74447444477, 74447444744, 74447444747, 74447444774, 74447444777, 74447447444, 74447447447, 74447447474, 74447447477, 74447447744, 74447447747, 74447447774, 74447447777, 74447474444, 74447474447, 74447474474, 74447474477, 74447474744, 74447474747, 74447474774, 74447474777, 74447477444, 74447477447, 74447477474, 74447477477, 74447477744, 74447477747, 74447477774, 74447477777, 74447744444, 74447744447, 74447744474, 74447744477, 74447744744, 74447744747, 74447744774, 74447744777, 74447747444, 74447747447, 74447747474, 74447747477, 74447747744, 74447747747, 74447747774, 74447747777, 74447774444, 74447774447, 74447774474, 74447774477, 74447774744, 74447774747, 74447774774, 74447774777, 74447777444, 74447777447, 74447777474, 74447777477, 74447777744, 74447777747, 74447777774, 74447777777, 74474444444, 74474444447, 74474444474, 74474444477, 74474444744, 74474444747, 74474444774, 74474444777, 74474447444, 74474447447, 74474447474, 74474447477, 74474447744, 74474447747, 74474447774, 74474447777, 74474474444, 74474474447, 74474474474, 74474474477, 74474474744, 74474474747, 74474474774, 74474474777, 74474477444, 74474477447, 74474477474, 74474477477, 74474477744, 74474477747, 74474477774, 74474477777, 74474744444, 74474744447, 74474744474, 74474744477, 74474744744, 74474744747, 74474744774, 74474744777, 74474747444, 74474747447, 74474747474, 74474747477, 74474747744, 74474747747, 74474747774, 74474747777, 74474774444, 74474774447, 74474774474, 74474774477, 74474774744, 74474774747, 74474774774, 74474774777, 74474777444, 74474777447, 74474777474, 74474777477, 74474777744, 74474777747, 74474777774, 74474777777, 74477444444, 74477444447, 74477444474, 74477444477, 74477444744, 74477444747, 74477444774, 74477444777, 74477447444, 74477447447, 74477447474, 74477447477, 74477447744, 74477447747, 74477447774, 74477447777, 74477474444, 74477474447, 74477474474, 74477474477, 74477474744, 74477474747, 74477474774, 74477474777, 74477477444, 74477477447, 74477477474, 74477477477, 74477477744, 74477477747, 74477477774, 74477477777, 74477744444, 74477744447, 74477744474, 74477744477, 74477744744, 74477744747, 74477744774, 74477744777, 74477747444, 74477747447, 74477747474, 74477747477, 74477747744, 74477747747, 74477747774, 74477747777, 74477774444, 74477774447, 74477774474, 74477774477, 74477774744, 74477774747, 74477774774, 74477774777, 74477777444, 74477777447, 74477777474, 74477777477, 74477777744, 74477777747, 74477777774, 74477777777, 74744444444, 74744444447, 74744444474, 74744444477, 74744444744, 74744444747, 74744444774, 74744444777, 74744447444, 74744447447, 74744447474, 74744447477, 74744447744, 74744447747, 74744447774, 74744447777, 74744474444, 74744474447, 74744474474, 74744474477, 74744474744, 74744474747, 74744474774, 74744474777, 74744477444, 74744477447, 74744477474, 74744477477, 74744477744, 74744477747, 74744477774, 74744477777, 74744744444, 74744744447, 74744744474, 74744744477, 74744744744, 74744744747, 74744744774, 74744744777, 74744747444, 74744747447, 74744747474, 74744747477, 74744747744, 74744747747, 74744747774, 74744747777, 74744774444, 74744774447, 74744774474, 74744774477, 74744774744, 74744774747, 74744774774, 74744774777, 74744777444, 74744777447, 74744777474, 74744777477, 74744777744, 74744777747, 74744777774, 74744777777, 74747444444, 74747444447, 74747444474, 74747444477, 74747444744, 74747444747, 74747444774, 74747444777, 74747447444, 74747447447, 74747447474, 74747447477, 74747447744, 74747447747, 74747447774, 74747447777, 74747474444, 74747474447, 74747474474, 74747474477, 74747474744, 74747474747, 74747474774, 74747474777, 74747477444, 74747477447, 74747477474, 74747477477, 74747477744, 74747477747, 74747477774, 74747477777, 74747744444, 74747744447, 74747744474, 74747744477, 74747744744, 74747744747, 74747744774, 74747744777, 74747747444, 74747747447, 74747747474, 74747747477, 74747747744, 74747747747, 74747747774, 74747747777, 74747774444, 74747774447, 74747774474, 74747774477, 74747774744, 74747774747, 74747774774, 74747774777, 74747777444, 74747777447, 74747777474, 74747777477, 74747777744, 74747777747, 74747777774, 74747777777, 74774444444, 74774444447, 74774444474, 74774444477, 74774444744, 74774444747, 74774444774, 74774444777, 74774447444, 74774447447, 74774447474, 74774447477, 74774447744, 74774447747, 74774447774, 74774447777, 74774474444, 74774474447, 74774474474, 74774474477, 74774474744, 74774474747, 74774474774, 74774474777, 74774477444, 74774477447, 74774477474, 74774477477, 74774477744, 74774477747, 74774477774, 74774477777, 74774744444, 74774744447, 74774744474, 74774744477, 74774744744, 74774744747, 74774744774, 74774744777, 74774747444, 74774747447, 74774747474, 74774747477, 74774747744, 74774747747, 74774747774, 74774747777, 74774774444, 74774774447, 74774774474, 74774774477, 74774774744, 74774774747, 74774774774, 74774774777, 74774777444, 74774777447, 74774777474, 74774777477, 74774777744, 74774777747, 74774777774, 74774777777, 74777444444, 74777444447, 74777444474, 74777444477, 74777444744, 74777444747, 74777444774, 74777444777, 74777447444, 74777447447, 74777447474, 74777447477, 74777447744, 74777447747, 74777447774, 74777447777, 74777474444, 74777474447, 74777474474, 74777474477, 74777474744, 74777474747, 74777474774, 74777474777, 74777477444, 74777477447, 74777477474, 74777477477, 74777477744, 74777477747, 74777477774, 74777477777, 74777744444, 74777744447, 74777744474, 74777744477, 74777744744, 74777744747, 74777744774, 74777744777, 74777747444, 74777747447, 74777747474, 74777747477, 74777747744, 74777747747, 74777747774, 74777747777, 74777774444, 74777774447, 74777774474, 74777774477, 74777774744, 74777774747, 74777774774, 74777774777, 74777777444, 74777777447, 74777777474, 74777777477, 74777777744, 74777777747, 74777777774, 74777777777, 77444444444, 77444444447, 77444444474, 77444444477, 77444444744, 77444444747, 77444444774, 77444444777, 77444447444, 77444447447, 77444447474, 77444447477, 77444447744, 77444447747, 77444447774, 77444447777, 77444474444, 77444474447, 77444474474, 77444474477, 77444474744, 77444474747, 77444474774, 77444474777, 77444477444, 77444477447, 77444477474, 77444477477, 77444477744, 77444477747, 77444477774, 77444477777, 77444744444, 77444744447, 77444744474, 77444744477, 77444744744, 77444744747, 77444744774, 77444744777, 77444747444, 77444747447, 77444747474, 77444747477, 77444747744, 77444747747, 77444747774, 77444747777, 77444774444, 77444774447, 77444774474, 77444774477, 77444774744, 77444774747, 77444774774, 77444774777, 77444777444, 77444777447, 77444777474, 77444777477, 77444777744, 77444777747, 77444777774, 77444777777, 77447444444, 77447444447, 77447444474, 77447444477, 77447444744, 77447444747, 77447444774, 77447444777, 77447447444, 77447447447, 77447447474, 77447447477, 77447447744, 77447447747, 77447447774, 77447447777, 77447474444, 77447474447, 77447474474, 77447474477, 77447474744, 77447474747, 77447474774, 77447474777, 77447477444, 77447477447, 77447477474, 77447477477, 77447477744, 77447477747, 77447477774, 77447477777, 77447744444, 77447744447, 77447744474, 77447744477, 77447744744, 77447744747, 77447744774, 77447744777, 77447747444, 77447747447, 77447747474, 77447747477, 77447747744, 77447747747, 77447747774, 77447747777, 77447774444, 77447774447, 77447774474, 77447774477, 77447774744, 77447774747, 77447774774, 77447774777, 77447777444, 77447777447, 77447777474, 77447777477, 77447777744, 77447777747, 77447777774, 77447777777, 77474444444, 77474444447, 77474444474, 77474444477, 77474444744, 77474444747, 77474444774, 77474444777, 77474447444, 77474447447, 77474447474, 77474447477, 77474447744, 77474447747, 77474447774, 77474447777, 77474474444, 77474474447, 77474474474, 77474474477, 77474474744, 77474474747, 77474474774, 77474474777, 77474477444, 77474477447, 77474477474, 77474477477, 77474477744, 77474477747, 77474477774, 77474477777, 77474744444, 77474744447, 77474744474, 77474744477, 77474744744, 77474744747, 77474744774, 77474744777, 77474747444, 77474747447, 77474747474, 77474747477, 77474747744, 77474747747, 77474747774, 77474747777, 77474774444, 77474774447, 77474774474, 77474774477, 77474774744, 77474774747, 77474774774, 77474774777, 77474777444, 77474777447, 77474777474, 77474777477, 77474777744, 77474777747, 77474777774, 77474777777, 77477444444, 77477444447, 77477444474, 77477444477, 77477444744, 77477444747, 77477444774, 77477444777, 77477447444, 77477447447, 77477447474, 77477447477, 77477447744, 77477447747, 77477447774, 77477447777, 77477474444, 77477474447, 77477474474, 77477474477, 77477474744, 77477474747, 77477474774, 77477474777, 77477477444, 77477477447, 77477477474, 77477477477, 77477477744, 77477477747, 77477477774, 77477477777, 77477744444, 77477744447, 77477744474, 77477744477, 77477744744, 77477744747, 77477744774, 77477744777, 77477747444, 77477747447, 77477747474, 77477747477, 77477747744, 77477747747, 77477747774, 77477747777, 77477774444, 77477774447, 77477774474, 77477774477, 77477774744, 77477774747, 77477774774, 77477774777, 77477777444, 77477777447, 77477777474, 77477777477, 77477777744, 77477777747, 77477777774, 77477777777, 77744444444, 77744444447, 77744444474, 77744444477, 77744444744, 77744444747, 77744444774, 77744444777, 77744447444, 77744447447, 77744447474, 77744447477, 77744447744, 77744447747, 77744447774, 77744447777, 77744474444, 77744474447, 77744474474, 77744474477, 77744474744, 77744474747, 77744474774, 77744474777, 77744477444, 77744477447, 77744477474, 77744477477, 77744477744, 77744477747, 77744477774, 77744477777, 77744744444, 77744744447, 77744744474, 77744744477, 77744744744, 77744744747, 77744744774, 77744744777, 77744747444, 77744747447, 77744747474, 77744747477, 77744747744, 77744747747, 77744747774, 77744747777, 77744774444, 77744774447, 77744774474, 77744774477, 77744774744, 77744774747, 77744774774, 77744774777, 77744777444, 77744777447, 77744777474, 77744777477, 77744777744, 77744777747, 77744777774, 77744777777, 77747444444, 77747444447, 77747444474, 77747444477, 77747444744, 77747444747, 77747444774, 77747444777, 77747447444, 77747447447, 77747447474, 77747447477, 77747447744, 77747447747, 77747447774, 77747447777, 77747474444, 77747474447, 77747474474, 77747474477, 77747474744, 77747474747, 77747474774, 77747474777, 77747477444, 77747477447, 77747477474, 77747477477, 77747477744, 77747477747, 77747477774, 77747477777, 77747744444, 77747744447, 77747744474, 77747744477, 77747744744, 77747744747, 77747744774, 77747744777, 77747747444, 77747747447, 77747747474, 77747747477, 77747747744, 77747747747, 77747747774, 77747747777, 77747774444, 77747774447, 77747774474, 77747774477, 77747774744, 77747774747, 77747774774, 77747774777, 77747777444, 77747777447, 77747777474, 77747777477, 77747777744, 77747777747, 77747777774, 77747777777, 77774444444, 77774444447, 77774444474, 77774444477, 77774444744, 77774444747, 77774444774, 77774444777, 77774447444, 77774447447, 77774447474, 77774447477, 77774447744, 77774447747, 77774447774, 77774447777, 77774474444, 77774474447, 77774474474, 77774474477, 77774474744, 77774474747, 77774474774, 77774474777, 77774477444, 77774477447, 77774477474, 77774477477, 77774477744, 77774477747, 77774477774, 77774477777, 77774744444, 77774744447, 77774744474, 77774744477, 77774744744, 77774744747, 77774744774, 77774744777, 77774747444, 77774747447, 77774747474, 77774747477, 77774747744, 77774747747, 77774747774, 77774747777, 77774774444, 77774774447, 77774774474, 77774774477, 77774774744, 77774774747, 77774774774, 77774774777, 77774777444, 77774777447, 77774777474, 77774777477, 77774777744, 77774777747, 77774777774, 77774777777, 77777444444, 77777444447, 77777444474, 77777444477, 77777444744, 77777444747, 77777444774, 77777444777, 77777447444, 77777447447, 77777447474, 77777447477, 77777447744, 77777447747, 77777447774, 77777447777, 77777474444, 77777474447, 77777474474, 77777474477, 77777474744, 77777474747, 77777474774, 77777474777, 77777477444, 77777477447, 77777477474, 77777477477, 77777477744, 77777477747, 77777477774, 77777477777, 77777744444, 77777744447, 77777744474, 77777744477, 77777744744, 77777744747, 77777744774, 77777744777, 77777747444, 77777747447, 77777747474, 77777747477, 77777747744, 77777747747, 77777747774, 77777747777, 77777774444, 77777774447, 77777774474, 77777774477, 77777774744, 77777774747, 77777774774, 77777774777, 77777777444, 77777777447, 77777777474, 77777777477, 77777777744, 77777777747, 77777777774, 77777777777] l, r = In() sm = 0 for i in range(l, r+1): x = bisect_right(arr, i) if arr[x-1] == i: sm += i else: sm += arr[x] print(sm)
Title: Lucky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. Input Specification: The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. Output Specification: In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['2 7\n', '7 7\n'] Demo Output: ['33\n', '7\n'] Note: In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
```python # cook your dish here from sys import stdin, stdout import math from itertools import permutations, combinations from itertools import combinations_with_replacement from collections import defaultdict from bisect import bisect_right def L(): return list(map(int, stdin.readline().split())) def In(): return map(int, stdin.readline().split()) def I(): return int(stdin.readline()) P = 1000000007 arr = [4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777, 4444, 4447, 4474, 4477, 4744, 4747, 4774, 4777, 7444, 7447, 7474, 7477, 7744, 7747, 7774, 7777, 44444, 44447, 44474, 44477, 44744, 44747, 44774, 44777, 47444, 47447, 47474, 47477, 47744, 47747, 47774, 47777, 74444, 74447, 74474, 74477, 74744, 74747, 74774, 74777, 77444, 77447, 77474, 77477, 77744, 77747, 77774, 77777, 444444, 444447, 444474, 444477, 444744, 444747, 444774, 444777, 447444, 447447, 447474, 447477, 447744, 447747, 447774, 447777, 474444, 474447, 474474, 474477, 474744, 474747, 474774, 474777, 477444, 477447, 477474, 477477, 477744, 477747, 477774, 477777, 744444, 744447, 744474, 744477, 744744, 744747, 744774, 744777, 747444, 747447, 747474, 747477, 747744, 747747, 747774, 747777, 774444, 774447, 774474, 774477, 774744, 774747, 774774, 774777, 777444, 777447, 777474, 777477, 777744, 777747, 777774, 777777, 4444444, 4444447, 4444474, 4444477, 4444744, 4444747, 4444774, 4444777, 4447444, 4447447, 4447474, 4447477, 4447744, 4447747, 4447774, 4447777, 4474444, 4474447, 4474474, 4474477, 4474744, 4474747, 4474774, 4474777, 4477444, 4477447, 4477474, 4477477, 4477744, 4477747, 4477774, 4477777, 4744444, 4744447, 4744474, 4744477, 4744744, 4744747, 4744774, 4744777, 4747444, 4747447, 4747474, 4747477, 4747744, 4747747, 4747774, 4747777, 4774444, 4774447, 4774474, 4774477, 4774744, 4774747, 4774774, 4774777, 4777444, 4777447, 4777474, 4777477, 4777744, 4777747, 4777774, 4777777, 7444444, 7444447, 7444474, 7444477, 7444744, 7444747, 7444774, 7444777, 7447444, 7447447, 7447474, 7447477, 7447744, 7447747, 7447774, 7447777, 7474444, 7474447, 7474474, 7474477, 7474744, 7474747, 7474774, 7474777, 7477444, 7477447, 7477474, 7477477, 7477744, 7477747, 7477774, 7477777, 7744444, 7744447, 7744474, 7744477, 7744744, 7744747, 7744774, 7744777, 7747444, 7747447, 7747474, 7747477, 7747744, 7747747, 7747774, 7747777, 7774444, 7774447, 7774474, 7774477, 7774744, 7774747, 7774774, 7774777, 7777444, 7777447, 7777474, 7777477, 7777744, 7777747, 7777774, 7777777, 44444444, 44444447, 44444474, 44444477, 44444744, 44444747, 44444774, 44444777, 44447444, 44447447, 44447474, 44447477, 44447744, 44447747, 44447774, 44447777, 44474444, 44474447, 44474474, 44474477, 44474744, 44474747, 44474774, 44474777, 44477444, 44477447, 44477474, 44477477, 44477744, 44477747, 44477774, 44477777, 44744444, 44744447, 44744474, 44744477, 44744744, 44744747, 44744774, 44744777, 44747444, 44747447, 44747474, 44747477, 44747744, 44747747, 44747774, 44747777, 44774444, 44774447, 44774474, 44774477, 44774744, 44774747, 44774774, 44774777, 44777444, 44777447, 44777474, 44777477, 44777744, 44777747, 44777774, 44777777, 47444444, 47444447, 47444474, 47444477, 47444744, 47444747, 47444774, 47444777, 47447444, 47447447, 47447474, 47447477, 47447744, 47447747, 47447774, 47447777, 47474444, 47474447, 47474474, 47474477, 47474744, 47474747, 47474774, 47474777, 47477444, 47477447, 47477474, 47477477, 47477744, 47477747, 47477774, 47477777, 47744444, 47744447, 47744474, 47744477, 47744744, 47744747, 47744774, 47744777, 47747444, 47747447, 47747474, 47747477, 47747744, 47747747, 47747774, 47747777, 47774444, 47774447, 47774474, 47774477, 47774744, 47774747, 47774774, 47774777, 47777444, 47777447, 47777474, 47777477, 47777744, 47777747, 47777774, 47777777, 74444444, 74444447, 74444474, 74444477, 74444744, 74444747, 74444774, 74444777, 74447444, 74447447, 74447474, 74447477, 74447744, 74447747, 74447774, 74447777, 74474444, 74474447, 74474474, 74474477, 74474744, 74474747, 74474774, 74474777, 74477444, 74477447, 74477474, 74477477, 74477744, 74477747, 74477774, 74477777, 74744444, 74744447, 74744474, 74744477, 74744744, 74744747, 74744774, 74744777, 74747444, 74747447, 74747474, 74747477, 74747744, 74747747, 74747774, 74747777, 74774444, 74774447, 74774474, 74774477, 74774744, 74774747, 74774774, 74774777, 74777444, 74777447, 74777474, 74777477, 74777744, 74777747, 74777774, 74777777, 77444444, 77444447, 77444474, 77444477, 77444744, 77444747, 77444774, 77444777, 77447444, 77447447, 77447474, 77447477, 77447744, 77447747, 77447774, 77447777, 77474444, 77474447, 77474474, 77474477, 77474744, 77474747, 77474774, 77474777, 77477444, 77477447, 77477474, 77477477, 77477744, 77477747, 77477774, 77477777, 77744444, 77744447, 77744474, 77744477, 77744744, 77744747, 77744774, 77744777, 77747444, 77747447, 77747474, 77747477, 77747744, 77747747, 77747774, 77747777, 77774444, 77774447, 77774474, 77774477, 77774744, 77774747, 77774774, 77774777, 77777444, 77777447, 77777474, 77777477, 77777744, 77777747, 77777774, 77777777, 444444444, 444444447, 444444474, 444444477, 444444744, 444444747, 444444774, 444444777, 444447444, 444447447, 444447474, 444447477, 444447744, 444447747, 444447774, 444447777, 444474444, 444474447, 444474474, 444474477, 444474744, 444474747, 444474774, 444474777, 444477444, 444477447, 444477474, 444477477, 444477744, 444477747, 444477774, 444477777, 444744444, 444744447, 444744474, 444744477, 444744744, 444744747, 444744774, 444744777, 444747444, 444747447, 444747474, 444747477, 444747744, 444747747, 444747774, 444747777, 444774444, 444774447, 444774474, 444774477, 444774744, 444774747, 444774774, 444774777, 444777444, 444777447, 444777474, 444777477, 444777744, 444777747, 444777774, 444777777, 447444444, 447444447, 447444474, 447444477, 447444744, 447444747, 447444774, 447444777, 447447444, 447447447, 447447474, 447447477, 447447744, 447447747, 447447774, 447447777, 447474444, 447474447, 447474474, 447474477, 447474744, 447474747, 447474774, 447474777, 447477444, 447477447, 447477474, 447477477, 447477744, 447477747, 447477774, 447477777, 447744444, 447744447, 447744474, 447744477, 447744744, 447744747, 447744774, 447744777, 447747444, 447747447, 447747474, 447747477, 447747744, 447747747, 447747774, 447747777, 447774444, 447774447, 447774474, 447774477, 447774744, 447774747, 447774774, 447774777, 447777444, 447777447, 447777474, 447777477, 447777744, 447777747, 447777774, 447777777, 474444444, 474444447, 474444474, 474444477, 474444744, 474444747, 474444774, 474444777, 474447444, 474447447, 474447474, 474447477, 474447744, 474447747, 474447774, 474447777, 474474444, 474474447, 474474474, 474474477, 474474744, 474474747, 474474774, 474474777, 474477444, 474477447, 474477474, 474477477, 474477744, 474477747, 474477774, 474477777, 474744444, 474744447, 474744474, 474744477, 474744744, 474744747, 474744774, 474744777, 474747444, 474747447, 474747474, 474747477, 474747744, 474747747, 474747774, 474747777, 474774444, 474774447, 474774474, 474774477, 474774744, 474774747, 474774774, 474774777, 474777444, 474777447, 474777474, 474777477, 474777744, 474777747, 474777774, 474777777, 477444444, 477444447, 477444474, 477444477, 477444744, 477444747, 477444774, 477444777, 477447444, 477447447, 477447474, 477447477, 477447744, 477447747, 477447774, 477447777, 477474444, 477474447, 477474474, 477474477, 477474744, 477474747, 477474774, 477474777, 477477444, 477477447, 477477474, 477477477, 477477744, 477477747, 477477774, 477477777, 477744444, 477744447, 477744474, 477744477, 477744744, 477744747, 477744774, 477744777, 477747444, 477747447, 477747474, 477747477, 477747744, 477747747, 477747774, 477747777, 477774444, 477774447, 477774474, 477774477, 477774744, 477774747, 477774774, 477774777, 477777444, 477777447, 477777474, 477777477, 477777744, 477777747, 477777774, 477777777, 744444444, 744444447, 744444474, 744444477, 744444744, 744444747, 744444774, 744444777, 744447444, 744447447, 744447474, 744447477, 744447744, 744447747, 744447774, 744447777, 744474444, 744474447, 744474474, 744474477, 744474744, 744474747, 744474774, 744474777, 744477444, 744477447, 744477474, 744477477, 744477744, 744477747, 744477774, 744477777, 744744444, 744744447, 744744474, 744744477, 744744744, 744744747, 744744774, 744744777, 744747444, 744747447, 744747474, 744747477, 744747744, 744747747, 744747774, 744747777, 744774444, 744774447, 744774474, 744774477, 744774744, 744774747, 744774774, 744774777, 744777444, 744777447, 744777474, 744777477, 744777744, 744777747, 744777774, 744777777, 747444444, 747444447, 747444474, 747444477, 747444744, 747444747, 747444774, 747444777, 747447444, 747447447, 747447474, 747447477, 747447744, 747447747, 747447774, 747447777, 747474444, 747474447, 747474474, 747474477, 747474744, 747474747, 747474774, 747474777, 747477444, 747477447, 747477474, 747477477, 747477744, 747477747, 747477774, 747477777, 747744444, 747744447, 747744474, 747744477, 747744744, 747744747, 747744774, 747744777, 747747444, 747747447, 747747474, 747747477, 747747744, 747747747, 747747774, 747747777, 747774444, 747774447, 747774474, 747774477, 747774744, 747774747, 747774774, 747774777, 747777444, 747777447, 747777474, 747777477, 747777744, 747777747, 747777774, 747777777, 774444444, 774444447, 774444474, 774444477, 774444744, 774444747, 774444774, 774444777, 774447444, 774447447, 774447474, 774447477, 774447744, 774447747, 774447774, 774447777, 774474444, 774474447, 774474474, 774474477, 774474744, 774474747, 774474774, 774474777, 774477444, 774477447, 774477474, 774477477, 774477744, 774477747, 774477774, 774477777, 774744444, 774744447, 774744474, 774744477, 774744744, 774744747, 774744774, 774744777, 774747444, 774747447, 774747474, 774747477, 774747744, 774747747, 774747774, 774747777, 774774444, 774774447, 774774474, 774774477, 774774744, 774774747, 774774774, 774774777, 774777444, 774777447, 774777474, 774777477, 774777744, 774777747, 774777774, 774777777, 777444444, 777444447, 777444474, 777444477, 777444744, 777444747, 777444774, 777444777, 777447444, 777447447, 777447474, 777447477, 777447744, 777447747, 777447774, 777447777, 777474444, 777474447, 777474474, 777474477, 777474744, 777474747, 777474774, 777474777, 777477444, 777477447, 777477474, 777477477, 777477744, 777477747, 777477774, 777477777, 777744444, 777744447, 777744474, 777744477, 777744744, 777744747, 777744774, 777744777, 777747444, 777747447, 777747474, 777747477, 777747744, 777747747, 777747774, 777747777, 777774444, 777774447, 777774474, 777774477, 777774744, 777774747, 777774774, 777774777, 777777444, 777777447, 777777474, 777777477, 777777744, 777777747, 777777774, 777777777, 4444444444, 4444444447, 4444444474, 4444444477, 4444444744, 4444444747, 4444444774, 4444444777, 4444447444, 4444447447, 4444447474, 4444447477, 4444447744, 4444447747, 4444447774, 4444447777, 4444474444, 4444474447, 4444474474, 4444474477, 4444474744, 4444474747, 4444474774, 4444474777, 4444477444, 4444477447, 4444477474, 4444477477, 4444477744, 4444477747, 4444477774, 4444477777, 4444744444, 4444744447, 4444744474, 4444744477, 4444744744, 4444744747, 4444744774, 4444744777, 4444747444, 4444747447, 4444747474, 4444747477, 4444747744, 4444747747, 4444747774, 4444747777, 4444774444, 4444774447, 4444774474, 4444774477, 4444774744, 4444774747, 4444774774, 4444774777, 4444777444, 4444777447, 4444777474, 4444777477, 4444777744, 4444777747, 4444777774, 4444777777, 4447444444, 4447444447, 4447444474, 4447444477, 4447444744, 4447444747, 4447444774, 4447444777, 4447447444, 4447447447, 4447447474, 4447447477, 4447447744, 4447447747, 4447447774, 4447447777, 4447474444, 4447474447, 4447474474, 4447474477, 4447474744, 4447474747, 4447474774, 4447474777, 4447477444, 4447477447, 4447477474, 4447477477, 4447477744, 4447477747, 4447477774, 4447477777, 4447744444, 4447744447, 4447744474, 4447744477, 4447744744, 4447744747, 4447744774, 4447744777, 4447747444, 4447747447, 4447747474, 4447747477, 4447747744, 4447747747, 4447747774, 4447747777, 4447774444, 4447774447, 4447774474, 4447774477, 4447774744, 4447774747, 4447774774, 4447774777, 4447777444, 4447777447, 4447777474, 4447777477, 4447777744, 4447777747, 4447777774, 4447777777, 4474444444, 4474444447, 4474444474, 4474444477, 4474444744, 4474444747, 4474444774, 4474444777, 4474447444, 4474447447, 4474447474, 4474447477, 4474447744, 4474447747, 4474447774, 4474447777, 4474474444, 4474474447, 4474474474, 4474474477, 4474474744, 4474474747, 4474474774, 4474474777, 4474477444, 4474477447, 4474477474, 4474477477, 4474477744, 4474477747, 4474477774, 4474477777, 4474744444, 4474744447, 4474744474, 4474744477, 4474744744, 4474744747, 4474744774, 4474744777, 4474747444, 4474747447, 4474747474, 4474747477, 4474747744, 4474747747, 4474747774, 4474747777, 4474774444, 4474774447, 4474774474, 4474774477, 4474774744, 4474774747, 4474774774, 4474774777, 4474777444, 4474777447, 4474777474, 4474777477, 4474777744, 4474777747, 4474777774, 4474777777, 4477444444, 4477444447, 4477444474, 4477444477, 4477444744, 4477444747, 4477444774, 4477444777, 4477447444, 4477447447, 4477447474, 4477447477, 4477447744, 4477447747, 4477447774, 4477447777, 4477474444, 4477474447, 4477474474, 4477474477, 4477474744, 4477474747, 4477474774, 4477474777, 4477477444, 4477477447, 4477477474, 4477477477, 4477477744, 4477477747, 4477477774, 4477477777, 4477744444, 4477744447, 4477744474, 4477744477, 4477744744, 4477744747, 4477744774, 4477744777, 4477747444, 4477747447, 4477747474, 4477747477, 4477747744, 4477747747, 4477747774, 4477747777, 4477774444, 4477774447, 4477774474, 4477774477, 4477774744, 4477774747, 4477774774, 4477774777, 4477777444, 4477777447, 4477777474, 4477777477, 4477777744, 4477777747, 4477777774, 4477777777, 4744444444, 4744444447, 4744444474, 4744444477, 4744444744, 4744444747, 4744444774, 4744444777, 4744447444, 4744447447, 4744447474, 4744447477, 4744447744, 4744447747, 4744447774, 4744447777, 4744474444, 4744474447, 4744474474, 4744474477, 4744474744, 4744474747, 4744474774, 4744474777, 4744477444, 4744477447, 4744477474, 4744477477, 4744477744, 4744477747, 4744477774, 4744477777, 4744744444, 4744744447, 4744744474, 4744744477, 4744744744, 4744744747, 4744744774, 4744744777, 4744747444, 4744747447, 4744747474, 4744747477, 4744747744, 4744747747, 4744747774, 4744747777, 4744774444, 4744774447, 4744774474, 4744774477, 4744774744, 4744774747, 4744774774, 4744774777, 4744777444, 4744777447, 4744777474, 4744777477, 4744777744, 4744777747, 4744777774, 4744777777, 4747444444, 4747444447, 4747444474, 4747444477, 4747444744, 4747444747, 4747444774, 4747444777, 4747447444, 4747447447, 4747447474, 4747447477, 4747447744, 4747447747, 4747447774, 4747447777, 4747474444, 4747474447, 4747474474, 4747474477, 4747474744, 4747474747, 4747474774, 4747474777, 4747477444, 4747477447, 4747477474, 4747477477, 4747477744, 4747477747, 4747477774, 4747477777, 4747744444, 4747744447, 4747744474, 4747744477, 4747744744, 4747744747, 4747744774, 4747744777, 4747747444, 4747747447, 4747747474, 4747747477, 4747747744, 4747747747, 4747747774, 4747747777, 4747774444, 4747774447, 4747774474, 4747774477, 4747774744, 4747774747, 4747774774, 4747774777, 4747777444, 4747777447, 4747777474, 4747777477, 4747777744, 4747777747, 4747777774, 4747777777, 4774444444, 4774444447, 4774444474, 4774444477, 4774444744, 4774444747, 4774444774, 4774444777, 4774447444, 4774447447, 4774447474, 4774447477, 4774447744, 4774447747, 4774447774, 4774447777, 4774474444, 4774474447, 4774474474, 4774474477, 4774474744, 4774474747, 4774474774, 4774474777, 4774477444, 4774477447, 4774477474, 4774477477, 4774477744, 4774477747, 4774477774, 4774477777, 4774744444, 4774744447, 4774744474, 4774744477, 4774744744, 4774744747, 4774744774, 4774744777, 4774747444, 4774747447, 4774747474, 4774747477, 4774747744, 4774747747, 4774747774, 4774747777, 4774774444, 4774774447, 4774774474, 4774774477, 4774774744, 4774774747, 4774774774, 4774774777, 4774777444, 4774777447, 4774777474, 4774777477, 4774777744, 4774777747, 4774777774, 4774777777, 4777444444, 4777444447, 4777444474, 4777444477, 4777444744, 4777444747, 4777444774, 4777444777, 4777447444, 4777447447, 4777447474, 4777447477, 4777447744, 4777447747, 4777447774, 4777447777, 4777474444, 4777474447, 4777474474, 4777474477, 4777474744, 4777474747, 4777474774, 4777474777, 4777477444, 4777477447, 4777477474, 4777477477, 4777477744, 4777477747, 4777477774, 4777477777, 4777744444, 4777744447, 4777744474, 4777744477, 4777744744, 4777744747, 4777744774, 4777744777, 4777747444, 4777747447, 4777747474, 4777747477, 4777747744, 4777747747, 4777747774, 4777747777, 4777774444, 4777774447, 4777774474, 4777774477, 4777774744, 4777774747, 4777774774, 4777774777, 4777777444, 4777777447, 4777777474, 4777777477, 4777777744, 4777777747, 4777777774, 4777777777, 7444444444, 7444444447, 7444444474, 7444444477, 7444444744, 7444444747, 7444444774, 7444444777, 7444447444, 7444447447, 7444447474, 7444447477, 7444447744, 7444447747, 7444447774, 7444447777, 7444474444, 7444474447, 7444474474, 7444474477, 7444474744, 7444474747, 7444474774, 7444474777, 7444477444, 7444477447, 7444477474, 7444477477, 7444477744, 7444477747, 7444477774, 7444477777, 7444744444, 7444744447, 7444744474, 7444744477, 7444744744, 7444744747, 7444744774, 7444744777, 7444747444, 7444747447, 7444747474, 7444747477, 7444747744, 7444747747, 7444747774, 7444747777, 7444774444, 7444774447, 7444774474, 7444774477, 7444774744, 7444774747, 7444774774, 7444774777, 7444777444, 7444777447, 7444777474, 7444777477, 7444777744, 7444777747, 7444777774, 7444777777, 7447444444, 7447444447, 7447444474, 7447444477, 7447444744, 7447444747, 7447444774, 7447444777, 7447447444, 7447447447, 7447447474, 7447447477, 7447447744, 7447447747, 7447447774, 7447447777, 7447474444, 7447474447, 7447474474, 7447474477, 7447474744, 7447474747, 7447474774, 7447474777, 7447477444, 7447477447, 7447477474, 7447477477, 7447477744, 7447477747, 7447477774, 7447477777, 7447744444, 7447744447, 7447744474, 7447744477, 7447744744, 7447744747, 7447744774, 7447744777, 7447747444, 7447747447, 7447747474, 7447747477, 7447747744, 7447747747, 7447747774, 7447747777, 7447774444, 7447774447, 7447774474, 7447774477, 7447774744, 7447774747, 7447774774, 7447774777, 7447777444, 7447777447, 7447777474, 7447777477, 7447777744, 7447777747, 7447777774, 7447777777, 7474444444, 7474444447, 7474444474, 7474444477, 7474444744, 7474444747, 7474444774, 7474444777, 7474447444, 7474447447, 7474447474, 7474447477, 7474447744, 7474447747, 7474447774, 7474447777, 7474474444, 7474474447, 7474474474, 7474474477, 7474474744, 7474474747, 7474474774, 7474474777, 7474477444, 7474477447, 7474477474, 7474477477, 7474477744, 7474477747, 7474477774, 7474477777, 7474744444, 7474744447, 7474744474, 7474744477, 7474744744, 7474744747, 7474744774, 7474744777, 7474747444, 7474747447, 7474747474, 7474747477, 7474747744, 7474747747, 7474747774, 7474747777, 7474774444, 7474774447, 7474774474, 7474774477, 7474774744, 7474774747, 7474774774, 7474774777, 7474777444, 7474777447, 7474777474, 7474777477, 7474777744, 7474777747, 7474777774, 7474777777, 7477444444, 7477444447, 7477444474, 7477444477, 7477444744, 7477444747, 7477444774, 7477444777, 7477447444, 7477447447, 7477447474, 7477447477, 7477447744, 7477447747, 7477447774, 7477447777, 7477474444, 7477474447, 7477474474, 7477474477, 7477474744, 7477474747, 7477474774, 7477474777, 7477477444, 7477477447, 7477477474, 7477477477, 7477477744, 7477477747, 7477477774, 7477477777, 7477744444, 7477744447, 7477744474, 7477744477, 7477744744, 7477744747, 7477744774, 7477744777, 7477747444, 7477747447, 7477747474, 7477747477, 7477747744, 7477747747, 7477747774, 7477747777, 7477774444, 7477774447, 7477774474, 7477774477, 7477774744, 7477774747, 7477774774, 7477774777, 7477777444, 7477777447, 7477777474, 7477777477, 7477777744, 7477777747, 7477777774, 7477777777, 7744444444, 7744444447, 7744444474, 7744444477, 7744444744, 7744444747, 7744444774, 7744444777, 7744447444, 7744447447, 7744447474, 7744447477, 7744447744, 7744447747, 7744447774, 7744447777, 7744474444, 7744474447, 7744474474, 7744474477, 7744474744, 7744474747, 7744474774, 7744474777, 7744477444, 7744477447, 7744477474, 7744477477, 7744477744, 7744477747, 7744477774, 7744477777, 7744744444, 7744744447, 7744744474, 7744744477, 7744744744, 7744744747, 7744744774, 7744744777, 7744747444, 7744747447, 7744747474, 7744747477, 7744747744, 7744747747, 7744747774, 7744747777, 7744774444, 7744774447, 7744774474, 7744774477, 7744774744, 7744774747, 7744774774, 7744774777, 7744777444, 7744777447, 7744777474, 7744777477, 7744777744, 7744777747, 7744777774, 7744777777, 7747444444, 7747444447, 7747444474, 7747444477, 7747444744, 7747444747, 7747444774, 7747444777, 7747447444, 7747447447, 7747447474, 7747447477, 7747447744, 7747447747, 7747447774, 7747447777, 7747474444, 7747474447, 7747474474, 7747474477, 7747474744, 7747474747, 7747474774, 7747474777, 7747477444, 7747477447, 7747477474, 7747477477, 7747477744, 7747477747, 7747477774, 7747477777, 7747744444, 7747744447, 7747744474, 7747744477, 7747744744, 7747744747, 7747744774, 7747744777, 7747747444, 7747747447, 7747747474, 7747747477, 7747747744, 7747747747, 7747747774, 7747747777, 7747774444, 7747774447, 7747774474, 7747774477, 7747774744, 7747774747, 7747774774, 7747774777, 7747777444, 7747777447, 7747777474, 7747777477, 7747777744, 7747777747, 7747777774, 7747777777, 7774444444, 7774444447, 7774444474, 7774444477, 7774444744, 7774444747, 7774444774, 7774444777, 7774447444, 7774447447, 7774447474, 7774447477, 7774447744, 7774447747, 7774447774, 7774447777, 7774474444, 7774474447, 7774474474, 7774474477, 7774474744, 7774474747, 7774474774, 7774474777, 7774477444, 7774477447, 7774477474, 7774477477, 7774477744, 7774477747, 7774477774, 7774477777, 7774744444, 7774744447, 7774744474, 7774744477, 7774744744, 7774744747, 7774744774, 7774744777, 7774747444, 7774747447, 7774747474, 7774747477, 7774747744, 7774747747, 7774747774, 7774747777, 7774774444, 7774774447, 7774774474, 7774774477, 7774774744, 7774774747, 7774774774, 7774774777, 7774777444, 7774777447, 7774777474, 7774777477, 7774777744, 7774777747, 7774777774, 7774777777, 7777444444, 7777444447, 7777444474, 7777444477, 7777444744, 7777444747, 7777444774, 7777444777, 7777447444, 7777447447, 7777447474, 7777447477, 7777447744, 7777447747, 7777447774, 7777447777, 7777474444, 7777474447, 7777474474, 7777474477, 7777474744, 7777474747, 7777474774, 7777474777, 7777477444, 7777477447, 7777477474, 7777477477, 7777477744, 7777477747, 7777477774, 7777477777, 7777744444, 7777744447, 7777744474, 7777744477, 7777744744, 7777744747, 7777744774, 7777744777, 7777747444, 7777747447, 7777747474, 7777747477, 7777747744, 7777747747, 7777747774, 7777747777, 7777774444, 7777774447, 7777774474, 7777774477, 7777774744, 7777774747, 7777774774, 7777774777, 7777777444, 7777777447, 7777777474, 7777777477, 7777777744, 7777777747, 7777777774, 7777777777, 44444444444, 44444444447, 44444444474, 44444444477, 44444444744, 44444444747, 44444444774, 44444444777, 44444447444, 44444447447, 44444447474, 44444447477, 44444447744, 44444447747, 44444447774, 44444447777, 44444474444, 44444474447, 44444474474, 44444474477, 44444474744, 44444474747, 44444474774, 44444474777, 44444477444, 44444477447, 44444477474, 44444477477, 44444477744, 44444477747, 44444477774, 44444477777, 44444744444, 44444744447, 44444744474, 44444744477, 44444744744, 44444744747, 44444744774, 44444744777, 44444747444, 44444747447, 44444747474, 44444747477, 44444747744, 44444747747, 44444747774, 44444747777, 44444774444, 44444774447, 44444774474, 44444774477, 44444774744, 44444774747, 44444774774, 44444774777, 44444777444, 44444777447, 44444777474, 44444777477, 44444777744, 44444777747, 44444777774, 44444777777, 44447444444, 44447444447, 44447444474, 44447444477, 44447444744, 44447444747, 44447444774, 44447444777, 44447447444, 44447447447, 44447447474, 44447447477, 44447447744, 44447447747, 44447447774, 44447447777, 44447474444, 44447474447, 44447474474, 44447474477, 44447474744, 44447474747, 44447474774, 44447474777, 44447477444, 44447477447, 44447477474, 44447477477, 44447477744, 44447477747, 44447477774, 44447477777, 44447744444, 44447744447, 44447744474, 44447744477, 44447744744, 44447744747, 44447744774, 44447744777, 44447747444, 44447747447, 44447747474, 44447747477, 44447747744, 44447747747, 44447747774, 44447747777, 44447774444, 44447774447, 44447774474, 44447774477, 44447774744, 44447774747, 44447774774, 44447774777, 44447777444, 44447777447, 44447777474, 44447777477, 44447777744, 44447777747, 44447777774, 44447777777, 44474444444, 44474444447, 44474444474, 44474444477, 44474444744, 44474444747, 44474444774, 44474444777, 44474447444, 44474447447, 44474447474, 44474447477, 44474447744, 44474447747, 44474447774, 44474447777, 44474474444, 44474474447, 44474474474, 44474474477, 44474474744, 44474474747, 44474474774, 44474474777, 44474477444, 44474477447, 44474477474, 44474477477, 44474477744, 44474477747, 44474477774, 44474477777, 44474744444, 44474744447, 44474744474, 44474744477, 44474744744, 44474744747, 44474744774, 44474744777, 44474747444, 44474747447, 44474747474, 44474747477, 44474747744, 44474747747, 44474747774, 44474747777, 44474774444, 44474774447, 44474774474, 44474774477, 44474774744, 44474774747, 44474774774, 44474774777, 44474777444, 44474777447, 44474777474, 44474777477, 44474777744, 44474777747, 44474777774, 44474777777, 44477444444, 44477444447, 44477444474, 44477444477, 44477444744, 44477444747, 44477444774, 44477444777, 44477447444, 44477447447, 44477447474, 44477447477, 44477447744, 44477447747, 44477447774, 44477447777, 44477474444, 44477474447, 44477474474, 44477474477, 44477474744, 44477474747, 44477474774, 44477474777, 44477477444, 44477477447, 44477477474, 44477477477, 44477477744, 44477477747, 44477477774, 44477477777, 44477744444, 44477744447, 44477744474, 44477744477, 44477744744, 44477744747, 44477744774, 44477744777, 44477747444, 44477747447, 44477747474, 44477747477, 44477747744, 44477747747, 44477747774, 44477747777, 44477774444, 44477774447, 44477774474, 44477774477, 44477774744, 44477774747, 44477774774, 44477774777, 44477777444, 44477777447, 44477777474, 44477777477, 44477777744, 44477777747, 44477777774, 44477777777, 44744444444, 44744444447, 44744444474, 44744444477, 44744444744, 44744444747, 44744444774, 44744444777, 44744447444, 44744447447, 44744447474, 44744447477, 44744447744, 44744447747, 44744447774, 44744447777, 44744474444, 44744474447, 44744474474, 44744474477, 44744474744, 44744474747, 44744474774, 44744474777, 44744477444, 44744477447, 44744477474, 44744477477, 44744477744, 44744477747, 44744477774, 44744477777, 44744744444, 44744744447, 44744744474, 44744744477, 44744744744, 44744744747, 44744744774, 44744744777, 44744747444, 44744747447, 44744747474, 44744747477, 44744747744, 44744747747, 44744747774, 44744747777, 44744774444, 44744774447, 44744774474, 44744774477, 44744774744, 44744774747, 44744774774, 44744774777, 44744777444, 44744777447, 44744777474, 44744777477, 44744777744, 44744777747, 44744777774, 44744777777, 44747444444, 44747444447, 44747444474, 44747444477, 44747444744, 44747444747, 44747444774, 44747444777, 44747447444, 44747447447, 44747447474, 44747447477, 44747447744, 44747447747, 44747447774, 44747447777, 44747474444, 44747474447, 44747474474, 44747474477, 44747474744, 44747474747, 44747474774, 44747474777, 44747477444, 44747477447, 44747477474, 44747477477, 44747477744, 44747477747, 44747477774, 44747477777, 44747744444, 44747744447, 44747744474, 44747744477, 44747744744, 44747744747, 44747744774, 44747744777, 44747747444, 44747747447, 44747747474, 44747747477, 44747747744, 44747747747, 44747747774, 44747747777, 44747774444, 44747774447, 44747774474, 44747774477, 44747774744, 44747774747, 44747774774, 44747774777, 44747777444, 44747777447, 44747777474, 44747777477, 44747777744, 44747777747, 44747777774, 44747777777, 44774444444, 44774444447, 44774444474, 44774444477, 44774444744, 44774444747, 44774444774, 44774444777, 44774447444, 44774447447, 44774447474, 44774447477, 44774447744, 44774447747, 44774447774, 44774447777, 44774474444, 44774474447, 44774474474, 44774474477, 44774474744, 44774474747, 44774474774, 44774474777, 44774477444, 44774477447, 44774477474, 44774477477, 44774477744, 44774477747, 44774477774, 44774477777, 44774744444, 44774744447, 44774744474, 44774744477, 44774744744, 44774744747, 44774744774, 44774744777, 44774747444, 44774747447, 44774747474, 44774747477, 44774747744, 44774747747, 44774747774, 44774747777, 44774774444, 44774774447, 44774774474, 44774774477, 44774774744, 44774774747, 44774774774, 44774774777, 44774777444, 44774777447, 44774777474, 44774777477, 44774777744, 44774777747, 44774777774, 44774777777, 44777444444, 44777444447, 44777444474, 44777444477, 44777444744, 44777444747, 44777444774, 44777444777, 44777447444, 44777447447, 44777447474, 44777447477, 44777447744, 44777447747, 44777447774, 44777447777, 44777474444, 44777474447, 44777474474, 44777474477, 44777474744, 44777474747, 44777474774, 44777474777, 44777477444, 44777477447, 44777477474, 44777477477, 44777477744, 44777477747, 44777477774, 44777477777, 44777744444, 44777744447, 44777744474, 44777744477, 44777744744, 44777744747, 44777744774, 44777744777, 44777747444, 44777747447, 44777747474, 44777747477, 44777747744, 44777747747, 44777747774, 44777747777, 44777774444, 44777774447, 44777774474, 44777774477, 44777774744, 44777774747, 44777774774, 44777774777, 44777777444, 44777777447, 44777777474, 44777777477, 44777777744, 44777777747, 44777777774, 44777777777, 47444444444, 47444444447, 47444444474, 47444444477, 47444444744, 47444444747, 47444444774, 47444444777, 47444447444, 47444447447, 47444447474, 47444447477, 47444447744, 47444447747, 47444447774, 47444447777, 47444474444, 47444474447, 47444474474, 47444474477, 47444474744, 47444474747, 47444474774, 47444474777, 47444477444, 47444477447, 47444477474, 47444477477, 47444477744, 47444477747, 47444477774, 47444477777, 47444744444, 47444744447, 47444744474, 47444744477, 47444744744, 47444744747, 47444744774, 47444744777, 47444747444, 47444747447, 47444747474, 47444747477, 47444747744, 47444747747, 47444747774, 47444747777, 47444774444, 47444774447, 47444774474, 47444774477, 47444774744, 47444774747, 47444774774, 47444774777, 47444777444, 47444777447, 47444777474, 47444777477, 47444777744, 47444777747, 47444777774, 47444777777, 47447444444, 47447444447, 47447444474, 47447444477, 47447444744, 47447444747, 47447444774, 47447444777, 47447447444, 47447447447, 47447447474, 47447447477, 47447447744, 47447447747, 47447447774, 47447447777, 47447474444, 47447474447, 47447474474, 47447474477, 47447474744, 47447474747, 47447474774, 47447474777, 47447477444, 47447477447, 47447477474, 47447477477, 47447477744, 47447477747, 47447477774, 47447477777, 47447744444, 47447744447, 47447744474, 47447744477, 47447744744, 47447744747, 47447744774, 47447744777, 47447747444, 47447747447, 47447747474, 47447747477, 47447747744, 47447747747, 47447747774, 47447747777, 47447774444, 47447774447, 47447774474, 47447774477, 47447774744, 47447774747, 47447774774, 47447774777, 47447777444, 47447777447, 47447777474, 47447777477, 47447777744, 47447777747, 47447777774, 47447777777, 47474444444, 47474444447, 47474444474, 47474444477, 47474444744, 47474444747, 47474444774, 47474444777, 47474447444, 47474447447, 47474447474, 47474447477, 47474447744, 47474447747, 47474447774, 47474447777, 47474474444, 47474474447, 47474474474, 47474474477, 47474474744, 47474474747, 47474474774, 47474474777, 47474477444, 47474477447, 47474477474, 47474477477, 47474477744, 47474477747, 47474477774, 47474477777, 47474744444, 47474744447, 47474744474, 47474744477, 47474744744, 47474744747, 47474744774, 47474744777, 47474747444, 47474747447, 47474747474, 47474747477, 47474747744, 47474747747, 47474747774, 47474747777, 47474774444, 47474774447, 47474774474, 47474774477, 47474774744, 47474774747, 47474774774, 47474774777, 47474777444, 47474777447, 47474777474, 47474777477, 47474777744, 47474777747, 47474777774, 47474777777, 47477444444, 47477444447, 47477444474, 47477444477, 47477444744, 47477444747, 47477444774, 47477444777, 47477447444, 47477447447, 47477447474, 47477447477, 47477447744, 47477447747, 47477447774, 47477447777, 47477474444, 47477474447, 47477474474, 47477474477, 47477474744, 47477474747, 47477474774, 47477474777, 47477477444, 47477477447, 47477477474, 47477477477, 47477477744, 47477477747, 47477477774, 47477477777, 47477744444, 47477744447, 47477744474, 47477744477, 47477744744, 47477744747, 47477744774, 47477744777, 47477747444, 47477747447, 47477747474, 47477747477, 47477747744, 47477747747, 47477747774, 47477747777, 47477774444, 47477774447, 47477774474, 47477774477, 47477774744, 47477774747, 47477774774, 47477774777, 47477777444, 47477777447, 47477777474, 47477777477, 47477777744, 47477777747, 47477777774, 47477777777, 47744444444, 47744444447, 47744444474, 47744444477, 47744444744, 47744444747, 47744444774, 47744444777, 47744447444, 47744447447, 47744447474, 47744447477, 47744447744, 47744447747, 47744447774, 47744447777, 47744474444, 47744474447, 47744474474, 47744474477, 47744474744, 47744474747, 47744474774, 47744474777, 47744477444, 47744477447, 47744477474, 47744477477, 47744477744, 47744477747, 47744477774, 47744477777, 47744744444, 47744744447, 47744744474, 47744744477, 47744744744, 47744744747, 47744744774, 47744744777, 47744747444, 47744747447, 47744747474, 47744747477, 47744747744, 47744747747, 47744747774, 47744747777, 47744774444, 47744774447, 47744774474, 47744774477, 47744774744, 47744774747, 47744774774, 47744774777, 47744777444, 47744777447, 47744777474, 47744777477, 47744777744, 47744777747, 47744777774, 47744777777, 47747444444, 47747444447, 47747444474, 47747444477, 47747444744, 47747444747, 47747444774, 47747444777, 47747447444, 47747447447, 47747447474, 47747447477, 47747447744, 47747447747, 47747447774, 47747447777, 47747474444, 47747474447, 47747474474, 47747474477, 47747474744, 47747474747, 47747474774, 47747474777, 47747477444, 47747477447, 47747477474, 47747477477, 47747477744, 47747477747, 47747477774, 47747477777, 47747744444, 47747744447, 47747744474, 47747744477, 47747744744, 47747744747, 47747744774, 47747744777, 47747747444, 47747747447, 47747747474, 47747747477, 47747747744, 47747747747, 47747747774, 47747747777, 47747774444, 47747774447, 47747774474, 47747774477, 47747774744, 47747774747, 47747774774, 47747774777, 47747777444, 47747777447, 47747777474, 47747777477, 47747777744, 47747777747, 47747777774, 47747777777, 47774444444, 47774444447, 47774444474, 47774444477, 47774444744, 47774444747, 47774444774, 47774444777, 47774447444, 47774447447, 47774447474, 47774447477, 47774447744, 47774447747, 47774447774, 47774447777, 47774474444, 47774474447, 47774474474, 47774474477, 47774474744, 47774474747, 47774474774, 47774474777, 47774477444, 47774477447, 47774477474, 47774477477, 47774477744, 47774477747, 47774477774, 47774477777, 47774744444, 47774744447, 47774744474, 47774744477, 47774744744, 47774744747, 47774744774, 47774744777, 47774747444, 47774747447, 47774747474, 47774747477, 47774747744, 47774747747, 47774747774, 47774747777, 47774774444, 47774774447, 47774774474, 47774774477, 47774774744, 47774774747, 47774774774, 47774774777, 47774777444, 47774777447, 47774777474, 47774777477, 47774777744, 47774777747, 47774777774, 47774777777, 47777444444, 47777444447, 47777444474, 47777444477, 47777444744, 47777444747, 47777444774, 47777444777, 47777447444, 47777447447, 47777447474, 47777447477, 47777447744, 47777447747, 47777447774, 47777447777, 47777474444, 47777474447, 47777474474, 47777474477, 47777474744, 47777474747, 47777474774, 47777474777, 47777477444, 47777477447, 47777477474, 47777477477, 47777477744, 47777477747, 47777477774, 47777477777, 47777744444, 47777744447, 47777744474, 47777744477, 47777744744, 47777744747, 47777744774, 47777744777, 47777747444, 47777747447, 47777747474, 47777747477, 47777747744, 47777747747, 47777747774, 47777747777, 47777774444, 47777774447, 47777774474, 47777774477, 47777774744, 47777774747, 47777774774, 47777774777, 47777777444, 47777777447, 47777777474, 47777777477, 47777777744, 47777777747, 47777777774, 47777777777, 74444444444, 74444444447, 74444444474, 74444444477, 74444444744, 74444444747, 74444444774, 74444444777, 74444447444, 74444447447, 74444447474, 74444447477, 74444447744, 74444447747, 74444447774, 74444447777, 74444474444, 74444474447, 74444474474, 74444474477, 74444474744, 74444474747, 74444474774, 74444474777, 74444477444, 74444477447, 74444477474, 74444477477, 74444477744, 74444477747, 74444477774, 74444477777, 74444744444, 74444744447, 74444744474, 74444744477, 74444744744, 74444744747, 74444744774, 74444744777, 74444747444, 74444747447, 74444747474, 74444747477, 74444747744, 74444747747, 74444747774, 74444747777, 74444774444, 74444774447, 74444774474, 74444774477, 74444774744, 74444774747, 74444774774, 74444774777, 74444777444, 74444777447, 74444777474, 74444777477, 74444777744, 74444777747, 74444777774, 74444777777, 74447444444, 74447444447, 74447444474, 74447444477, 74447444744, 74447444747, 74447444774, 74447444777, 74447447444, 74447447447, 74447447474, 74447447477, 74447447744, 74447447747, 74447447774, 74447447777, 74447474444, 74447474447, 74447474474, 74447474477, 74447474744, 74447474747, 74447474774, 74447474777, 74447477444, 74447477447, 74447477474, 74447477477, 74447477744, 74447477747, 74447477774, 74447477777, 74447744444, 74447744447, 74447744474, 74447744477, 74447744744, 74447744747, 74447744774, 74447744777, 74447747444, 74447747447, 74447747474, 74447747477, 74447747744, 74447747747, 74447747774, 74447747777, 74447774444, 74447774447, 74447774474, 74447774477, 74447774744, 74447774747, 74447774774, 74447774777, 74447777444, 74447777447, 74447777474, 74447777477, 74447777744, 74447777747, 74447777774, 74447777777, 74474444444, 74474444447, 74474444474, 74474444477, 74474444744, 74474444747, 74474444774, 74474444777, 74474447444, 74474447447, 74474447474, 74474447477, 74474447744, 74474447747, 74474447774, 74474447777, 74474474444, 74474474447, 74474474474, 74474474477, 74474474744, 74474474747, 74474474774, 74474474777, 74474477444, 74474477447, 74474477474, 74474477477, 74474477744, 74474477747, 74474477774, 74474477777, 74474744444, 74474744447, 74474744474, 74474744477, 74474744744, 74474744747, 74474744774, 74474744777, 74474747444, 74474747447, 74474747474, 74474747477, 74474747744, 74474747747, 74474747774, 74474747777, 74474774444, 74474774447, 74474774474, 74474774477, 74474774744, 74474774747, 74474774774, 74474774777, 74474777444, 74474777447, 74474777474, 74474777477, 74474777744, 74474777747, 74474777774, 74474777777, 74477444444, 74477444447, 74477444474, 74477444477, 74477444744, 74477444747, 74477444774, 74477444777, 74477447444, 74477447447, 74477447474, 74477447477, 74477447744, 74477447747, 74477447774, 74477447777, 74477474444, 74477474447, 74477474474, 74477474477, 74477474744, 74477474747, 74477474774, 74477474777, 74477477444, 74477477447, 74477477474, 74477477477, 74477477744, 74477477747, 74477477774, 74477477777, 74477744444, 74477744447, 74477744474, 74477744477, 74477744744, 74477744747, 74477744774, 74477744777, 74477747444, 74477747447, 74477747474, 74477747477, 74477747744, 74477747747, 74477747774, 74477747777, 74477774444, 74477774447, 74477774474, 74477774477, 74477774744, 74477774747, 74477774774, 74477774777, 74477777444, 74477777447, 74477777474, 74477777477, 74477777744, 74477777747, 74477777774, 74477777777, 74744444444, 74744444447, 74744444474, 74744444477, 74744444744, 74744444747, 74744444774, 74744444777, 74744447444, 74744447447, 74744447474, 74744447477, 74744447744, 74744447747, 74744447774, 74744447777, 74744474444, 74744474447, 74744474474, 74744474477, 74744474744, 74744474747, 74744474774, 74744474777, 74744477444, 74744477447, 74744477474, 74744477477, 74744477744, 74744477747, 74744477774, 74744477777, 74744744444, 74744744447, 74744744474, 74744744477, 74744744744, 74744744747, 74744744774, 74744744777, 74744747444, 74744747447, 74744747474, 74744747477, 74744747744, 74744747747, 74744747774, 74744747777, 74744774444, 74744774447, 74744774474, 74744774477, 74744774744, 74744774747, 74744774774, 74744774777, 74744777444, 74744777447, 74744777474, 74744777477, 74744777744, 74744777747, 74744777774, 74744777777, 74747444444, 74747444447, 74747444474, 74747444477, 74747444744, 74747444747, 74747444774, 74747444777, 74747447444, 74747447447, 74747447474, 74747447477, 74747447744, 74747447747, 74747447774, 74747447777, 74747474444, 74747474447, 74747474474, 74747474477, 74747474744, 74747474747, 74747474774, 74747474777, 74747477444, 74747477447, 74747477474, 74747477477, 74747477744, 74747477747, 74747477774, 74747477777, 74747744444, 74747744447, 74747744474, 74747744477, 74747744744, 74747744747, 74747744774, 74747744777, 74747747444, 74747747447, 74747747474, 74747747477, 74747747744, 74747747747, 74747747774, 74747747777, 74747774444, 74747774447, 74747774474, 74747774477, 74747774744, 74747774747, 74747774774, 74747774777, 74747777444, 74747777447, 74747777474, 74747777477, 74747777744, 74747777747, 74747777774, 74747777777, 74774444444, 74774444447, 74774444474, 74774444477, 74774444744, 74774444747, 74774444774, 74774444777, 74774447444, 74774447447, 74774447474, 74774447477, 74774447744, 74774447747, 74774447774, 74774447777, 74774474444, 74774474447, 74774474474, 74774474477, 74774474744, 74774474747, 74774474774, 74774474777, 74774477444, 74774477447, 74774477474, 74774477477, 74774477744, 74774477747, 74774477774, 74774477777, 74774744444, 74774744447, 74774744474, 74774744477, 74774744744, 74774744747, 74774744774, 74774744777, 74774747444, 74774747447, 74774747474, 74774747477, 74774747744, 74774747747, 74774747774, 74774747777, 74774774444, 74774774447, 74774774474, 74774774477, 74774774744, 74774774747, 74774774774, 74774774777, 74774777444, 74774777447, 74774777474, 74774777477, 74774777744, 74774777747, 74774777774, 74774777777, 74777444444, 74777444447, 74777444474, 74777444477, 74777444744, 74777444747, 74777444774, 74777444777, 74777447444, 74777447447, 74777447474, 74777447477, 74777447744, 74777447747, 74777447774, 74777447777, 74777474444, 74777474447, 74777474474, 74777474477, 74777474744, 74777474747, 74777474774, 74777474777, 74777477444, 74777477447, 74777477474, 74777477477, 74777477744, 74777477747, 74777477774, 74777477777, 74777744444, 74777744447, 74777744474, 74777744477, 74777744744, 74777744747, 74777744774, 74777744777, 74777747444, 74777747447, 74777747474, 74777747477, 74777747744, 74777747747, 74777747774, 74777747777, 74777774444, 74777774447, 74777774474, 74777774477, 74777774744, 74777774747, 74777774774, 74777774777, 74777777444, 74777777447, 74777777474, 74777777477, 74777777744, 74777777747, 74777777774, 74777777777, 77444444444, 77444444447, 77444444474, 77444444477, 77444444744, 77444444747, 77444444774, 77444444777, 77444447444, 77444447447, 77444447474, 77444447477, 77444447744, 77444447747, 77444447774, 77444447777, 77444474444, 77444474447, 77444474474, 77444474477, 77444474744, 77444474747, 77444474774, 77444474777, 77444477444, 77444477447, 77444477474, 77444477477, 77444477744, 77444477747, 77444477774, 77444477777, 77444744444, 77444744447, 77444744474, 77444744477, 77444744744, 77444744747, 77444744774, 77444744777, 77444747444, 77444747447, 77444747474, 77444747477, 77444747744, 77444747747, 77444747774, 77444747777, 77444774444, 77444774447, 77444774474, 77444774477, 77444774744, 77444774747, 77444774774, 77444774777, 77444777444, 77444777447, 77444777474, 77444777477, 77444777744, 77444777747, 77444777774, 77444777777, 77447444444, 77447444447, 77447444474, 77447444477, 77447444744, 77447444747, 77447444774, 77447444777, 77447447444, 77447447447, 77447447474, 77447447477, 77447447744, 77447447747, 77447447774, 77447447777, 77447474444, 77447474447, 77447474474, 77447474477, 77447474744, 77447474747, 77447474774, 77447474777, 77447477444, 77447477447, 77447477474, 77447477477, 77447477744, 77447477747, 77447477774, 77447477777, 77447744444, 77447744447, 77447744474, 77447744477, 77447744744, 77447744747, 77447744774, 77447744777, 77447747444, 77447747447, 77447747474, 77447747477, 77447747744, 77447747747, 77447747774, 77447747777, 77447774444, 77447774447, 77447774474, 77447774477, 77447774744, 77447774747, 77447774774, 77447774777, 77447777444, 77447777447, 77447777474, 77447777477, 77447777744, 77447777747, 77447777774, 77447777777, 77474444444, 77474444447, 77474444474, 77474444477, 77474444744, 77474444747, 77474444774, 77474444777, 77474447444, 77474447447, 77474447474, 77474447477, 77474447744, 77474447747, 77474447774, 77474447777, 77474474444, 77474474447, 77474474474, 77474474477, 77474474744, 77474474747, 77474474774, 77474474777, 77474477444, 77474477447, 77474477474, 77474477477, 77474477744, 77474477747, 77474477774, 77474477777, 77474744444, 77474744447, 77474744474, 77474744477, 77474744744, 77474744747, 77474744774, 77474744777, 77474747444, 77474747447, 77474747474, 77474747477, 77474747744, 77474747747, 77474747774, 77474747777, 77474774444, 77474774447, 77474774474, 77474774477, 77474774744, 77474774747, 77474774774, 77474774777, 77474777444, 77474777447, 77474777474, 77474777477, 77474777744, 77474777747, 77474777774, 77474777777, 77477444444, 77477444447, 77477444474, 77477444477, 77477444744, 77477444747, 77477444774, 77477444777, 77477447444, 77477447447, 77477447474, 77477447477, 77477447744, 77477447747, 77477447774, 77477447777, 77477474444, 77477474447, 77477474474, 77477474477, 77477474744, 77477474747, 77477474774, 77477474777, 77477477444, 77477477447, 77477477474, 77477477477, 77477477744, 77477477747, 77477477774, 77477477777, 77477744444, 77477744447, 77477744474, 77477744477, 77477744744, 77477744747, 77477744774, 77477744777, 77477747444, 77477747447, 77477747474, 77477747477, 77477747744, 77477747747, 77477747774, 77477747777, 77477774444, 77477774447, 77477774474, 77477774477, 77477774744, 77477774747, 77477774774, 77477774777, 77477777444, 77477777447, 77477777474, 77477777477, 77477777744, 77477777747, 77477777774, 77477777777, 77744444444, 77744444447, 77744444474, 77744444477, 77744444744, 77744444747, 77744444774, 77744444777, 77744447444, 77744447447, 77744447474, 77744447477, 77744447744, 77744447747, 77744447774, 77744447777, 77744474444, 77744474447, 77744474474, 77744474477, 77744474744, 77744474747, 77744474774, 77744474777, 77744477444, 77744477447, 77744477474, 77744477477, 77744477744, 77744477747, 77744477774, 77744477777, 77744744444, 77744744447, 77744744474, 77744744477, 77744744744, 77744744747, 77744744774, 77744744777, 77744747444, 77744747447, 77744747474, 77744747477, 77744747744, 77744747747, 77744747774, 77744747777, 77744774444, 77744774447, 77744774474, 77744774477, 77744774744, 77744774747, 77744774774, 77744774777, 77744777444, 77744777447, 77744777474, 77744777477, 77744777744, 77744777747, 77744777774, 77744777777, 77747444444, 77747444447, 77747444474, 77747444477, 77747444744, 77747444747, 77747444774, 77747444777, 77747447444, 77747447447, 77747447474, 77747447477, 77747447744, 77747447747, 77747447774, 77747447777, 77747474444, 77747474447, 77747474474, 77747474477, 77747474744, 77747474747, 77747474774, 77747474777, 77747477444, 77747477447, 77747477474, 77747477477, 77747477744, 77747477747, 77747477774, 77747477777, 77747744444, 77747744447, 77747744474, 77747744477, 77747744744, 77747744747, 77747744774, 77747744777, 77747747444, 77747747447, 77747747474, 77747747477, 77747747744, 77747747747, 77747747774, 77747747777, 77747774444, 77747774447, 77747774474, 77747774477, 77747774744, 77747774747, 77747774774, 77747774777, 77747777444, 77747777447, 77747777474, 77747777477, 77747777744, 77747777747, 77747777774, 77747777777, 77774444444, 77774444447, 77774444474, 77774444477, 77774444744, 77774444747, 77774444774, 77774444777, 77774447444, 77774447447, 77774447474, 77774447477, 77774447744, 77774447747, 77774447774, 77774447777, 77774474444, 77774474447, 77774474474, 77774474477, 77774474744, 77774474747, 77774474774, 77774474777, 77774477444, 77774477447, 77774477474, 77774477477, 77774477744, 77774477747, 77774477774, 77774477777, 77774744444, 77774744447, 77774744474, 77774744477, 77774744744, 77774744747, 77774744774, 77774744777, 77774747444, 77774747447, 77774747474, 77774747477, 77774747744, 77774747747, 77774747774, 77774747777, 77774774444, 77774774447, 77774774474, 77774774477, 77774774744, 77774774747, 77774774774, 77774774777, 77774777444, 77774777447, 77774777474, 77774777477, 77774777744, 77774777747, 77774777774, 77774777777, 77777444444, 77777444447, 77777444474, 77777444477, 77777444744, 77777444747, 77777444774, 77777444777, 77777447444, 77777447447, 77777447474, 77777447477, 77777447744, 77777447747, 77777447774, 77777447777, 77777474444, 77777474447, 77777474474, 77777474477, 77777474744, 77777474747, 77777474774, 77777474777, 77777477444, 77777477447, 77777477474, 77777477477, 77777477744, 77777477747, 77777477774, 77777477777, 77777744444, 77777744447, 77777744474, 77777744477, 77777744744, 77777744747, 77777744774, 77777744777, 77777747444, 77777747447, 77777747474, 77777747477, 77777747744, 77777747747, 77777747774, 77777747777, 77777774444, 77777774447, 77777774474, 77777774477, 77777774744, 77777774747, 77777774774, 77777774777, 77777777444, 77777777447, 77777777474, 77777777477, 77777777744, 77777777747, 77777777774, 77777777777] l, r = In() sm = 0 for i in range(l, r+1): x = bisect_right(arr, i) if arr[x-1] == i: sm += i else: sm += arr[x] print(sm) ```
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,667,648,809
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
word = input() test = "hello" index = 0 for i in word: if i == test[index]: index += 1 if index == 5: break if index == 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 word = input() test = "hello" index = 0 for i in word: if i == test[index]: index += 1 if index == 5: break if index == 5: print("yes") else: print("no") ```
0
0
none
none
none
0
[ "none" ]
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.
0
[ { "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,695,492,515
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
46
0
n = int(input()) a = list(map(int, input().split())) dp = [0] * n dp[0] = a[0] for i in range(1, n): if a[i] == 1: if dp[i - 1] == 1: dp[i] = 0 else: dp[i] = 1 if a[i] == 2: if dp[i - 1] == 2: dp[i] = 0 else: dp[i] = 2 if a[i] == 3: if dp[i - 1] == 1: dp[i] = 2 if dp[i - 1] == 2: dp[i] = 1 if dp[i - 1] == 3: dp[i] = 3 cnt=0 for i in range(n): if dp[i]==0: cnt+=1 print(cnt)
Title: none 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()) a = list(map(int, input().split())) dp = [0] * n dp[0] = a[0] for i in range(1, n): if a[i] == 1: if dp[i - 1] == 1: dp[i] = 0 else: dp[i] = 1 if a[i] == 2: if dp[i - 1] == 2: dp[i] = 0 else: dp[i] = 2 if a[i] == 3: if dp[i - 1] == 1: dp[i] = 2 if dp[i - 1] == 2: dp[i] = 1 if dp[i - 1] == 3: dp[i] = 3 cnt=0 for i in range(n): if dp[i]==0: cnt+=1 print(cnt) ```
0
415
B
Mashmokh and Tokens
PROGRAMMING
1,500
[ "binary search", "greedy", "implementation", "math" ]
null
null
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save.
The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109).
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
[ "5 1 4\n12 6 11 9 1\n", "3 1 2\n1 2 3\n", "1 1 1\n1\n" ]
[ "0 2 3 1 1 ", "1 0 1 ", "0 " ]
none
1,000
[ { "input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1 " }, { "input": "3 1 2\n1 2 3", "output": "1 0 1 " }, { "input": "1 1 1\n1", "output": "0 " }, { "input": "1 1 1000000000\n1000000000", "output": "0 " }, { "input": "1 1 1000000000\n999999999", "output": "999999999 " }, { "input": "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999", "output": "99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 " } ]
1,572,521,713
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
280
11,059,200
n, a, b = map(int, input().split()) print(*[(w * a) - (w * a) // b * b for w in map(int, input().split())])
Title: Mashmokh and Tokens Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save. Input Specification: The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). Output Specification: Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. Demo Input: ['5 1 4\n12 6 11 9 1\n', '3 1 2\n1 2 3\n', '1 1 1\n1\n'] Demo Output: ['0 2 3 1 1 ', '1 0 1 ', '0 '] Note: none
```python n, a, b = map(int, input().split()) print(*[(w * a) - (w * a) // b * b for w in map(int, input().split())]) ```
0
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReality\nSoul\nSpace\nMind" }, { "input": "3\nblue\norange\npurple", "output": "3\nTime\nReality\nMind" }, { "input": "2\nyellow\nred", "output": "4\nPower\nSoul\nSpace\nTime" }, { "input": "1\ngreen", "output": "5\nReality\nSpace\nPower\nSoul\nMind" }, { "input": "2\npurple\ngreen", "output": "4\nReality\nMind\nSpace\nSoul" }, { "input": "1\nblue", "output": "5\nPower\nReality\nSoul\nTime\nMind" }, { "input": "2\npurple\nblue", "output": "4\nMind\nSoul\nTime\nReality" }, { "input": "2\ngreen\nblue", "output": "4\nReality\nMind\nPower\nSoul" }, { "input": "3\npurple\ngreen\nblue", "output": "3\nMind\nReality\nSoul" }, { "input": "1\norange", "output": "5\nReality\nTime\nPower\nSpace\nMind" }, { "input": "2\npurple\norange", "output": "4\nReality\nMind\nTime\nSpace" }, { "input": "2\norange\ngreen", "output": "4\nSpace\nMind\nReality\nPower" }, { "input": "3\norange\npurple\ngreen", "output": "3\nReality\nSpace\nMind" }, { "input": "2\norange\nblue", "output": "4\nTime\nMind\nReality\nPower" }, { "input": "3\nblue\ngreen\norange", "output": "3\nPower\nMind\nReality" }, { "input": "4\nblue\norange\ngreen\npurple", "output": "2\nMind\nReality" }, { "input": "1\nred", "output": "5\nTime\nSoul\nMind\nPower\nSpace" }, { "input": "2\nred\npurple", "output": "4\nMind\nSpace\nTime\nSoul" }, { "input": "2\nred\ngreen", "output": "4\nMind\nSpace\nPower\nSoul" }, { "input": "3\nred\npurple\ngreen", "output": "3\nSoul\nSpace\nMind" }, { "input": "2\nblue\nred", "output": "4\nMind\nTime\nPower\nSoul" }, { "input": "3\nred\nblue\npurple", "output": "3\nTime\nMind\nSoul" }, { "input": "3\nred\nblue\ngreen", "output": "3\nSoul\nPower\nMind" }, { "input": "4\npurple\nblue\ngreen\nred", "output": "2\nMind\nSoul" }, { "input": "2\norange\nred", "output": "4\nPower\nMind\nTime\nSpace" }, { "input": "3\nred\norange\npurple", "output": "3\nMind\nSpace\nTime" }, { "input": "3\nred\norange\ngreen", "output": "3\nMind\nSpace\nPower" }, { "input": "4\nred\norange\ngreen\npurple", "output": "2\nSpace\nMind" }, { "input": "3\nblue\norange\nred", "output": "3\nPower\nMind\nTime" }, { "input": "4\norange\nblue\npurple\nred", "output": "2\nTime\nMind" }, { "input": "4\ngreen\norange\nred\nblue", "output": "2\nMind\nPower" }, { "input": "5\npurple\norange\nblue\nred\ngreen", "output": "1\nMind" }, { "input": "1\nyellow", "output": "5\nPower\nSoul\nReality\nSpace\nTime" }, { "input": "2\npurple\nyellow", "output": "4\nTime\nReality\nSpace\nSoul" }, { "input": "2\ngreen\nyellow", "output": "4\nSpace\nReality\nPower\nSoul" }, { "input": "3\npurple\nyellow\ngreen", "output": "3\nSoul\nReality\nSpace" }, { "input": "2\nblue\nyellow", "output": "4\nTime\nReality\nPower\nSoul" }, { "input": "3\nyellow\nblue\npurple", "output": "3\nSoul\nReality\nTime" }, { "input": "3\ngreen\nyellow\nblue", "output": "3\nSoul\nReality\nPower" }, { "input": "4\nyellow\nblue\ngreen\npurple", "output": "2\nReality\nSoul" }, { "input": "2\nyellow\norange", "output": "4\nTime\nSpace\nReality\nPower" }, { "input": "3\nyellow\npurple\norange", "output": "3\nSpace\nReality\nTime" }, { "input": "3\norange\nyellow\ngreen", "output": "3\nSpace\nReality\nPower" }, { "input": "4\ngreen\nyellow\norange\npurple", "output": "2\nSpace\nReality" }, { "input": "3\nyellow\nblue\norange", "output": "3\nTime\nReality\nPower" }, { "input": "4\norange\npurple\nblue\nyellow", "output": "2\nReality\nTime" }, { "input": "4\nblue\norange\nyellow\ngreen", "output": "2\nReality\nPower" }, { "input": "5\ngreen\nyellow\norange\nblue\npurple", "output": "1\nReality" }, { "input": "3\nyellow\npurple\nred", "output": "3\nTime\nSoul\nSpace" }, { "input": "3\nred\ngreen\nyellow", "output": "3\nPower\nSoul\nSpace" }, { "input": "4\nred\npurple\ngreen\nyellow", "output": "2\nSpace\nSoul" }, { "input": "3\nred\nyellow\nblue", "output": "3\nPower\nSoul\nTime" }, { "input": "4\nblue\nyellow\nred\npurple", "output": "2\nTime\nSoul" }, { "input": "4\nblue\nyellow\nred\ngreen", "output": "2\nSoul\nPower" }, { "input": "5\nred\nyellow\ngreen\nblue\npurple", "output": "1\nSoul" }, { "input": "3\nred\nyellow\norange", "output": "3\nPower\nSpace\nTime" }, { "input": "4\norange\ngreen\nyellow\nred", "output": "2\nPower\nSpace" }, { "input": "5\norange\nred\ngreen\nyellow\npurple", "output": "1\nSpace" }, { "input": "4\nyellow\nred\norange\nblue", "output": "2\nTime\nPower" }, { "input": "5\npurple\nblue\norange\nyellow\nred", "output": "1\nTime" }, { "input": "5\norange\nblue\nyellow\nred\ngreen", "output": "1\nPower" } ]
1,621,934,467
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
124
2,048,000
stone = { 'purple': 'Power', 'green' : 'Time', 'blue' : 'Space', 'organge' : 'Soul', 'red' : 'Reality', 'yellow' : 'Mind' } n = int(input()) for i in range(0 ,n): k = input() del stone[k] print(6 - n) for index in stone: print(stone[index])
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. Output Specification: In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
```python stone = { 'purple': 'Power', 'green' : 'Time', 'blue' : 'Space', 'organge' : 'Soul', 'red' : 'Reality', 'yellow' : 'Mind' } n = int(input()) for i in range(0 ,n): k = input() del stone[k] print(6 - n) for index in stone: print(stone[index]) ```
-1
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
500
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
1,510,507,899
5,199
Python 3
WRONG_ANSWER
PRETESTS
3
61
0
a = list(map(int,input().split())) ans = False power_of_t = sum(a) if power_of_t %2 !=0: print('NO') elif max(a) >= (power_of_t // 2): print('NO') else: for i in range(0,6): for j in range(1,6): for e in range(5,0,-1): if a[i] + a[j] + a[e] == a[-i] + a[-j] + a[-e]: ans = True if ans: print('YES')
Title: ACM ICPC Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input Specification: The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants Output Specification: Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['1 3 2 1 2 1\n', '1 1 1 1 1 99\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
```python a = list(map(int,input().split())) ans = False power_of_t = sum(a) if power_of_t %2 !=0: print('NO') elif max(a) >= (power_of_t // 2): print('NO') else: for i in range(0,6): for j in range(1,6): for e in range(5,0,-1): if a[i] + a[j] + a[e] == a[-i] + a[-j] + a[-e]: ans = True if ans: print('YES') ```
0
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
1,643,201,731
2,147,483,647
Python 3
OK
TESTS
31
92
0
n=int(input()) s=input() s=s.split() l=[] for i in range(n): l.append(int(s[i])) m = int(input()) for i in range(m): ss=input() ss=ss.split() xi=int(ss[0]) yi=int(ss[1]) ox=l[xi-1] l[xi-1]-=yi if xi-2>=0: l[xi-2]+=(yi-1) ox=ox-yi l[xi-1]-=ox if xi-1<n-1: l[xi]+=ox for j in l: print(j)
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. Output Specification: On the *i*-th line of the output print the number of birds on the *i*-th wire. Demo Input: ['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n'] Demo Output: ['0\n12\n5\n0\n16\n', '3\n0\n3\n'] Note: none
```python n=int(input()) s=input() s=s.split() l=[] for i in range(n): l.append(int(s[i])) m = int(input()) for i in range(m): ss=input() ss=ss.split() xi=int(ss[0]) yi=int(ss[1]) ox=l[xi-1] l[xi-1]-=yi if xi-2>=0: l[xi-2]+=(yi-1) ox=ox-yi l[xi-1]-=ox if xi-1<n-1: l[xi]+=ox for j in l: print(j) ```
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,663,230,255
2,147,483,647
Python 3
OK
TESTS
40
31
0
s=list(input()) n='NO' for i in range(len(s)): if s[i]=='h' : for i_1 in range(i,len(s)): if s[i_1]=='e' : for i_2 in range(i_1,len(s)): if s[i_2]=='l' : for i_3 in range(i_2+1,len(s)): if s[i_3]=='l' : for i_4 in range(i_3,len(s)): if s[i_4]=='o' : n='YES' break continue continue continue print(n)
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=list(input()) n='NO' for i in range(len(s)): if s[i]=='h' : for i_1 in range(i,len(s)): if s[i_1]=='e' : for i_2 in range(i_1,len(s)): if s[i_2]=='l' : for i_3 in range(i_2+1,len(s)): if s[i_3]=='l' : for i_4 in range(i_3,len(s)): if s[i_4]=='o' : n='YES' break continue continue continue print(n) ```
3.9845
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,674,326,274
2,147,483,647
PyPy 3-64
OK
TESTS
35
62
1,638,400
fristNum,secondNum=map(int,input().split()) listNum=list(map(int,input().split())) counts=0 for i in range(fristNum): if(listNum[i]+secondNum <= 5): counts+=1 print(counts//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python fristNum,secondNum=map(int,input().split()) listNum=list(map(int,input().split())) counts=0 for i in range(fristNum): if(listNum[i]+secondNum <= 5): counts+=1 print(counts//3) ```
3
909
C
Python Indentation
PROGRAMMING
1,800
[ "dp" ]
null
null
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
[ "4\ns\nf\nf\ns\n", "4\nf\ns\nf\ns\n" ]
[ "1\n", "2\n" ]
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
1,500
[ { "input": "4\ns\nf\nf\ns", "output": "1" }, { "input": "4\nf\ns\nf\ns", "output": "2" }, { "input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns\ns\nf\nf\ns\ns\ns\ns\ns\nf\nf\nf\nf\ns\nf\nf\ns\nf\ns\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\nf\ns\ns\nf\nf\nf\ns\ns\nf\nf\nf\ns\nf\ns\nf\nf\ns", "output": "666443222" }, { "input": "4\nf\nf\ns\ns", "output": "3" }, { "input": "2\nf\ns", "output": "1" }, { "input": "1\ns", "output": "1" }, { "input": "3\nf\nf\ns", "output": "1" }, { "input": "2\ns\ns", "output": "1" }, { "input": "156\ns\nf\ns\ns\ns\ns\nf\ns\ns\ns\nf\nf\ns\nf\nf\ns\nf\nf\nf\ns\nf\nf\ns\nf\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\nf\nf\nf\ns\ns\nf\nf\ns\nf\ns\ns\ns\ns\ns\ns\ns\nf\ns\nf\nf\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\ns\ns\nf\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\nf\ns\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\ns\nf\ns\nf\ns\ns\ns\nf\nf\ns", "output": "479461584" }, { "input": "66\ns\nf\ns\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\ns", "output": "392847498" } ]
1,666,558,985
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
lines = int(input()) code = [] for i in range(lines): code.append(input()) print(pow(2, len(''.join(''.join(code).split('f'))) - 1, 1000000007))
Title: Python Indentation Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program. Input Specification: The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. Output Specification: Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. Demo Input: ['4\ns\nf\nf\ns\n', '4\nf\ns\nf\ns\n'] Demo Output: ['1\n', '2\n'] Note: In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
```python lines = int(input()) code = [] for i in range(lines): code.append(input()) print(pow(2, len(''.join(''.join(code).split('f'))) - 1, 1000000007)) ```
0
446
A
DZY Loves Sequences
PROGRAMMING
1,600
[ "dp", "implementation", "two pointers" ]
null
null
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
[ "6\n7 2 3 1 5 6\n" ]
[ "5\n" ]
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
500
[ { "input": "6\n7 2 3 1 5 6", "output": "5" }, { "input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "output": "9" }, { "input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371", "output": "19" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "2" }, { "input": "5\n1 2 3 4 1", "output": "5" }, { "input": "10\n1 2 3 4 5 5 6 7 8 9", "output": "6" }, { "input": "5\n1 1 1 1 1", "output": "2" }, { "input": "5\n1 1 2 3 4", "output": "5" }, { "input": "5\n1 2 3 1 6", "output": "5" }, { "input": "1\n42", "output": "1" }, { "input": "5\n1 2 42 3 4", "output": "4" }, { "input": "5\n1 5 9 6 10", "output": "4" }, { "input": "5\n5 2 3 4 5", "output": "5" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "5\n1 2 3 3 4", "output": "4" }, { "input": "8\n1 2 3 4 1 5 6 7", "output": "5" }, { "input": "1\n3", "output": "1" }, { "input": "3\n5 1 2", "output": "3" }, { "input": "4\n1 4 3 4", "output": "4" }, { "input": "6\n7 2 12 4 5 6", "output": "5" }, { "input": "6\n7 2 3 1 4 5", "output": "4" }, { "input": "6\n2 3 5 5 6 7", "output": "6" }, { "input": "5\n2 4 7 6 8", "output": "5" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "2\n1 2", "output": "2" }, { "input": "5\n4 1 2 3 4", "output": "5" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6", "output": "7" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "4\n4 3 1 2", "output": "3" }, { "input": "6\n1 2 2 3 4 5", "output": "5" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n5 1 2 3", "output": "4" }, { "input": "5\n9 1 2 3 4", "output": "5" }, { "input": "2\n1 1", "output": "2" }, { "input": "5\n1 3 2 4 5", "output": "4" }, { "input": "6\n1 2 1 2 4 5", "output": "5" }, { "input": "10\n1 1 5 3 2 9 9 7 7 6", "output": "3" }, { "input": "6\n1 2 3 100000 100 101", "output": "6" }, { "input": "4\n3 3 3 4", "output": "3" }, { "input": "3\n4 3 5", "output": "3" }, { "input": "5\n1 3 2 3 4", "output": "4" }, { "input": "10\n1 2 3 4 5 10 10 11 12 13", "output": "10" }, { "input": "7\n11 2 1 2 13 4 14", "output": "5" }, { "input": "3\n5 1 3", "output": "3" }, { "input": "4\n1 5 3 4", "output": "4" }, { "input": "10\n1 2 3 4 100 6 7 8 9 10", "output": "10" }, { "input": "3\n5 3 5", "output": "3" }, { "input": "5\n100 100 7 8 9", "output": "4" }, { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "5\n1 2 4 4 5", "output": "5" }, { "input": "6\n7 4 5 6 7 8", "output": "6" }, { "input": "9\n3 4 1 6 3 4 5 6 7", "output": "7" }, { "input": "3\n1000 1 2", "output": "3" }, { "input": "3\n20 1 9", "output": "3" }, { "input": "6\n7 2 3 1 4 6", "output": "4" }, { "input": "3\n100 5 10", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "6\n4 2 8 1 2 5", "output": "4" }, { "input": "3\n25 1 6", "output": "3" }, { "input": "10\n17 99 23 72 78 36 5 43 95 9", "output": "5" }, { "input": "7\n21 16 22 21 11 13 19", "output": "4" }, { "input": "5\n1 2 5 3 4", "output": "4" }, { "input": "6\n2 2 2 3 4 5", "output": "5" }, { "input": "5\n1 3 1 2 3", "output": "4" }, { "input": "3\n81 33 64", "output": "3" }, { "input": "7\n14 3 3 19 13 19 15", "output": "4" }, { "input": "9\n1 2 3 4 5 42 7 8 9", "output": "9" }, { "input": "5\n2 3 7 5 6", "output": "5" }, { "input": "5\n1 3 3 4 5", "output": "5" }, { "input": "6\n1 5 4 3 4 5", "output": "4" } ]
1,508,479,072
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
4,608,000
def find_longest_streak(nums): if len(nums) < 2: return n last_streak = 0 current_streak = 1 longest = 0 for i in range(1, n): if nums[i] > nums[i-1]: current_streak += 1 else: if current_streak + last_streak > longest: longest = current_streak + last_streak last_streak = current_streak current_streak = 1 if current_streak + last_streak > longest: longest = current_streak + last_streak return longest if __name__ == '__main__': n = int(input()) nums = [int(i) for i in input().split(" ")] print(find_longest_streak(nums))
Title: DZY Loves Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: In a single line print the answer to the problem — the maximum length of the required subsegment. Demo Input: ['6\n7 2 3 1 5 6\n'] Demo Output: ['5\n'] Note: You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
```python def find_longest_streak(nums): if len(nums) < 2: return n last_streak = 0 current_streak = 1 longest = 0 for i in range(1, n): if nums[i] > nums[i-1]: current_streak += 1 else: if current_streak + last_streak > longest: longest = current_streak + last_streak last_streak = current_streak current_streak = 1 if current_streak + last_streak > longest: longest = current_streak + last_streak return longest if __name__ == '__main__': n = int(input()) nums = [int(i) for i in input().split(" ")] print(find_longest_streak(nums)) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,539,353,643
2,147,483,647
Python 3
OK
TESTS
40
171
512,000
import re k=input() helloRegex=re.compile(r'(h)+((\w)?)+(e)+((\w)?)+(l)+((\w)?)+(l)+((\w)?)+(o)+') if helloRegex.search(k)== None : print('NO') else : print('YES')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python import re k=input() helloRegex=re.compile(r'(h)+((\w)?)+(e)+((\w)?)+(l)+((\w)?)+(l)+((\w)?)+(o)+') if helloRegex.search(k)== None : print('NO') else : print('YES') ```
3.913546
99
A
Help Far Away Kingdom
PROGRAMMING
800
[ "strings" ]
A. Help Far Away Kingdom
2
256
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
[ "0.0\n", "1.49\n", "1.50\n", "2.71828182845904523536\n", "3.14159265358979323846\n", "12345678901234567890.1\n", "123456789123456789.999\n" ]
[ "0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa." ]
none
500
[ { "input": "0.0", "output": "0" }, { "input": "1.49", "output": "1" }, { "input": "1.50", "output": "2" }, { "input": "2.71828182845904523536", "output": "3" }, { "input": "3.14159265358979323846", "output": "3" }, { "input": "12345678901234567890.1", "output": "12345678901234567890" }, { "input": "123456789123456789.999", "output": "GOTO Vasilisa." }, { "input": "12345678901234567890.9", "output": "12345678901234567891" }, { "input": "123456789123456788.999", "output": "123456789123456789" }, { "input": "9.000", "output": "GOTO Vasilisa." }, { "input": "0.1", "output": "0" }, { "input": "0.2", "output": "0" }, { "input": "0.3", "output": "0" }, { "input": "0.4", "output": "0" }, { "input": "0.5", "output": "1" }, { "input": "0.6", "output": "1" }, { "input": "0.7", "output": "1" }, { "input": "0.8", "output": "1" }, { "input": "0.9", "output": "1" }, { "input": "1.0", "output": "1" }, { "input": "1.1", "output": "1" }, { "input": "1.2", "output": "1" }, { "input": "1.3", "output": "1" }, { "input": "1.4", "output": "1" }, { "input": "1.5", "output": "2" }, { "input": "1.6", "output": "2" }, { "input": "1.7", "output": "2" }, { "input": "1.8", "output": "2" }, { "input": "1.9", "output": "2" }, { "input": "2.0", "output": "2" }, { "input": "2.1", "output": "2" }, { "input": "2.2", "output": "2" }, { "input": "2.3", "output": "2" }, { "input": "2.4", "output": "2" }, { "input": "2.5", "output": "3" }, { "input": "2.6", "output": "3" }, { "input": "2.7", "output": "3" }, { "input": "2.8", "output": "3" }, { "input": "2.9", "output": "3" }, { "input": "3.0", "output": "3" }, { "input": "3.1", "output": "3" }, { "input": "3.2", "output": "3" }, { "input": "3.3", "output": "3" }, { "input": "3.4", "output": "3" }, { "input": "3.5", "output": "4" }, { "input": "3.6", "output": "4" }, { "input": "3.7", "output": "4" }, { "input": "3.8", "output": "4" }, { "input": "3.9", "output": "4" }, { "input": "4.0", "output": "4" }, { "input": "4.1", "output": "4" }, { "input": "4.2", "output": "4" }, { "input": "4.3", "output": "4" }, { "input": "4.4", "output": "4" }, { "input": "4.5", "output": "5" }, { "input": "4.6", "output": "5" }, { "input": "4.7", "output": "5" }, { "input": "4.8", "output": "5" }, { "input": "4.9", "output": "5" }, { "input": "5.0", "output": "5" }, { "input": "5.1", "output": "5" }, { "input": "5.2", "output": "5" }, { "input": "5.3", "output": "5" }, { "input": "5.4", "output": "5" }, { "input": "5.5", "output": "6" }, { "input": "5.6", "output": "6" }, { "input": "5.7", "output": "6" }, { "input": "5.8", "output": "6" }, { "input": "5.9", "output": "6" }, { "input": "6.0", "output": "6" }, { "input": "6.1", "output": "6" }, { "input": "6.2", "output": "6" }, { "input": "6.3", "output": "6" }, { "input": "6.4", "output": "6" }, { "input": "6.5", "output": "7" }, { "input": "6.6", "output": "7" }, { "input": "6.7", "output": "7" }, { "input": "6.8", "output": "7" }, { "input": "6.9", "output": "7" }, { "input": "7.0", "output": "7" }, { "input": "7.1", "output": "7" }, { "input": "7.2", "output": "7" }, { "input": "7.3", "output": "7" }, { "input": "7.4", "output": "7" }, { "input": "7.5", "output": "8" }, { "input": "7.6", "output": "8" }, { "input": "7.7", "output": "8" }, { "input": "7.8", "output": "8" }, { "input": "7.9", "output": "8" }, { "input": "8.0", "output": "8" }, { "input": "8.1", "output": "8" }, { "input": "8.2", "output": "8" }, { "input": "8.3", "output": "8" }, { "input": "8.4", "output": "8" }, { "input": "8.5", "output": "9" }, { "input": "8.6", "output": "9" }, { "input": "8.7", "output": "9" }, { "input": "8.8", "output": "9" }, { "input": "8.9", "output": "9" }, { "input": "9.0", "output": "GOTO Vasilisa." }, { "input": "9.1", "output": "GOTO Vasilisa." }, { "input": "9.2", "output": "GOTO Vasilisa." }, { "input": "9.3", "output": "GOTO Vasilisa." }, { "input": "9.4", "output": "GOTO Vasilisa." }, { "input": "9.5", "output": "GOTO Vasilisa." }, { "input": "9.6", "output": "GOTO Vasilisa." }, { "input": "9.7", "output": "GOTO Vasilisa." }, { "input": "9.8", "output": "GOTO Vasilisa." }, { "input": "9.9", "output": "GOTO Vasilisa." }, { "input": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098.1664915772983166314490532653577560222779830866949001942720729759794777105570672781798092416748052690224813237139640723361527601154465287615917169132637313918577673651098507390501962", "output": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098" }, { "input": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394.20211856263503281388748282682120712214711232598021393495443628276945042110862480888110959179019986486690931930108026302665438087068150666835901617457150158918705186964935221768346957536540345814875615118637945520917367155931078965", "output": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394" }, { "input": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616068" }, { "input": "718130341896330596635811874410345440628950330.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "718130341896330596635811874410345440628950331" }, { "input": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280722.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280723" }, { "input": "68289614863244584294178637364598054554769889.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "GOTO Vasilisa." }, { "input": "7536521504744364134984603189602839063535643888645969434165019366202558753840519.4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "GOTO Vasilisa." }, { "input": "646188694587964249318078225173.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "646188694587964249318078225174" }, { "input": "7017472758334494297677068672222822550374695787171163207025095950296957261530.50", "output": "7017472758334494297677068672222822550374695787171163207025095950296957261531" }, { "input": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774368.50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774369" }, { "input": "682500858233333594535201113441004740771119672961581796618069185960107115823662126812159957094407454522028503739299.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "GOTO Vasilisa." }, { "input": "41203422675619090661099806687619.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "GOTO Vasilisa." } ]
1,669,372,697
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
a=float(input()) if a%10>=9: print("GOTO vasilisa") elif a%1?=0.5: print(str(int(a))[:-1]+str(int(a)%10+1)) else: print(a//1)
Title: Help Far Away Kingdom Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? Input Specification: The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. Output Specification: If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). Demo Input: ['0.0\n', '1.49\n', '1.50\n', '2.71828182845904523536\n', '3.14159265358979323846\n', '12345678901234567890.1\n', '123456789123456789.999\n'] Demo Output: ['0', '1', '2', '3', '3', '12345678901234567890', 'GOTO Vasilisa.'] Note: none
```python a=float(input()) if a%10>=9: print("GOTO vasilisa") elif a%1?=0.5: print(str(int(a))[:-1]+str(int(a)%10+1)) else: print(a//1) ```
-1
278
A
Circle Line
PROGRAMMING
800
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.
Print a single number — the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
500
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "input": "6\n89 82 87 32 67 33\n4 4", "output": "0" }, { "input": "7\n2 3 17 10 2 2 2\n4 2", "output": "18" }, { "input": "3\n4 37 33\n3 3", "output": "0" }, { "input": "8\n87 40 96 7 86 86 72 97\n6 8", "output": "158" }, { "input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8", "output": "348" }, { "input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7", "output": "0" }, { "input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16", "output": "452" }, { "input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6", "output": "337" }, { "input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64", "output": "1740" }, { "input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5", "output": "2127" }, { "input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57", "output": "932" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6", "output": "997" }, { "input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24", "output": "195" }, { "input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10", "output": "60" }, { "input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25", "output": "2523" }, { "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\n1 51", "output": "5000" }, { "input": "4\n1 1 1 1\n2 4", "output": "2" }, { "input": "4\n1 1 2 1\n2 4", "output": "2" } ]
1,583,840,092
2,147,483,647
Python 3
OK
TESTS
23
218
0
num = int(input()) stations = list(map(int,list(input().split()))) points = sorted(list(map(int,list(input().split())))) sum1 = sum(stations[points[0]-1:points[1]-1]) sum2 = sum(stations) - sum(stations[points[0]-1:points[1]-1]) if sum1 < sum2: print(sum1) else: print(sum2)
Title: Circle Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. Output Specification: Print a single number — the length of the shortest path between stations number *s* and *t*. Demo Input: ['4\n2 3 4 9\n1 3\n', '4\n5 8 2 100\n4 1\n', '3\n1 1 1\n3 1\n', '3\n31 41 59\n1 1\n'] Demo Output: ['5\n', '15\n', '1\n', '0\n'] Note: In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
```python num = int(input()) stations = list(map(int,list(input().split()))) points = sorted(list(map(int,list(input().split())))) sum1 = sum(stations[points[0]-1:points[1]-1]) sum2 = sum(stations) - sum(stations[points[0]-1:points[1]-1]) if sum1 < sum2: print(sum1) else: print(sum2) ```
3
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,687,002,580
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
n,a,b = map(int,input().split()) count = 2 if n % 2 == 0: print(count) else: print(count + (n% 2))
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python n,a,b = map(int,input().split()) count = 2 if n % 2 == 0: print(count) else: print(count + (n% 2)) ```
0
615
A
Bulbs
PROGRAMMING
800
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
500
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" }, { "input": "1 5\n5 1 1 1 1 5", "output": "NO" }, { "input": "2 5\n4 3 1 4 2\n4 2 3 4 5", "output": "YES" }, { "input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "output": "YES" }, { "input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "100 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": "NO" }, { "input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6", "output": "YES" }, { "input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "NO" }, { "input": "1 4\n3 1 2 3", "output": "NO" }, { "input": "1 4\n3 2 3 4", "output": "NO" }, { "input": "2 4\n3 2 3 4\n1 1", "output": "YES" }, { "input": "2 4\n3 1 2 3\n1 4", "output": "YES" }, { "input": "5 1\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "1 1\n0", "output": "NO" }, { "input": "1 10\n10 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 100\n99 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", "output": "NO" }, { "input": "1 3\n3 1 2 1", "output": "NO" }, { "input": "1 100\n100 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", "output": "YES" } ]
1,666,107,144
2,147,483,647
Python 3
OK
TESTS
45
46
0
a,b=map(int,input().split()) g=set() for i in range(a): n=list(map(int,input().split())) n.pop(0) g.update(n) print(['NO','YES'][len(g) == b])
Title: Bulbs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. Input Specification: The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. Output Specification: If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". Demo Input: ['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
```python a,b=map(int,input().split()) g=set() for i in range(a): n=list(map(int,input().split())) n.pop(0) g.update(n) print(['NO','YES'][len(g) == b]) ```
3
920
C
Swap Adjacent Elements
PROGRAMMING
1,400
[ "dfs and similar", "greedy", "math", "sortings", "two pointers" ]
null
null
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array. For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap *i*-th element with (*i*<=+<=1)-th (if the position is not forbidden). Can you make this array sorted in ascending order performing some sequence of swapping operations?
The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once. The third line contains a string of *n*<=-<=1 characters, each character is either 0 or 1. If *i*-th character is 1, then you can swap *i*-th element with (*i*<=+<=1)-th any number of times, otherwise it is forbidden to swap *i*-th element with (*i*<=+<=1)-th.
If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO.
[ "6\n1 2 5 3 4 6\n01110\n", "6\n1 2 5 3 4 6\n01010\n" ]
[ "YES\n", "NO\n" ]
In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>.
0
[ { "input": "6\n1 2 5 3 4 6\n01110", "output": "YES" }, { "input": "6\n1 2 5 3 4 6\n01010", "output": "NO" }, { "input": "6\n1 6 3 4 5 2\n01101", "output": "NO" }, { "input": "6\n2 3 1 4 5 6\n01111", "output": "NO" }, { "input": "4\n2 3 1 4\n011", "output": "NO" }, { "input": "2\n2 1\n0", "output": "NO" }, { "input": "5\n1 2 4 5 3\n0101", "output": "NO" }, { "input": "5\n1 2 4 5 3\n0001", "output": "NO" }, { "input": "5\n1 4 5 2 3\n0110", "output": "NO" }, { "input": "5\n4 5 1 2 3\n0111", "output": "NO" }, { "input": "3\n3 1 2\n10", "output": "NO" }, { "input": "5\n2 3 4 5 1\n0011", "output": "NO" }, { "input": "16\n3 4 14 16 11 7 13 9 10 8 6 5 15 12 1 2\n111111101111111", "output": "NO" }, { "input": "5\n1 5 3 4 2\n1101", "output": "NO" }, { "input": "6\n6 1 2 3 4 5\n11101", "output": "NO" }, { "input": "3\n2 3 1\n01", "output": "NO" }, { "input": "6\n1 6 3 4 5 2\n01110", "output": "NO" }, { "input": "7\n1 7 3 4 5 6 2\n010001", "output": "NO" }, { "input": "5\n5 2 3 4 1\n1001", "output": "NO" }, { "input": "4\n1 3 4 2\n001", "output": "NO" }, { "input": "5\n4 5 1 2 3\n1011", "output": "NO" }, { "input": "6\n1 5 3 4 2 6\n11011", "output": "NO" }, { "input": "5\n1 4 2 5 3\n1101", "output": "NO" }, { "input": "5\n3 2 4 1 5\n1010", "output": "NO" }, { "input": "6\n1 4 3 5 6 2\n01101", "output": "NO" }, { "input": "6\n2 3 4 5 1 6\n00010", "output": "NO" }, { "input": "10\n5 2 7 9 1 10 3 4 6 8\n111101000", "output": "NO" }, { "input": "5\n2 4 3 1 5\n0110", "output": "NO" }, { "input": "4\n3 1 2 4\n100", "output": "NO" }, { "input": "6\n1 5 3 4 2 6\n01010", "output": "NO" }, { "input": "4\n3 1 2 4\n101", "output": "NO" }, { "input": "4\n2 4 3 1\n011", "output": "NO" }, { "input": "4\n2 3 4 1\n001", "output": "NO" }, { "input": "4\n3 4 1 2\n011", "output": "NO" }, { "input": "5\n2 4 1 3 5\n0110", "output": "NO" }, { "input": "4\n1 3 4 2\n101", "output": "NO" }, { "input": "20\n20 19 18 17 16 15 1 2 3 4 5 14 13 12 11 10 9 8 7 6\n1111111011111111111", "output": "NO" }, { "input": "6\n6 5 4 1 2 3\n11100", "output": "NO" }, { "input": "5\n2 3 5 1 4\n0011", "output": "NO" }, { "input": "4\n1 4 2 3\n010", "output": "NO" }, { "input": "6\n1 6 3 4 5 2\n01001", "output": "NO" }, { "input": "7\n1 7 2 4 3 5 6\n011110", "output": "NO" }, { "input": "5\n1 3 4 2 5\n0010", "output": "NO" }, { "input": "5\n5 4 3 1 2\n1110", "output": "NO" }, { "input": "5\n2 5 4 3 1\n0111", "output": "NO" }, { "input": "4\n2 3 4 1\n101", "output": "NO" }, { "input": "5\n1 4 5 2 3\n1011", "output": "NO" }, { "input": "5\n1 3 2 5 4\n1110", "output": "NO" }, { "input": "6\n3 2 4 1 5 6\n10111", "output": "NO" }, { "input": "7\n3 1 7 4 5 2 6\n101110", "output": "NO" }, { "input": "10\n5 4 10 9 2 1 6 7 3 8\n011111111", "output": "NO" }, { "input": "5\n1 5 3 2 4\n1110", "output": "NO" }, { "input": "4\n2 3 4 1\n011", "output": "NO" }, { "input": "5\n5 4 3 2 1\n0000", "output": "NO" }, { "input": "12\n6 9 11 1 12 7 5 8 10 4 3 2\n11111111110", "output": "NO" }, { "input": "5\n3 1 5 2 4\n1011", "output": "NO" }, { "input": "5\n4 5 1 2 3\n1110", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 8 9 7 10\n000000000", "output": "NO" }, { "input": "6\n5 6 3 2 4 1\n01111", "output": "NO" }, { "input": "5\n1 3 4 2 5\n0100", "output": "NO" }, { "input": "4\n2 1 4 3\n100", "output": "NO" }, { "input": "6\n1 2 3 4 6 5\n00000", "output": "NO" }, { "input": "6\n4 6 5 3 2 1\n01111", "output": "NO" }, { "input": "5\n3 1 4 5 2\n1001", "output": "NO" }, { "input": "5\n5 2 3 1 4\n1011", "output": "NO" }, { "input": "3\n2 3 1\n10", "output": "NO" }, { "input": "10\n6 5 9 4 3 2 8 10 7 1\n111111110", "output": "NO" }, { "input": "7\n1 2 7 3 4 5 6\n111101", "output": "NO" }, { "input": "6\n5 6 1 2 4 3\n11101", "output": "NO" }, { "input": "6\n4 6 3 5 2 1\n11110", "output": "NO" }, { "input": "5\n5 4 2 3 1\n1110", "output": "NO" }, { "input": "2\n2 1\n1", "output": "YES" }, { "input": "3\n1 3 2\n10", "output": "NO" }, { "input": "5\n3 4 5 1 2\n1110", "output": "NO" }, { "input": "5\n3 4 2 1 5\n0110", "output": "NO" }, { "input": "6\n6 1 2 3 4 5\n10001", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n000000000", "output": "YES" }, { "input": "3\n3 2 1\n00", "output": "NO" }, { "input": "5\n5 4 3 2 1\n1110", "output": "NO" }, { "input": "6\n3 1 2 5 6 4\n10011", "output": "NO" }, { "input": "6\n3 2 1 6 5 4\n11000", "output": "NO" }, { "input": "2\n1 2\n0", "output": "YES" }, { "input": "2\n1 2\n1", "output": "YES" }, { "input": "11\n1 2 3 4 5 6 7 8 9 10 11\n0000000000", "output": "YES" }, { "input": "4\n2 4 3 1\n101", "output": "NO" }, { "input": "4\n3 4 1 2\n101", "output": "NO" }, { "input": "3\n1 3 2\n01", "output": "YES" }, { "input": "6\n6 2 3 1 4 5\n11110", "output": "NO" }, { "input": "3\n2 1 3\n01", "output": "NO" }, { "input": "5\n1 5 4 3 2\n0111", "output": "YES" }, { "input": "6\n1 2 6 3 4 5\n11110", "output": "NO" }, { "input": "7\n2 3 1 7 6 5 4\n011111", "output": "NO" }, { "input": "6\n5 6 1 2 3 4\n01111", "output": "NO" }, { "input": "4\n1 2 4 3\n001", "output": "YES" }, { "input": "6\n1 2 3 6 4 5\n11001", "output": "NO" }, { "input": "11\n9 8 10 11 1 2 3 4 5 6 7\n1101111111", "output": "NO" }, { "input": "5\n1 5 3 4 2\n0101", "output": "NO" }, { "input": "10\n9 1 2 3 7 8 5 6 4 10\n110111100", "output": "NO" }, { "input": "7\n1 2 7 3 4 5 6\n111011", "output": "NO" }, { "input": "10\n3 10 1 2 6 4 5 7 8 9\n111111001", "output": "NO" }, { "input": "10\n1 3 6 5 2 9 7 8 4 10\n001101111", "output": "NO" }, { "input": "10\n1 8 9 7 6 10 4 2 3 5\n111111101", "output": "NO" }, { "input": "7\n1 2 5 3 6 4 7\n111011", "output": "NO" }, { "input": "4\n2 4 3 1\n100", "output": "NO" }, { "input": "6\n1 2 3 4 6 5\n00001", "output": "YES" }, { "input": "6\n2 1 3 4 5 6\n10000", "output": "YES" }, { "input": "5\n3 2 1 5 4\n1100", "output": "NO" }, { "input": "9\n2 1 3 6 5 4 7 9 8\n10011001", "output": "YES" }, { "input": "8\n2 6 4 1 5 7 3 8\n1010010", "output": "NO" }, { "input": "5\n1 2 4 5 3\n1101", "output": "NO" }, { "input": "6\n1 3 5 2 4 6\n00110", "output": "NO" }, { "input": "6\n1 3 6 2 4 5\n10111", "output": "NO" }, { "input": "9\n9 8 7 6 5 4 3 1 2\n11111110", "output": "NO" }, { "input": "10\n6 7 8 9 10 1 2 3 4 5\n111111110", "output": "NO" }, { "input": "8\n6 1 7 8 3 2 5 4\n1011111", "output": "NO" }, { "input": "70\n4 65 66 30 67 16 39 35 57 14 42 51 5 21 61 53 63 13 60 29 68 70 69 46 20 2 43 47 49 52 26 44 54 62 25 19 12 28 27 24 18 36 6 33 7 8 11 1 45 32 64 38 23 22 56 59 15 9 41 37 40 55 3 31 34 48 50 10 17 58\n111111101101111111111110101111111111111101101111010010110011011110010", "output": "NO" }, { "input": "5\n5 3 2 4 1\n0100", "output": "NO" }, { "input": "6\n3 2 6 5 1 4\n11011", "output": "NO" }, { "input": "6\n1 2 4 5 6 3\n10011", "output": "NO" }, { "input": "7\n1 7 3 2 5 6 4\n111001", "output": "NO" } ]
1,518,262,219
2,147,483,647
Python 3
OK
TESTS
139
249
20,480,000
n=int(input()) a=input().split() b=input()+'1' c=[] k=0 for u in b: c.append(k) if u=='0': k+=1 for i in range(0,n): if c[i]!=c[int(a[i])-1]: print('NO') exit() print('YES') exit()
Title: Swap Adjacent Elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array. For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap *i*-th element with (*i*<=+<=1)-th (if the position is not forbidden). Can you make this array sorted in ascending order performing some sequence of swapping operations? Input Specification: The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once. The third line contains a string of *n*<=-<=1 characters, each character is either 0 or 1. If *i*-th character is 1, then you can swap *i*-th element with (*i*<=+<=1)-th any number of times, otherwise it is forbidden to swap *i*-th element with (*i*<=+<=1)-th. Output Specification: If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. Demo Input: ['6\n1 2 5 3 4 6\n01110\n', '6\n1 2 5 3 4 6\n01010\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>.
```python n=int(input()) a=input().split() b=input()+'1' c=[] k=0 for u in b: c.append(k) if u=='0': k+=1 for i in range(0,n): if c[i]!=c[int(a[i])-1]: print('NO') exit() print('YES') exit() ```
3
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=&gt;<=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*). In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces.
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "input": "3 1 2\n6 5 5", "output": "1" }, { "input": "3 2 1\n10 10 8", "output": "2" }, { "input": "8 3 5\n42 55 61 72 83 10 22 33", "output": "6" }, { "input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995", "output": "999999990" }, { "input": "4 1 3\n10 8 7 3", "output": "2" }, { "input": "4 2 2\n402 10 10 402", "output": "392" }, { "input": "4 1 3\n10 402 402 10", "output": "0" }, { "input": "4 3 1\n100 100 200 200", "output": "0" }, { "input": "150 10 140\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", "output": "0" }, { "input": "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" } ]
1,597,042,024
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
6,656,000
n=int(input()) c=0 for i in range (n) : a,b,d=list(map(int,input().split())) c+=a+b+d if c : print("NO") else : print("YES")
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=&gt;<=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*). In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? Input Specification: The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces. Output Specification: Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. Demo Input: ['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n'] Demo Output: ['3\n', '0\n'] Note: In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
```python n=int(input()) c=0 for i in range (n) : a,b,d=list(map(int,input().split())) c+=a+b+d if c : print("NO") else : print("YES") ```
-1
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,504,626,847
2,947
Python 3
RUNTIME_ERROR
TESTS
0
46
0
a=int(input()) p=0 t=0 q=[] for k in range(0,a): b=input() q.append(b) for j in q: if(j=="1"): p=p+1 else: t=t+1 if(p>=t): print(p) else: print(t)
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 a=int(input()) p=0 t=0 q=[] for k in range(0,a): b=input() q.append(b) for j in q: if(j=="1"): p=p+1 else: t=t+1 if(p>=t): print(p) else: print(t) ```
-1
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,525,077,009
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
77
7,372,800
import math in_put = input('') in_put = in_put.split(' ') l = int(in_put[0]) r = int(in_put[1]) a = int(in_put[2]) c = 0 if (l > r): c = r if (a > (l - r)): c = c + (l - r) elif (a <= (l - r)): c = c + a elif (l < r): c = l if (a < r - l): c = c + a elif (a >= r - l): c = c + l - r elif (l == r): c = l c = c + math.floor(a / 2) print(c*2, end='')
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python import math in_put = input('') in_put = in_put.split(' ') l = int(in_put[0]) r = int(in_put[1]) a = int(in_put[2]) c = 0 if (l > r): c = r if (a > (l - r)): c = c + (l - r) elif (a <= (l - r)): c = c + a elif (l < r): c = l if (a < r - l): c = c + a elif (a >= r - l): c = c + l - r elif (l == r): c = l c = c + math.floor(a / 2) print(c*2, end='') ```
0
522
B
Photo to Remember
PROGRAMMING
1,100
[ "*special", "data structures", "dp", "implementation" ]
null
null
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangle of width *w**i* pixels and height *h**i* pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is *W*<=×<=*H*, where *W* is the total sum of all widths and *H* is the maximum height of all the photographed friends. As is usually the case, the friends made *n* photos — the *j*-th (1<=≤<=*j*<=≤<=*n*) photo had everybody except for the *j*-th friend as he was the photographer. Print the minimum size of each made photo in pixels.
The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends. Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the corresponding rectangle.
Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one.
[ "3\n1 10\n5 5\n10 1\n", "3\n2 1\n1 2\n2 1\n" ]
[ "75 110 60 ", "6 4 6 " ]
none
1,000
[ { "input": "3\n1 10\n5 5\n10 1", "output": "75 110 60 " }, { "input": "3\n2 1\n1 2\n2 1", "output": "6 4 6 " }, { "input": "2\n1 5\n2 3", "output": "6 5 " }, { "input": "2\n2 3\n1 1", "output": "1 6 " }, { "input": "3\n1 10\n2 10\n3 10", "output": "50 40 30 " }, { "input": "3\n2 10\n1 9\n3 7", "output": "36 50 30 " }, { "input": "3\n1 1\n3 2\n2 3", "output": "15 9 8 " }, { "input": "3\n3 123\n1 456\n2 789", "output": "2367 3945 1824 " }, { "input": "3\n2 987\n3 654\n1 321", "output": "2616 2961 4935 " }, { "input": "3\n3 143\n2 543\n1 893", "output": "2679 3572 2715 " }, { "input": "2\n1 1\n1 2", "output": "2 1 " }, { "input": "3\n2 22\n1 11\n2 22", "output": "66 88 66 " }, { "input": "3\n1 11\n1 12\n1 13", "output": "26 26 24 " }, { "input": "3\n1 11\n1 12\n2 10", "output": "36 33 24 " }, { "input": "10\n6 20\n1 175\n1 758\n1 169\n2 490\n2 600\n4 463\n7 377\n9 40\n4 961", "output": "29791 34596 34596 34596 33635 33635 31713 28830 26908 25014 " }, { "input": "10\n8 158\n1 709\n6 766\n4 335\n5 356\n2 972\n1 108\n4 235\n3 631\n1 414", "output": "26244 33048 28188 30132 29160 25278 33048 30132 31104 33048 " }, { "input": "10\n7 549\n9 115\n8 141\n3 650\n5 730\n3 841\n7 18\n9 170\n2 217\n1 155", "output": "39527 37845 38686 42891 41209 37230 39527 37845 43732 44573 " }, { "input": "10\n6 386\n9 816\n9 268\n9 481\n8 284\n10 715\n9 351\n7 580\n4 327\n7 392", "output": "58752 49335 56304 56304 57120 55488 56304 57936 60384 57936 " }, { "input": "10\n9 292\n4 6\n6 638\n8 461\n10 970\n10 488\n9 769\n10 644\n8 280\n5 334", "output": "67900 72750 70810 68870 53061 66930 67900 66930 68870 71780 " }, { "input": "10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000", "output": "90000 90000 90000 90000 90000 90000 90000 90000 90000 90000 " } ]
1,677,174,837
2,147,483,647
Python 3
OK
TESTS
44
904
12,697,600
n = int(input()) W = 0 pers = [] H1 = 0; H2 = 0 I = 0 for i in range(n): w, h = map(int, input().split()) pers.append([w,h]) W += w if h > H2: H2 = h I = i for i in range(n): if i == I: continue w, h = pers[i] if H2 >= h > H1: H1 = h for i in range(0, n): if i == I: print((W-pers[i][0])*H1, end = " ") else: print((W-pers[i][0])*H2, end = " ")
Title: Photo to Remember Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangle of width *w**i* pixels and height *h**i* pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is *W*<=×<=*H*, where *W* is the total sum of all widths and *H* is the maximum height of all the photographed friends. As is usually the case, the friends made *n* photos — the *j*-th (1<=≤<=*j*<=≤<=*n*) photo had everybody except for the *j*-th friend as he was the photographer. Print the minimum size of each made photo in pixels. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends. Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the corresponding rectangle. Output Specification: Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one. Demo Input: ['3\n1 10\n5 5\n10 1\n', '3\n2 1\n1 2\n2 1\n'] Demo Output: ['75 110 60 ', '6 4 6 '] Note: none
```python n = int(input()) W = 0 pers = [] H1 = 0; H2 = 0 I = 0 for i in range(n): w, h = map(int, input().split()) pers.append([w,h]) W += w if h > H2: H2 = h I = i for i in range(n): if i == I: continue w, h = pers[i] if H2 >= h > H1: H1 = h for i in range(0, n): if i == I: print((W-pers[i][0])*H1, end = " ") else: print((W-pers[i][0])*H2, end = " ") ```
3
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "100" }, { "input": "9 3\n9 5 2 3 7 1 8 4 6", "output": "7" }, { "input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58", "output": "16" }, { "input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54", "output": "48" }, { "input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1", "output": "44" }, { "input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3", "output": "46" }, { "input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78", "output": "40" }, { "input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69", "output": "11" }, { "input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95", "output": "50" }, { "input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9", "output": "86" }, { "input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7", "output": "93" }, { "input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42", "output": "77" }, { "input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48", "output": "97" }, { "input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78", "output": "20" }, { "input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41", "output": "97" }, { "input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82", "output": "51" }, { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58", "output": "97" }, { "input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88", "output": "47" }, { "input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51", "output": "98" }, { "input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67", "output": "94" }, { "input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19", "output": "95" }, { "input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49", "output": "88" }, { "input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1", "output": "99" }, { "input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95", "output": "100" }, { "input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15", "output": "98" }, { "input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16", "output": "100" }, { "input": "1 3\n5", "output": "1" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 3\n4 2", "output": "1" }, { "input": "2 5\n99 97", "output": "2" }, { "input": "3 4\n7 5 2", "output": "2" }, { "input": "3 50\n47 86 51", "output": "3" }, { "input": "5 100\n82 100 85 1 37", "output": "5" }, { "input": "5 20\n40 39 21 5 20", "output": "3" }, { "input": "1 27\n81", "output": "1" }, { "input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1", "output": "7" }, { "input": "2 1\n100 2", "output": "1" }, { "input": "2 2\n6 4", "output": "1" }, { "input": "5 2\n6 4 4 1 1", "output": "1" }, { "input": "1 4\n3", "output": "1" }, { "input": "3 2\n1 5 3", "output": "2" }, { "input": "3 1\n3 2 2", "output": "1" }, { "input": "3 1\n2 3 2", "output": "2" }, { "input": "5 1\n5 1 1 1 1", "output": "1" }, { "input": "2 3\n7 4", "output": "1" } ]
1,669,393,173
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] -= m mx = max(a) a.reverse() print(n - a.index(mx))
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output a single integer, representing the number of the last child. Demo Input: ['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n'] Demo Output: ['4\n', '6\n'] Note: Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
```python n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] -= m mx = max(a) a.reverse() print(n - a.index(mx)) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "10000220" }, { "input": ".", "output": "0" }, { "input": "-.", "output": "1" }, { "input": "--", "output": "2" }, { "input": "..", "output": "00" }, { "input": "--.", "output": "20" }, { "input": ".--.", "output": "020" }, { "input": ".-.-..", "output": "0110" }, { "input": "----.-.", "output": "2201" }, { "input": "-..--.-.", "output": "10201" }, { "input": "..--..--.", "output": "0020020" }, { "input": "-.-.---.--..-..-.-.-..-..-.--.", "output": "112120010111010120" }, { "input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "output": "21112220010101011012011011221011" }, { "input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------", "output": "11020111110111222212021020002022111100201121222020012022110010222" }, { "input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..", "output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110" }, { "input": ".-..-.-.---.-----.--.---...-.--.-.-....-..", "output": "01011212212021001201100010" }, { "input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..", "output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210" }, { "input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.", "output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220" }, { "input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----", "output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122" }, { "input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..", "output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110" }, { "input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.", "output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020" }, { "input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..", "output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200" }, { "input": "-.---...----...--.--...-.--.----", "output": "121002200020200012022" }, { "input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.", "output": "202020212012111010201021100001021221200011222112012201012220" } ]
1,621,032,763
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
102,400
from collections import defaultdict def solve(): s = input() m = '' code = defaultdict(int) code['.'] = '0' code['-.'] = '1' code['--'] = '2' i = 0 prev = '' while (i<len(s)): prev += s[i] if(code[prev] == 0 ): i+=1 else: m+= code[prev] prev = '' i+=1 return m
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python from collections import defaultdict def solve(): s = input() m = '' code = defaultdict(int) code['.'] = '0' code['-.'] = '1' code['--'] = '2' i = 0 prev = '' while (i<len(s)): prev += s[i] if(code[prev] == 0 ): i+=1 else: m+= code[prev] prev = '' i+=1 return m ```
0
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number.
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "output": "130" }, { "input": "900000000 16", "output": "1" }, { "input": "909090909 50", "output": "3" }, { "input": "1001 2", "output": "100" }, { "input": "5 2", "output": "3" }, { "input": "2 1", "output": "1" } ]
1,697,101,461
2,147,483,647
PyPy 3
OK
TESTS
11
77
0
n, k = [int(z) for z in input().split(" ")] for i in range(1,k+1): if(n%10!=0): n=n-1 else: n=n/10 print(int(n))
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number. Input Specification: The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Specification: Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number. Demo Input: ['512 4\n', '1000000000 9\n'] Demo Output: ['50\n', '1\n'] Note: The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
```python n, k = [int(z) for z in input().split(" ")] for i in range(1,k+1): if(n%10!=0): n=n-1 else: n=n/10 print(int(n)) ```
3
385
A
Bear and Raspberry
PROGRAMMING
1,000
[ "brute force", "greedy", "implementation" ]
null
null
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=&lt;<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel. The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Print a single integer — the answer to the problem.
[ "5 1\n5 10 7 3 20\n", "6 2\n100 1 10 40 10 40\n", "3 0\n1 2 3\n" ]
[ "3\n", "97\n", "0\n" ]
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
500
[ { "input": "5 1\n5 10 7 3 20", "output": "3" }, { "input": "6 2\n100 1 10 40 10 40", "output": "97" }, { "input": "3 0\n1 2 3", "output": "0" }, { "input": "2 0\n2 1", "output": "1" }, { "input": "10 5\n10 1 11 2 12 3 13 4 14 5", "output": "4" }, { "input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77", "output": "87" }, { "input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93", "output": "84" }, { "input": "6 100\n10 9 8 7 6 5", "output": "0" }, { "input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46", "output": "78" }, { "input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44", "output": "0" }, { "input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62", "output": "4" }, { "input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71", "output": "0" }, { "input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1", "output": "0" }, { "input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27", "output": "63" }, { "input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22", "output": "38" }, { "input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83", "output": "91" }, { "input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14", "output": "79" }, { "input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24", "output": "91" }, { "input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49", "output": "83" }, { "input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70", "output": "94" }, { "input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42", "output": "43" }, { "input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0", "output": "100" }, { "input": "3 1\n1 2 3", "output": "0" }, { "input": "3 2\n3 3 3", "output": "0" }, { "input": "3 3\n3 2 1", "output": "0" }, { "input": "3 100\n1 2 3", "output": "0" }, { "input": "2 100\n0 0", "output": "0" }, { "input": "2 90\n10 5", "output": "0" }, { "input": "2 5\n5 4", "output": "0" }, { "input": "3 1\n19 20 1", "output": "18" }, { "input": "5 1\n5 10 7 4 20", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "0" } ]
1,605,011,415
2,147,483,647
PyPy 3
OK
TESTS
32
187
0
n,c=map(int,input().split()) x=list(map(int,input().split())) e=0 for i in range(n-1): e=max(e,x[i]-x[i+1]-c) print(e)
Title: Bear and Raspberry Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=&lt;<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel. The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. Input Specification: The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n'] Demo Output: ['3\n', '97\n', '0\n'] Note: In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
```python n,c=map(int,input().split()) x=list(map(int,input().split())) e=0 for i in range(n-1): e=max(e,x[i]-x[i+1]-c) print(e) ```
3
103
A
Testing Pants for Sadness
PROGRAMMING
1,100
[ "greedy", "implementation", "math" ]
A. Testing Pants for Sadness
2
256
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2\n1 1\n", "2\n2 2\n", "1\n10\n" ]
[ "2", "5", "10" ]
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
500
[ { "input": "2\n1 1", "output": "2" }, { "input": "2\n2 2", "output": "5" }, { "input": "1\n10", "output": "10" }, { "input": "3\n2 4 1", "output": "10" }, { "input": "4\n5 5 3 1", "output": "22" }, { "input": "2\n1000000000 1000000000", "output": "2999999999" }, { "input": "10\n5 7 8 1 10 3 6 4 10 6", "output": "294" }, { "input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8", "output": "24212" }, { "input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62", "output": "261115" }, { "input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644", "output": "2519223" }, { "input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950", "output": "24496504" }, { "input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899", "output": "685659563557" }, { "input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460", "output": "27409624352" }, { "input": "1\n84355694", "output": "84355694" }, { "input": "2\n885992042 510468669", "output": "1906929379" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1", "output": "2686" }, { "input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1", "output": "4667" } ]
1,616,750,795
2,147,483,647
Python 3
OK
TESTS
25
124
0
try: t=int(input()) a=[int(i) for i in input().split()] c=0 j=[] for i in range(t): c=(a[i]-1)*(i+1)+1 j.append(c) print(sum(j)) except: pass
Title: Testing Pants for Sadness Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case? Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. Output Specification: Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['2\n1 1\n', '2\n2 2\n', '1\n10\n'] Demo Output: ['2', '5', '10'] Note: Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
```python try: t=int(input()) a=[int(i) for i in input().split()] c=0 j=[] for i in range(t): c=(a[i]-1)*(i+1)+1 j.append(c) print(sum(j)) except: pass ```
3.969
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge. You task is to find any suitable placement of chessmen on the given chessboard.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------", "output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------" }, { "input": "1 1\n-", "output": "-" }, { "input": "4 2\n..\n..\n..\n..", "output": "BW\nWB\nBW\nWB" }, { "input": "5 1\n.\n.\n.\n.\n.", "output": "B\nW\nB\nW\nB" } ]
1,628,556,853
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a, b = map(int, input().split()) for i in range(0, a): n = input() resultado = "" for j in range(0, b): if n[j] == '.': if (i + j) & 1 == 1: resultado = resultado + "B" else: resultado = resultado + "W" else: resultado = resultado + n[j] print(resultado)
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge. You task is to find any suitable placement of chessmen on the given chessboard. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad. Output Specification: Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guaranteed that at least one answer exists. Demo Input: ['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.'] Demo Output: ['B\n', 'BW\nWB\n', 'B-B\n---\n--B'] Note: In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
```python a, b = map(int, input().split()) for i in range(0, a): n = input() resultado = "" for j in range(0, b): if n[j] == '.': if (i + j) & 1 == 1: resultado = resultado + "B" else: resultado = resultado + "W" else: resultado = resultado + n[j] print(resultado) ```
-1
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
1,510,507,608
4,907
Python 3
RUNTIME_ERROR
PRETESTS
2
46
0
n = int(input()) queue = [int(i) for i in input().split()] last = queue.pop() n -= queue.count(last) + 1 while queue.count(last): del queue[queue.index(last)] the_longest_distance = 0 all_canteenes = set(queue) for canteen in all_canteenes: tmp = queue.copy()[::-1] first = n - 1 - tmp.index(canteen) del tmp[tmp.index(canteen)] if tmp.count(canteen): end = n - tmp.index(canteen) else: end = n - 1 if end - first > the_longest_distance: the_longest_distance = end - first answer = canteen print(answer)
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. Input Specification: In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. Output Specification: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Demo Input: ['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n'] Demo Output: ['3\n', '2\n'] Note: In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
```python n = int(input()) queue = [int(i) for i in input().split()] last = queue.pop() n -= queue.count(last) + 1 while queue.count(last): del queue[queue.index(last)] the_longest_distance = 0 all_canteenes = set(queue) for canteen in all_canteenes: tmp = queue.copy()[::-1] first = n - 1 - tmp.index(canteen) del tmp[tmp.index(canteen)] if tmp.count(canteen): end = n - tmp.index(canteen) else: end = n - 1 if end - first > the_longest_distance: the_longest_distance = end - first answer = canteen print(answer) ```
-1
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
1,685,737,550
2,147,483,647
Python 3
OK
TESTS
31
92
0
n=int(input()) x=input() num=x.split(" ") sum=0 for m in num: sum+=int(m) print(sum/n)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python n=int(input()) x=input() num=x.split(" ") sum=0 for m in num: sum+=int(m) print(sum/n) ```
3
463
C
Gargari and Bishops
PROGRAMMING
1,900
[ "greedy", "hashing", "implementation" ]
null
null
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard.
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right. If there are several optimal solutions, you can print any of them.
[ "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n" ]
[ "12\n2 2 3 2\n" ]
none
1,500
[ { "input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1", "output": "12\n2 2 3 2" }, { "input": "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 79 51\n93 66 53 39 89 30 16 27 63 93", "output": "2242\n6 6 7 6" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "output": "0\n1 1 1 2" }, { "input": "15\n2 6 9 4 8 9 10 10 3 8 8 4 4 8 7\n10 9 2 6 8 10 5 2 8 4 9 6 9 10 10\n3 1 5 1 6 5 1 6 4 4 3 3 9 8 10\n5 7 10 6 4 9 6 8 1 5 4 9 10 4 8\n9 6 10 5 8 6 9 9 3 4 4 7 6 2 4\n8 6 10 7 3 3 8 10 3 8 4 8 8 3 1\n7 3 6 8 8 5 5 8 3 7 2 6 3 9 7\n6 8 4 7 7 7 10 4 6 4 3 10 1 10 2\n1 6 7 8 3 4 2 8 1 7 4 4 4 9 5\n3 4 4 6 1 10 2 2 5 8 7 7 7 7 6\n10 9 3 6 8 6 1 9 5 4 7 10 7 1 8\n3 3 4 9 8 6 10 2 9 5 9 5 3 7 3\n1 8 1 3 4 8 10 4 8 4 7 5 4 6 7\n3 10 9 6 8 8 1 8 9 9 4 9 5 6 5\n7 6 3 9 9 8 6 10 3 6 4 2 10 9 7", "output": "361\n7 9 9 8" }, { "input": "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5", "output": "159\n4 4 5 4" }, { "input": "13\n9 9 3 3 5 6 8 2 6 1 10 3 8\n10 4 9 2 10 3 5 10 10 7 10 7 3\n5 8 4 1 10 2 1 2 4 7 9 1 10\n6 3 10 10 10 1 3 10 4 4 2 10 4\n1 7 5 7 9 9 7 4 1 8 5 4 1\n10 10 9 2 2 6 4 1 5 5 1 9 4\n4 2 5 5 7 8 1 2 6 1 2 4 6\n5 1 10 8 1 1 9 1 2 10 6 7 2\n2 1 2 10 4 7 4 1 4 10 10 4 3\n7 7 5 1 2 1 1 4 8 2 4 8 2\n8 8 8 4 1 1 7 3 1 10 1 4 2\n4 5 1 10 8 8 8 4 10 9 4 10 4\n3 1 10 10 5 7 9 4 2 10 4 8 4", "output": "280\n6 6 7 6" }, { "input": "9\n3 9 6 1 7 6 2 8 4\n5 4 1 1 7 2 7 4 10\n7 9 9 4 6 2 7 2 8\n5 7 7 4 9 5 9 1 3\n7 3 10 2 9 4 2 1 2\n5 8 7 4 6 6 2 2 3\n4 8 4 3 4 2 1 8 10\n5 8 2 8 4 4 7 5 4\n2 8 7 4 3 6 10 8 1", "output": "181\n5 4 6 4" } ]
1,644,320,529
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
2,457,600
import itertools from sys import maxsize, stdout, stdin,stderr mod = int(1e9+7) import sys from collections import defaultdict, Counter, deque import math import heapq from heapq import heappop , heappush import bisect from math import factorial, inf from itertools import groupby from itertools import permutations as comb def ask(a,b,c): print('? {} {} {}'.format(a,b,c),flush=True) n=int(input()) return n t=1 # t=int(input()) for _ in range(t): n=int(input()) s=[] d1=[0]*(2*n) d2=[0]*(2*n) for i in range(n): s.append(list(map(int,input().split()))) o,e=-1,-1 x1,y1,x2,y2=None,None,None,None for i in range(n): for j in range(n): d1[i+j] += s[i][j] d2[i-j+n] += s[i][j] for i in range(n): for j in range(n): if (i+j)%2: if o<d1[i+j]+d2[i-j+n]-s[i][j]: o=d1[i+j]+d2[i-j+n]-s[i][j] x1,y1=i+1,j+1 else: if e<d1[i+j]+d2[i-j+n]-s[i][j]: e=d1[i+j]+d2[i-j+n]-s[i][j] x2,y2=i+1,j+1 print(o+e) print(x1,y2,x2,y2)
Title: Gargari and Bishops Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard. Output Specification: On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right. If there are several optimal solutions, you can print any of them. Demo Input: ['4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n'] Demo Output: ['12\n2 2 3 2\n'] Note: none
```python import itertools from sys import maxsize, stdout, stdin,stderr mod = int(1e9+7) import sys from collections import defaultdict, Counter, deque import math import heapq from heapq import heappop , heappush import bisect from math import factorial, inf from itertools import groupby from itertools import permutations as comb def ask(a,b,c): print('? {} {} {}'.format(a,b,c),flush=True) n=int(input()) return n t=1 # t=int(input()) for _ in range(t): n=int(input()) s=[] d1=[0]*(2*n) d2=[0]*(2*n) for i in range(n): s.append(list(map(int,input().split()))) o,e=-1,-1 x1,y1,x2,y2=None,None,None,None for i in range(n): for j in range(n): d1[i+j] += s[i][j] d2[i-j+n] += s[i][j] for i in range(n): for j in range(n): if (i+j)%2: if o<d1[i+j]+d2[i-j+n]-s[i][j]: o=d1[i+j]+d2[i-j+n]-s[i][j] x1,y1=i+1,j+1 else: if e<d1[i+j]+d2[i-j+n]-s[i][j]: e=d1[i+j]+d2[i-j+n]-s[i][j] x2,y2=i+1,j+1 print(o+e) print(x1,y2,x2,y2) ```
0
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10000", "output": "10800100" }, { "input": "2333", "output": "310060" }, { "input": "9139", "output": "10134010" }, { "input": "9859", "output": "10422001" }, { "input": "5987", "output": "2221201" }, { "input": "3", "output": "37" }, { "input": "4", "output": "46" }, { "input": "5", "output": "55" }, { "input": "7", "output": "73" }, { "input": "9", "output": "91" }, { "input": "10", "output": "109" }, { "input": "15", "output": "154" }, { "input": "51", "output": "613" }, { "input": "99", "output": "1414" }, { "input": "138", "output": "2224" }, { "input": "233", "output": "5050" }, { "input": "666", "output": "27100" }, { "input": "1234", "output": "110206" }, { "input": "3567", "output": "1033003" }, { "input": "4445", "output": "1221301" }, { "input": "5689", "output": "2114002" }, { "input": "6666", "output": "3102004" }, { "input": "7777", "output": "5300200" }, { "input": "8888", "output": "10110061" }, { "input": "9411", "output": "10214200" }, { "input": "5539", "output": "2101114" }, { "input": "6259", "output": "2511100" }, { "input": "2387", "output": "312220" }, { "input": "8515", "output": "10030114" } ]
1,671,961,365
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n=int(input()) k=0 if n>=10: print(19+(9*n))
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). Output Specification: A single number, denoting the $k$-th smallest perfect integer. Demo Input: ['1\n', '2\n'] Demo Output: ['19\n', '28\n'] Note: The first perfect integer is $19$ and the second one is $28$.
```python n=int(input()) k=0 if n>=10: print(19+(9*n)) ```
0
23
B
Party
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "math" ]
B. Party
2
256
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end?
The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
[ "1\n3\n" ]
[ "1\n" ]
none
0
[ { "input": "1\n3", "output": "1" } ]
1,641,379,850
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
1
2,000
8,192,000
t = int(input()) for _ in range(t): print(max(0, int(input()) - 2))
Title: Party Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end? Input Specification: The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105). Output Specification: For each test output in a separate line one number — the maximum amount of people that could stay in the end. Demo Input: ['1\n3\n'] Demo Output: ['1\n'] Note: none
```python t = int(input()) for _ in range(t): print(max(0, int(input()) - 2)) ```
0
349
A
Cinema Line
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
[ "4\n25 25 50 50\n", "2\n25 100\n", "4\n50 50 25 25\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "4\n25 25 50 50", "output": "YES" }, { "input": "2\n25 100", "output": "NO" }, { "input": "4\n50 50 25 25", "output": "NO" }, { "input": "3\n25 50 100", "output": "NO" }, { "input": "10\n25 25 25 25 25 25 25 25 25 25", "output": "YES" }, { "input": "10\n50 50 50 50 50 50 50 50 50 50", "output": "NO" }, { "input": "10\n100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "7\n25 25 25 25 50 100 50", "output": "YES" }, { "input": "2\n25 25", "output": "YES" }, { "input": "3\n50 100 100", "output": "NO" }, { "input": "3\n25 50 50", "output": "NO" }, { "input": "2\n50 25", "output": "NO" }, { "input": "14\n25 25 25 25 25 25 25 50 50 50 100 100 100 100", "output": "NO" }, { "input": "5\n25 25 25 100 100", "output": "NO" }, { "input": "7\n25 50 25 50 25 50 100", "output": "NO" }, { "input": "5\n25 50 25 50 100", "output": "NO" }, { "input": "5\n25 25 50 50 50", "output": "NO" }, { "input": "5\n25 25 50 100 50", "output": "NO" }, { "input": "5\n25 25 50 50 100", "output": "NO" }, { "input": "1\n50", "output": "NO" } ]
1,645,098,583
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
24
2,000
14,540,800
n=int(input()) l=list(map(int,input().split())) change=[] ans="YES" for i in range(n): if(l[i]==25): change.append(25) elif(l[i]==50): if(25 in change): change.append(50) change.remove(25) else: ans="NO" break else: if(25 in change and 50 in change): change.remove(25) change.remove(50) elif(change.count(25)>=3): change.append(100) change.remove(25) change.remove(25) change.remove(25) else: ans="NO" break print(ans)
Title: Cinema Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Specification: Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Demo Input: ['4\n25 25 50 50\n', '2\n25 100\n', '4\n50 50 25 25\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python n=int(input()) l=list(map(int,input().split())) change=[] ans="YES" for i in range(n): if(l[i]==25): change.append(25) elif(l[i]==50): if(25 in change): change.append(50) change.remove(25) else: ans="NO" break else: if(25 in change and 50 in change): change.remove(25) change.remove(50) elif(change.count(25)>=3): change.append(100) change.remove(25) change.remove(25) change.remove(25) else: ans="NO" break print(ans) ```
0
415
B
Mashmokh and Tokens
PROGRAMMING
1,500
[ "binary search", "greedy", "implementation", "math" ]
null
null
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save.
The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109).
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
[ "5 1 4\n12 6 11 9 1\n", "3 1 2\n1 2 3\n", "1 1 1\n1\n" ]
[ "0 2 3 1 1 ", "1 0 1 ", "0 " ]
none
1,000
[ { "input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1 " }, { "input": "3 1 2\n1 2 3", "output": "1 0 1 " }, { "input": "1 1 1\n1", "output": "0 " }, { "input": "1 1 1000000000\n1000000000", "output": "0 " }, { "input": "1 1 1000000000\n999999999", "output": "999999999 " }, { "input": "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999", "output": "99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 " } ]
1,585,900,613
2,147,483,647
PyPy 3
OK
TESTS
47
326
12,800,000
import math n,a,b=map(int,input().split()) arr = list(map(int,input().split())) for i in range(n): x=(math.floor(arr[i]*a/b)) arr[i]-=(math.ceil(x*b/a)) print(*arr)
Title: Mashmokh and Tokens Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save. Input Specification: The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). Output Specification: Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. Demo Input: ['5 1 4\n12 6 11 9 1\n', '3 1 2\n1 2 3\n', '1 1 1\n1\n'] Demo Output: ['0 2 3 1 1 ', '1 0 1 ', '0 '] Note: none
```python import math n,a,b=map(int,input().split()) arr = list(map(int,input().split())) for i in range(n): x=(math.floor(arr[i]*a/b)) arr[i]-=(math.ceil(x*b/a)) print(*arr) ```
3
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,628,843,897
2,147,483,647
Python 3
OK
TESTS
102
77
6,758,400
line1 = input() line2 = input() output = [] for i in range(0,len(line1)): if line1[i] == line2[i]: output.append(0) else: output.append(1) print(int(output[i]),end = "")
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python line1 = input() line2 = input() output = [] for i in range(0,len(line1)): if line1[i] == line2[i]: output.append(0) else: output.append(1) print(int(output[i]),end = "") ```
3.968161
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,642,086,367
667
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
import sys input = sys.stdin.buffer.readline def process(n): S = n*(n+1)//2 A = [i+1 for i in range(n+1)] goal = S//2 curr = 0 A2 = [] while len(A) > 0: x = A.pop() if x+curr <= goal: A2.append(x) curr+=x c2 = S-curr return [abs(curr-c2), A2] n = int(input()) answer = [int(x) for x in input().split()] a1, a2 = process(n) print(a1) sys.stdout.write(' '.join(map(str, a2))+'\n')
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 import sys input = sys.stdin.buffer.readline def process(n): S = n*(n+1)//2 A = [i+1 for i in range(n+1)] goal = S//2 curr = 0 A2 = [] while len(A) > 0: x = A.pop() if x+curr <= goal: A2.append(x) curr+=x c2 = S-curr return [abs(curr-c2), A2] n = int(input()) answer = [int(x) for x in input().split()] a1, a2 = process(n) print(a1) sys.stdout.write(' '.join(map(str, a2))+'\n') ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,634,821,185
2,147,483,647
Python 3
OK
TESTS
35
92
4,300,800
height, width = map(int, input().split()) print(int ((height * width) / 2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python height, width = map(int, input().split()) print(int ((height * width) / 2)) ```
3.968989
955
C
Sad powers
PROGRAMMING
2,100
[ "binary search", "math", "number theory" ]
null
null
You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*.
The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018).
Output *Q* lines — the answers to the queries.
[ "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n" ]
[ "2\n1\n0\n3\n17\n1111\n" ]
In query one the suitable numbers are 1 and 4.
1,500
[ { "input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000", "output": "2\n1\n0\n3\n17\n1111" }, { "input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770", "output": "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n6\n4\n4\n15\n26\n2\n2\n4" } ]
1,521,831,875
8,975
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
0
2,000
49,664,000
a=[1] for i in range(3,31): num=2 while(num**i<1+10**18): a.append(num**i) num+=1 # print(a) b=sorted(a) import math def is_square(integer): root = math.sqrt(integer) if int(root + 0.5) ** 2 == integer: return True else: return False c=[x for x in b if not is_square(x)] import math def CountSquares(a,b): return (math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1) def findClosest(arr, n, target): # Corner cases if (target <= arr[0]): return 0 if (target >= arr[n - 1]): return n - 1 # Doing binary search i = 0; j = n; mid = 0 while (i < j): mid = (i + j) // 2 if (arr[mid] == target): return mid # If target is less than array # element, then search in left if (target < arr[mid]) : # If target is greater than previous # to mid, return closest of two if (mid > 0 and target > arr[mid - 1]): return getClosest(arr,mid - 1, mid, target) # Repeat for left half j = mid # If target is greater than mid else : if (mid < n - 1 and target < arr[mid + 1]): return getClosest(arr,mid, mid + 1, target) # update i i = mid + 1 # Only single element left after search return mid # Method to compare which one is the more close. # We find the closest by taking the difference # between the target and both values. It assumes # that val2 is greater than val1 and target lies # between these two. def getClosest(arr,val1, val2, target): if (target - arr[val1] >= arr[val2] - target): return val2 else: return val1 nn=int(input()) for i in range(nn): a,b=list(map(int,input().split(' '))) count = CountSquares(a,b) # Driver code n = len(c) a1=findClosest(c, n, a) a2=findClosest(c, n, b) # print(a1,a2) count+=a2-a1+1 if a>c[a1]: count-=1 if b<c[a2]: count+=1 if is_square(a): count-=1 if is_square(b): count-=1 if is_square(a) and is_square(b) and a==b: count+=2 if a<c[0]: count-=1 if b<c[0]: count-=1 # if a not in c and b not in c: # count-=1 # print(findClosest(arr, n, target)) print(count)
Title: Sad powers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*. Input Specification: The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). Output Specification: Output *Q* lines — the answers to the queries. Demo Input: ['6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n'] Demo Output: ['2\n1\n0\n3\n17\n1111\n'] Note: In query one the suitable numbers are 1 and 4.
```python a=[1] for i in range(3,31): num=2 while(num**i<1+10**18): a.append(num**i) num+=1 # print(a) b=sorted(a) import math def is_square(integer): root = math.sqrt(integer) if int(root + 0.5) ** 2 == integer: return True else: return False c=[x for x in b if not is_square(x)] import math def CountSquares(a,b): return (math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1) def findClosest(arr, n, target): # Corner cases if (target <= arr[0]): return 0 if (target >= arr[n - 1]): return n - 1 # Doing binary search i = 0; j = n; mid = 0 while (i < j): mid = (i + j) // 2 if (arr[mid] == target): return mid # If target is less than array # element, then search in left if (target < arr[mid]) : # If target is greater than previous # to mid, return closest of two if (mid > 0 and target > arr[mid - 1]): return getClosest(arr,mid - 1, mid, target) # Repeat for left half j = mid # If target is greater than mid else : if (mid < n - 1 and target < arr[mid + 1]): return getClosest(arr,mid, mid + 1, target) # update i i = mid + 1 # Only single element left after search return mid # Method to compare which one is the more close. # We find the closest by taking the difference # between the target and both values. It assumes # that val2 is greater than val1 and target lies # between these two. def getClosest(arr,val1, val2, target): if (target - arr[val1] >= arr[val2] - target): return val2 else: return val1 nn=int(input()) for i in range(nn): a,b=list(map(int,input().split(' '))) count = CountSquares(a,b) # Driver code n = len(c) a1=findClosest(c, n, a) a2=findClosest(c, n, b) # print(a1,a2) count+=a2-a1+1 if a>c[a1]: count-=1 if b<c[a2]: count+=1 if is_square(a): count-=1 if is_square(b): count-=1 if is_square(a) and is_square(b) and a==b: count+=2 if a<c[0]: count-=1 if b<c[0]: count-=1 # if a not in c and b not in c: # count-=1 # print(findClosest(arr, n, target)) print(count) ```
0
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "input": "6 5\naaccdd", "output": "d" }, { "input": "2 1\nzz", "output": "z" }, { "input": "14 5\nhxehmvkybeklnj", "output": "xmvkyklnj" } ]
1,686,331,453
2,147,483,647
PyPy 3-64
OK
TESTS
44
77
6,860,800
n,k=map(int,input().split()) s=input() for j in range(ord('a'), ord('z') + 1): i=len(s) s=s.replace(chr(j), "",k) j=len(s) k-=(i-j) if k==0: break print(s)
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string. Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters. Output Specification: Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Demo Input: ['15 3\ncccaabababaccbc\n', '15 9\ncccaabababaccbc\n', '1 1\nu\n'] Demo Output: ['cccbbabaccbc\n', 'cccccc\n', ''] Note: none
```python n,k=map(int,input().split()) s=input() for j in range(ord('a'), ord('z') + 1): i=len(s) s=s.replace(chr(j), "",k) j=len(s) k-=(i-j) if k==0: break print(s) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,674,393,042
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n = input() a = 0 for z in n : a += 1 if a > 9 : print(f'{n[0]}{a-2}{n[-1]}') else : print(n)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n = input() a = 0 for z in n : a += 1 if a > 9 : print(f'{n[0]}{a-2}{n[-1]}') else : print(n) ```
0
339
B
Xenia and Ringroad
PROGRAMMING
1,000
[ "implementation" ]
null
null
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete the *i*-th task, she needs to be in the house number *a**i* and complete all tasks with numbers less than *i*. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house.
Print a single integer — the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n3 2 3\n", "4 3\n2 3 3\n" ]
[ "6\n", "2\n" ]
In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
1,000
[ { "input": "4 3\n3 2 3", "output": "6" }, { "input": "4 3\n2 3 3", "output": "2" }, { "input": "2 2\n1 1", "output": "0" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "100 100\n56 46 1 47 5 86 45 35 81 1 31 70 67 70 62 99 100 47 44 33 78 35 32 37 92 12 95 18 3 22 54 24 22 90 25 22 78 88 51 92 46 84 15 29 28 40 8 5 93 68 77 47 45 76 85 39 84 94 52 69 93 64 31 60 99 17 51 59 62 37 46 47 86 60 88 14 68 22 47 93 50 10 55 87 46 50 43 63 44 43 61 65 91 43 33 97 67 57 66 70", "output": "4869" }, { "input": "78 58\n23 14 73 45 47 14 27 59 65 39 15 23 5 1 50 37 3 51 46 69 75 65 45 68 48 59 77 39 53 21 72 33 46 32 34 5 69 55 56 53 47 31 32 5 42 23 76 15 2 77 65 24 16 68 61 28 55 10", "output": "2505" }, { "input": "14 54\n9 13 14 9 5 12 4 7 3 14 5 12 13 1 1 11 10 2 7 9 5 2 2 8 10 7 3 9 5 11 2 2 6 12 11 5 4 11 11 6 2 11 14 13 8 7 13 9 4 9 11 3 7 13", "output": "362" }, { "input": "100 100\n48 73 63 16 49 88 36 17 66 6 87 13 94 52 58 70 71 52 7 70 25 42 24 36 57 9 79 26 75 39 13 14 38 26 33 66 88 28 75 98 53 48 67 54 63 25 69 87 88 32 72 17 36 35 29 67 74 89 70 47 20 90 78 13 94 57 32 73 29 74 45 78 85 64 81 56 12 65 19 67 34 86 55 71 41 33 76 13 100 47 44 76 86 78 37 15 26 98 83 98", "output": "4997" }, { "input": "99 100\n88 65 10 91 18 35 58 49 42 2 22 57 74 31 53 24 27 93 45 4 71 2 69 39 21 90 97 89 45 73 20 45 82 98 35 90 37 76 68 26 21 65 95 63 24 74 50 59 3 93 65 6 30 37 62 71 18 88 40 12 56 40 89 56 38 71 90 41 97 43 44 23 19 22 10 80 3 24 32 85 26 65 70 60 76 85 66 68 74 11 64 88 12 63 16 15 79 57 93 58", "output": "4809" }, { "input": "65 100\n53 14 5 10 32 60 31 52 52 56 38 6 8 17 52 23 59 3 18 28 15 2 46 26 8 2 40 6 58 30 28 46 49 23 47 24 9 53 3 47 55 12 36 49 12 24 54 55 58 7 50 42 15 4 58 49 34 40 19 4 59 19 31 17 35 65 36 50 45 5 33 11 29 52 55 40 48 11 32 41 31 7 46 55 32 41 56 51 39 13 5 59 58 34 38 50 55 10 43 30", "output": "3149" }, { "input": "10 100\n7 6 2 10 7 2 3 8 10 4 6 1 4 5 7 10 1 2 3 5 4 10 8 2 3 3 6 8 3 9 4 1 9 10 1 2 5 1 8 8 5 9 2 8 1 2 3 2 1 10 10 7 1 3 2 2 7 1 6 6 6 9 2 3 1 7 2 2 9 7 3 3 2 10 7 4 7 3 3 3 2 4 4 2 2 8 4 1 10 10 5 10 6 10 6 10 3 10 8 9", "output": "428" }, { "input": "2 100\n1 1 2 2 2 2 1 2 1 2 2 2 1 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 2 1 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 1 1 2 2 1 2 1 2 2 2 1 1 1 1 1 2 2 2 1 1 2 2 1 1 2 2 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 2", "output": "47" }, { "input": "67 100\n49 5 25 48 37 55 5 33 14 30 59 28 57 46 45 32 47 22 40 28 58 34 27 29 4 52 63 44 31 65 42 61 11 17 32 17 18 1 12 33 38 11 59 46 43 55 23 30 23 2 42 21 45 51 30 19 35 15 10 30 13 21 32 34 33 3 5 59 23 63 6 9 20 43 64 3 42 41 40 4 14 20 40 33 25 44 1 2 50 46 13 10 3 20 22 64 28 42 58 30", "output": "3245" }, { "input": "100 100\n81 62 26 90 7 87 60 35 75 81 54 94 53 71 64 80 58 83 53 70 40 96 87 50 37 63 5 77 83 75 53 28 22 98 52 45 72 70 62 21 1 99 37 93 16 98 68 27 96 37 21 83 92 23 62 96 85 31 85 66 38 77 45 16 90 86 6 21 75 42 18 60 2 17 51 61 94 68 97 79 17 59 66 14 87 78 70 40 63 78 58 22 87 7 90 17 20 97 9 31", "output": "5530" }, { "input": "2 1\n1", "output": "0" }, { "input": "2 10\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "2 10\n1 1 1 2 2 2 1 1 1 2", "output": "3" }, { "input": "3 6\n1 2 3 3 2 1", "output": "6" } ]
1,699,620,678
2,147,483,647
PyPy 3-64
OK
TESTS
29
154
12,185,600
n,m = map(int, input().split(" ")) x=0 work = [int(x) for x in input().split()[:m]] pos=1 for i in range(len(work)): if(pos>work[i]): x+=(n-(pos-work[i])) pos=work[i] else: x+=((work[i]-pos)) pos=work[i] print(x)
Title: Xenia and Ringroad Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete the *i*-th task, she needs to be in the house number *a**i* and complete all tasks with numbers less than *i*. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time. Input Specification: The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house. Output Specification: Print a single integer — the time Xenia needs to complete all tasks. Please, do not use 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: ['4 3\n3 2 3\n', '4 3\n2 3 3\n'] Demo Output: ['6\n', '2\n'] Note: In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
```python n,m = map(int, input().split(" ")) x=0 work = [int(x) for x in input().split()[:m]] pos=1 for i in range(len(work)): if(pos>work[i]): x+=(n-(pos-work[i])) pos=work[i] else: x+=((work[i]-pos)) pos=work[i] print(x) ```
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
1,668,449,389
2,147,483,647
Python 3
OK
TESTS
45
184
0
def is_prime(n): return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1)) n, m = map(int, input().split()) next_prime = n + 1 while not is_prime(next_prime): next_prime += 1 print("YES" if next_prime == m else "NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python def is_prime(n): return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1)) n, m = map(int, input().split()) next_prime = n + 1 while not is_prime(next_prime): next_prime += 1 print("YES" if next_prime == m else "NO") ```
3.954
44
A
Indian Summer
PROGRAMMING
900
[ "implementation" ]
A. Indian Summer
2
256
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output the single number — the number of Alyona's leaves.
[ "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n", "3\noak yellow\noak yellow\noak yellow\n" ]
[ "4\n", "1\n" ]
none
0
[ { "input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4" }, { "input": "3\noak yellow\noak yellow\noak yellow", "output": "1" }, { "input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae", "output": "5" }, { "input": "1\nqvwli hz", "output": "1" }, { "input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab", "output": "2" }, { "input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded", "output": "3" }, { "input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw", "output": "1" }, { "input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp", "output": "2" }, { "input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb", "output": "13" }, { "input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux", "output": "15" }, { "input": "2\nab ab\na bab", "output": "2" } ]
1,648,745,376
2,147,483,647
Python 3
OK
TESTS
29
92
0
n = int(input()) mySet = set(()) for i in range(n): s = input() mySet.add(s) print(len(mySet))
Title: Indian Summer Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Specification: Output the single number — the number of Alyona's leaves. Demo Input: ['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n'] Demo Output: ['4\n', '1\n'] Note: none
```python n = int(input()) mySet = set(()) for i in range(n): s = input() mySet.add(s) print(len(mySet)) ```
3.977
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
1,639,472,839
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
11,776,000
a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())) def p(i,x): for j in b: if j<=i: x+=1 return x for k in c: print(p(k,0),end=' ')
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). Output Specification: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Demo Input: ['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n'] Demo Output: ['3 2 1 4\n', '4 2 4 2 5\n'] Note: none
```python a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())) def p(i,x): for j in b: if j<=i: x+=1 return x for k in c: print(p(k,0),end=' ') ```
0
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter.
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "output": "25" }, { "input": "10 90\n24 27 40 41 61 69 73 87 95 97", "output": "120" }, { "input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99", "output": "79351" }, { "input": "1 14751211\n847188590", "output": "0" }, { "input": "2 1000000000\n-907894512 -289906312", "output": "0" }, { "input": "2 1000000000\n-14348867 1760823", "output": "0" }, { "input": "3 1000000000\n-5 -1 1", "output": "1" } ]
1,597,716,831
2,147,483,647
PyPy 3
OK
TESTS
39
466
10,444,800
import sys input = sys.stdin.readline def inInt(): return int(input()) def inStr(): return input().strip("\n") def inIList(): return(list(map(int,input().split()))) def inSList(): return(input().split()) def solve(case, d): ans = 0 j = 0 for i in range(len(case)): while case[i] - case[j] > d:j += 1 ans += int((i - j) * (i - j - 1)/2) print(ans) nums = inIList() case = inIList() solve(case, nums[1])
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter. Input Specification: The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase. Output Specification: Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use 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: ['4 3\n1 2 3 4\n', '4 2\n-3 -2 -1 0\n', '5 19\n1 10 20 30 50\n'] Demo Output: ['4\n', '2\n', '1\n'] Note: In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
```python import sys input = sys.stdin.readline def inInt(): return int(input()) def inStr(): return input().strip("\n") def inIList(): return(list(map(int,input().split()))) def inSList(): return(input().split()) def solve(case, d): ans = 0 j = 0 for i in range(len(case)): while case[i] - case[j] > d:j += 1 ans += int((i - j) * (i - j - 1)/2) print(ans) nums = inIList() case = inIList() solve(case, nums[1]) ```
3
0
none
none
none
0
[ "none" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
0
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" }, { "input": "680 1091", "output": "351905328" }, { "input": "1229 1315", "output": "100240813" }, { "input": "1766 1038", "output": "435768250" }, { "input": "1000 1", "output": "1000" }, { "input": "2000 100", "output": "983281065" }, { "input": "1 1", "output": "1" }, { "input": "2000 1000", "output": "228299266" }, { "input": "1928 1504", "output": "81660104" }, { "input": "2000 2000", "output": "585712681" }, { "input": "29 99", "output": "23125873" }, { "input": "56 48", "output": "20742237" }, { "input": "209 370", "output": "804680894" }, { "input": "83 37", "output": "22793555" }, { "input": "49 110", "output": "956247348" }, { "input": "217 3", "output": "4131" }, { "input": "162 161", "output": "591739753" }, { "input": "273 871", "output": "151578252" }, { "input": "43 1640", "output": "173064407" }, { "input": "1472 854", "output": "748682383" }, { "input": "1639 1056", "output": "467464129" }, { "input": "359 896", "output": "770361185" }, { "input": "1544 648", "output": "9278889" }, { "input": "436 1302", "output": "874366220" }, { "input": "1858 743", "output": "785912917" }, { "input": "991 1094", "output": "483493131" }, { "input": "1013 1550", "output": "613533467" }, { "input": "675 741", "output": "474968598" }, { "input": "1420 1223", "output": "922677437" }, { "input": "1544 1794", "output": "933285446" }, { "input": "1903 1612", "output": "620810276" }, { "input": "500 1304", "output": "706176027" }, { "input": "525 314", "output": "245394744" }, { "input": "39 1930", "output": "992125404" }, { "input": "1895 753", "output": "180474828" }, { "input": "1722 1474", "output": "742424590" }, { "input": "1153 1823", "output": "791493066" }, { "input": "1409 734", "output": "627413973" }, { "input": "478 1301", "output": "476483030" }, { "input": "1887 1729", "output": "730033374" }, { "input": "1610 774", "output": "50897314" }, { "input": "1770 679", "output": "235295539" }, { "input": "987 1292", "output": "560110556" }, { "input": "1707 1117", "output": "237674323" }, { "input": "1424 1431", "output": "184145444" }, { "input": "86 1078", "output": "252515343" }, { "input": "1066 995", "output": "180753612" }, { "input": "1024 133", "output": "392603027" }, { "input": "659 974", "output": "397026719" }, { "input": "1349 1606", "output": "522392901" }, { "input": "473 211", "output": "809550224" }, { "input": "634 1825", "output": "438513382" }, { "input": "22 373", "output": "907321755" }, { "input": "531 147", "output": "242883376" }, { "input": "1307 1247", "output": "21512331" }, { "input": "415 735", "output": "393705804" }, { "input": "1659 1501", "output": "225266660" }, { "input": "1454 296", "output": "750032659" }, { "input": "158 772", "output": "850911301" }, { "input": "2000 1", "output": "2000" } ]
1,617,822,950
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
3,584,000
def mlt(): return map(int, input().split()) x, y = mlt() divs = [[] for _ in range(x+1)] for n in range(1, x+1): for k in range(n, x+1, n): divs[k].append(n) dp = [[0 for n in range(y+1)] for k in range(x+1)] for n in range(1, y+1): dp[1][n] = 1 for n in range(1, x+1): dp[n][1] = 1 mod = int(1e9 + 7) for n in range(2, x+1): for k in range(2, y+1): for dv in divs[n]: dp[n][k] += dp[dv][k-1] dp[n][k] %= mod res = 0 for n in dp: res += n[-1] print(res)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7). Input Specification: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). Output Specification: Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). Demo Input: ['3 2\n', '6 4\n', '2 1\n'] Demo Output: ['5\n', '39\n', '2\n'] Note: In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
```python def mlt(): return map(int, input().split()) x, y = mlt() divs = [[] for _ in range(x+1)] for n in range(1, x+1): for k in range(n, x+1, n): divs[k].append(n) dp = [[0 for n in range(y+1)] for k in range(x+1)] for n in range(1, y+1): dp[1][n] = 1 for n in range(1, x+1): dp[n][1] = 1 mod = int(1e9 + 7) for n in range(2, x+1): for k in range(2, y+1): for dv in divs[n]: dp[n][k] += dp[dv][k-1] dp[n][k] %= mod res = 0 for n in dp: res += n[-1] print(res) ```
0
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10", "output": "3" }, { "input": "1\n01", "output": "1" }, { "input": "2\n01\n01", "output": "1" }, { "input": "2\n10\n01", "output": "2" }, { "input": "3\n01\n01\n01", "output": "1" }, { "input": "3\n10\n10\n01", "output": "2" }, { "input": "3\n01\n10\n10", "output": "2" }, { "input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10", "output": "55" } ]
1,691,149,272
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n = int(input()) a = list(map(int, input().split())) count = 1 temp = a[0] for i in a: if i != temp: count +=1 temp = i print(count)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. Output Specification: On the single line of the output print the number of groups of magnets. Demo Input: ['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n'] Demo Output: ['3\n', '2\n'] Note: The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
```python n = int(input()) a = list(map(int, input().split())) count = 1 temp = a[0] for i in a: if i != temp: count +=1 temp = i print(count) ```
0
18
C
Stripe
PROGRAMMING
1,200
[ "data structures", "implementation" ]
C. Stripe
2
64
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
[ "9\n1 5 -6 7 9 -16 0 -2 2\n", "3\n1 1 1\n", "2\n0 0\n" ]
[ "3\n", "0\n", "1\n" ]
none
0
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2", "output": "3" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "4\n100 1 10 111", "output": "1" }, { "input": "10\n0 4 -3 0 -2 2 -3 -3 2 5", "output": "3" }, { "input": "10\n0 -1 2 2 -1 1 0 0 0 2", "output": "0" }, { "input": "10\n-1 -1 1 -1 0 1 0 1 1 1", "output": "1" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "9" }, { "input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3", "output": "3" }, { "input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3", "output": "0" }, { "input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2", "output": "0" }, { "input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2", "output": "1" }, { "input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2", "output": "6" }, { "input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n10000", "output": "0" }, { "input": "1\n-10000", "output": "0" } ]
1,671,909,417
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
60
0
# Wadea # s = int(input()) m = list(map(int, input().split())) r = 0 k = 0 for j in range(len(m)): r += m[j] if r == sum(m[j:]): k = j break if k >= 0: if k > int(s / 2): print(s-j) else: print(s-j) else: print("0")
Title: Stripe Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem? Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. Output Specification: Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. Demo Input: ['9\n1 5 -6 7 9 -16 0 -2 2\n', '3\n1 1 1\n', '2\n0 0\n'] Demo Output: ['3\n', '0\n', '1\n'] Note: none
```python # Wadea # s = int(input()) m = list(map(int, input().split())) r = 0 k = 0 for j in range(len(m)): r += m[j] if r == sum(m[j:]): k = j break if k >= 0: if k > int(s / 2): print(s-j) else: print(s-j) else: print("0") ```
0
919
D
Substring
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs" ]
null
null
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
[ "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n" ]
[ "3\n", "-1\n", "4\n" ]
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
1,500
[ { "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "output": "3" }, { "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "output": "-1" }, { "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7", "output": "4" }, { "input": "1 1\nf\n1 1", "output": "-1" }, { "input": "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\n1 10\n3 7\n1 8\n3 10\n8 6\n1 7\n10 6\n1 6\n5 8\n1 5\n2 10\n3 9\n5 8\n8 3\n3 7\n5 2\n1 10\n1 4\n5 3\n3 2\n1 2\n5 8\n10 4\n2 10\n8 2\n1 9\n1 8\n1 2\n3 4\n1 8", "output": "2" }, { "input": "13 37\ndwpzcppjmhkmz\n2 6\n3 6\n6 7\n6 7\n6 7\n6 7\n6 8\n6 8\n6 8\n6 8\n4 6\n4 6\n5 6\n4 6\n4 6\n6 9\n6 9\n6 10\n6 10\n6 10\n6 10\n4 6\n1 6\n1 6\n10 11\n6 11\n1 6\n6 12\n6 12\n6 12\n6 13\n6 13\n6 13\n6 13\n3 6\n2 6\n2 6", "output": "3" }, { "input": "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1", "output": "-1" }, { "input": "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4", "output": "-1" } ]
1,623,264,005
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
3,000
129,843,200
# J A I S H R E E R A M # import math, sys, collections, functools, time, itertools; # sys.setrecursionlimit(10**6) def Read_Ints() : return map(int, input().strip().split()) def Read_Array() : return list(Read_Ints()) def Read_Strings() : return list(input().strip().split()) def printxsp(*args) : return print(*args, end="") def printsp(*args) : return print(*args, end=" ") d4i = [-1, +0, +1, +0]; d8i = [-1, -1, +0, +1, +1, +1, +0, -1]; d4j = [+0, +1, +0, -1]; d8j = [+0, +1, +1, +1, +0, -1, -1, -1]; # >>>>>>--->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> def solveEachTest(_TestCase): # printsp("Case #{}: ".format(_TestCase)) n, m = Read_Ints() adj = collections.defaultdict(list) indeg = [0 for x in range(n+1)] s = input(); for i in range(m): a, b = Read_Ints() adj[a].append(b); indeg[b] += 1; que = collections.deque(); ans = 0; dp = [[0 for x in range(26)] for xx in range(n+1)] indegCopy = indeg.copy() for j in range(26): ch = chr(ord('a') + j) indeg = indegCopy.copy() for i in range(1, n+1): if indeg[i] == 0: que.append(i) dp[i][j] = s[i-1] == ch cnt = 0 while (len(que)): node = que.popleft() for i in adj[node]: dp[i][j] = dp[node][j] + (s[i-1] == ch); ans = max(ans, dp[i][j]) indeg[i] -= 1 if indeg[i] == 0: que.append(i) cnt += 1 if cnt > n: break if cnt > n: break # print(cnt) print(ans if cnt == n else -1) _T0T4 = 1; # _T0T4 = int(input()) for _TestCase in range(1, _T0T4 + 1): solveEachTest(_TestCase) # Udit "luctivud" Gupta # linkedin : https://www.linkedin.com/in/udit-gupta-1b7863135/
Title: Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest. Input Specification: The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected. Output Specification: Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead. Demo Input: ['5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n', '6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n', '10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n'] Demo Output: ['3\n', '-1\n', '4\n'] Note: In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
```python # J A I S H R E E R A M # import math, sys, collections, functools, time, itertools; # sys.setrecursionlimit(10**6) def Read_Ints() : return map(int, input().strip().split()) def Read_Array() : return list(Read_Ints()) def Read_Strings() : return list(input().strip().split()) def printxsp(*args) : return print(*args, end="") def printsp(*args) : return print(*args, end=" ") d4i = [-1, +0, +1, +0]; d8i = [-1, -1, +0, +1, +1, +1, +0, -1]; d4j = [+0, +1, +0, -1]; d8j = [+0, +1, +1, +1, +0, -1, -1, -1]; # >>>>>>--->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> def solveEachTest(_TestCase): # printsp("Case #{}: ".format(_TestCase)) n, m = Read_Ints() adj = collections.defaultdict(list) indeg = [0 for x in range(n+1)] s = input(); for i in range(m): a, b = Read_Ints() adj[a].append(b); indeg[b] += 1; que = collections.deque(); ans = 0; dp = [[0 for x in range(26)] for xx in range(n+1)] indegCopy = indeg.copy() for j in range(26): ch = chr(ord('a') + j) indeg = indegCopy.copy() for i in range(1, n+1): if indeg[i] == 0: que.append(i) dp[i][j] = s[i-1] == ch cnt = 0 while (len(que)): node = que.popleft() for i in adj[node]: dp[i][j] = dp[node][j] + (s[i-1] == ch); ans = max(ans, dp[i][j]) indeg[i] -= 1 if indeg[i] == 0: que.append(i) cnt += 1 if cnt > n: break if cnt > n: break # print(cnt) print(ans if cnt == n else -1) _T0T4 = 1; # _T0T4 = int(input()) for _TestCase in range(1, _T0T4 + 1): solveEachTest(_TestCase) # Udit "luctivud" Gupta # linkedin : https://www.linkedin.com/in/udit-gupta-1b7863135/ ```
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,692,594,764
2,147,483,647
Python 3
OK
TESTS
30
124
0
stroka = input() counter1=0 counter2=0 for char in stroka: if char.isupper(): counter1+=1 else: counter2+=1 if counter2>counter1 or counter1==counter2: stroka = stroka.lower() elif counter1>counter2: stroka=stroka.upper() print(stroka)
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 stroka = input() counter1=0 counter2=0 for char in stroka: if char.isupper(): counter1+=1 else: counter2+=1 if counter2>counter1 or counter1==counter2: stroka = stroka.lower() elif counter1>counter2: stroka=stroka.upper() print(stroka) ```
3.969
462
A
Appleman and Easy Task
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
[ "3\nxxo\nxox\noxx\n", "4\nxxxo\nxoxo\noxox\nxxxx\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "3\nxxo\nxox\noxx", "output": "YES" }, { "input": "4\nxxxo\nxoxo\noxox\nxxxx", "output": "NO" }, { "input": "1\no", "output": "YES" }, { "input": "2\nox\nxo", "output": "YES" }, { "input": "2\nxx\nxo", "output": "NO" }, { "input": "3\nooo\noxo\nxoo", "output": "NO" }, { "input": "3\nxxx\nxxo\nxxo", "output": "NO" }, { "input": "4\nxooo\nooxo\noxoo\nooox", "output": "YES" }, { "input": "4\noooo\noxxo\nxoxo\noooo", "output": "NO" }, { "input": "5\noxoxo\nxxxxx\noxoxo\nxxxxx\noxoxo", "output": "YES" }, { "input": "5\nxxxox\nxxxxo\nxoxox\noxoxx\nxoxxx", "output": "NO" }, { "input": "10\nxoxooooooo\noxxoxxxxxo\nxxooxoooxo\noooxxoxoxo\noxxxooooxo\noxooooxxxo\noxoxoxxooo\noxoooxooxx\noxxxxxoxxo\noooooooxox", "output": "YES" }, { "input": "10\nxxxxxxxoox\nxooxxooooo\noxoooxxooo\nxoxxxxxxxx\nxxoxooxxox\nooxoxxooox\nooxxxxxooo\nxxxxoxooox\nxoxxooxxxx\noooooxxoxo", "output": "NO" }, { "input": "19\noxoxoxoxooxoooxxoox\nxxxxxxxxoxxoxoooooo\noxoxoxooxxxooxxxooo\nxxoxxxooxooxxxoxxox\noxoxooxxxooooxxoxox\nxxxoooxoxxoxxoxxxoo\noxooxxxoooooxxoooxo\nxxooxooxoxxoxxoxxoo\noxxxxooooxxxooooxxx\nooxooxoxxoxxoxooxoo\nxxxooooxxxooooxoxox\noooxoxooxxoxooxooxx\nxxoooxxxooooxxoooxo\nooxxxooxoxooxooxxxx\nxoxoxxooxoxxxooxoxo\nxoxxoxoxooxooxxxxxx\noooxxxooxxxooxoxoxo\nxoooooxoxooxxxxxxxo\nxooxxoooxxoxoxoxoxx", "output": "NO" }, { "input": "12\nxxooxxoxxxoo\nxxoooxoxoxoo\nooxoxoxxooxx\nooxxooooxoxo\nxxxxxxxxoxxx\noxooooxxxooo\noxxoxoxoooxx\nxxxxxxxooxox\noxoooooxoxxx\nxxooxxoxxoxx\noxxxxxxxooxx\nooxoxooxxooo", "output": "NO" }, { "input": "2\noo\nxx", "output": "NO" } ]
1,638,421,897
2,147,483,647
Python 3
OK
TESTS
32
61
0
def solve(n, arr): for i in range(n): for j in range(n): cnt = 0 for x, y in [(-1, 0), (0, 1), (1, 0), (0, -1)]: ni, nj = x + i, y + j if ni >= 0 and ni < n and nj >= 0 and nj < n: if arr[ni][nj] == "o": cnt += 1 if cnt % 2 != 0: return "NO" return "YES" n = int(input()) arr = [] for i in range(n): temp = input() arr.append(list(temp)) print(solve(n, arr))
Title: Appleman and Easy Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. Output Specification: Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Demo Input: ['3\nxxo\nxox\noxx\n', '4\nxxxo\nxoxo\noxox\nxxxx\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python def solve(n, arr): for i in range(n): for j in range(n): cnt = 0 for x, y in [(-1, 0), (0, 1), (1, 0), (0, -1)]: ni, nj = x + i, y + j if ni >= 0 and ni < n and nj >= 0 and nj < n: if arr[ni][nj] == "o": cnt += 1 if cnt % 2 != 0: return "NO" return "YES" n = int(input()) arr = [] for i in range(n): temp = input() arr.append(list(temp)) print(solve(n, arr)) ```
3
784
F
Crunching Numbers Just for You
PROGRAMMING
1,900
[ "*special", "implementation" ]
null
null
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order.
The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100).
Output space-separated elements of the sorted array.
[ "3 3 1 2\n" ]
[ "1 2 3 \n" ]
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
0
[ { "input": "3 3 1 2", "output": "1 2 3 " }, { "input": "10 54 100 27 1 33 27 80 49 27 6", "output": "1 6 27 27 27 33 49 54 80 100 " } ]
1,690,372,154
2,147,483,647
Python 3
REJECTED
TESTS
0
0
0
# LUOGU_RID: 117574442 a=list(map(int,input().split()))[1:] a.sort() print(' '.join(map(str,a)))
Title: Crunching Numbers Just for You Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input Specification: The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). Output Specification: Output space-separated elements of the sorted array. Demo Input: ['3 3 1 2\n'] Demo Output: ['1 2 3 \n'] Note: Remember, this is a very important feature, and you have to make sure the customers appreciate it!
```python # LUOGU_RID: 117574442 a=list(map(int,input().split()))[1:] a.sort() print(' '.join(map(str,a))) ```
-1
834
A
The Useless Toy
PROGRAMMING
900
[ "implementation" ]
null
null
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in. Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
[ "^ &gt;\n1\n", "&lt; ^\n3\n", "^ v\n6\n" ]
[ "cw\n", "ccw\n", "undefined\n" ]
none
500
[ { "input": "^ >\n1", "output": "cw" }, { "input": "< ^\n3", "output": "ccw" }, { "input": "^ v\n6", "output": "undefined" }, { "input": "^ >\n999999999", "output": "ccw" }, { "input": "> v\n1", "output": "cw" }, { "input": "v <\n1", "output": "cw" }, { "input": "< ^\n1", "output": "cw" }, { "input": "v <\n422435957", "output": "cw" }, { "input": "v >\n139018901", "output": "ccw" }, { "input": "v ^\n571728018", "output": "undefined" }, { "input": "^ ^\n0", "output": "undefined" }, { "input": "< >\n2", "output": "undefined" }, { "input": "> >\n1000000000", "output": "undefined" }, { "input": "v v\n8", "output": "undefined" }, { "input": "< <\n1568", "output": "undefined" }, { "input": "^ v\n2", "output": "undefined" }, { "input": "^ <\n1", "output": "ccw" }, { "input": "< v\n1", "output": "ccw" }, { "input": "v >\n1", "output": "ccw" }, { "input": "> ^\n1", "output": "ccw" }, { "input": "v <\n422435957", "output": "cw" }, { "input": "v v\n927162384", "output": "undefined" }, { "input": "v ^\n571728018", "output": "undefined" }, { "input": "^ <\n467441155", "output": "cw" }, { "input": "^ >\n822875521", "output": "cw" }, { "input": "^ <\n821690113", "output": "ccw" }, { "input": "^ <\n171288453", "output": "ccw" }, { "input": "^ <\n110821381", "output": "ccw" }, { "input": "^ ^\n539580280", "output": "undefined" }, { "input": "^ >\n861895563", "output": "ccw" }, { "input": "v v\n4", "output": "undefined" }, { "input": "^ ^\n4", "output": "undefined" }, { "input": "> >\n4", "output": "undefined" }, { "input": "< <\n8", "output": "undefined" }, { "input": "v v\n0", "output": "undefined" }, { "input": "^ <\n11", "output": "cw" }, { "input": "< <\n4", "output": "undefined" }, { "input": "< <\n0", "output": "undefined" }, { "input": "< v\n3", "output": "cw" }, { "input": "^ <\n3", "output": "cw" }, { "input": "^ <\n7", "output": "cw" }, { "input": "< >\n6", "output": "undefined" }, { "input": "v >\n3", "output": "cw" }, { "input": "> >\n300", "output": "undefined" }, { "input": "> >\n0", "output": "undefined" }, { "input": "v <\n3", "output": "ccw" }, { "input": "> >\n12", "output": "undefined" } ]
1,501,427,280
1,980
Python 3
RUNTIME_ERROR
PRETESTS
4
46
4,608,000
c=['^','<','v','>'] d,e=[],[] a,b=map(str,input().split()) n=int(input()) n=n%4 #print(n) if n==2: print('undefined') exit() for i in range(4): if a==c[i]: aa=i if b==c[i]: bb=i #print(c[(aa+n)%4],c[4-(aa+n)%4]) if b==c[(aa+n)%4]: print('ccw') elif b==c[4-(aa+n)%4]: print('cw')
Title: The Useless Toy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in. Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this. Input Specification: There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position. Output Specification: Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. Demo Input: ['^ &gt;\n1\n', '&lt; ^\n3\n', '^ v\n6\n'] Demo Output: ['cw\n', 'ccw\n', 'undefined\n'] Note: none
```python c=['^','<','v','>'] d,e=[],[] a,b=map(str,input().split()) n=int(input()) n=n%4 #print(n) if n==2: print('undefined') exit() for i in range(4): if a==c[i]: aa=i if b==c[i]: bb=i #print(c[(aa+n)%4],c[4-(aa+n)%4]) if b==c[(aa+n)%4]: print('ccw') elif b==c[4-(aa+n)%4]: print('cw') ```
-1
94
A
Restoring Password
PROGRAMMING
900
[ "implementation", "strings" ]
A. Restoring Password
2
256
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
[ "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n" ]
[ "12345678\n", "30234919\n" ]
none
500
[ { "input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "output": "12345678" }, { "input": "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000", "output": "30234919" }, { "input": "00010101101110110101100110101100010101100010101111000101011010011010110010000011\n0101010110\n0001001101\n1001101011\n0000100011\n0010101111\n1110110101\n0001010110\n0110111000\n0000111110\n0010000011", "output": "65264629" }, { "input": "10100100010010010011011001101000100100110110011010011001101011000100110110011010\n1111110011\n1001000111\n1001000100\n1100010011\n0110011010\n0010000001\n1110101110\n0010000110\n0010010011\n1010010001", "output": "98484434" }, { "input": "00101100011111010001001000000110110000000110010011001111111010110010001011000000\n0010000001\n0110010011\n0010000010\n1011001000\n0011111110\n0110001000\n1111010001\n1011000000\n0000100110\n0010110001", "output": "96071437" }, { "input": "10001110111110000001000010001010001110110000100010100010111101101101010000100010\n0000010110\n1101010111\n1000101111\n0001011110\n0011110101\n0101100100\n0110110101\n0000100010\n1000111011\n1110000001", "output": "89787267" }, { "input": "10010100011001010001010101001101010100110100111011001010111100011001000010100000\n0011100000\n1001100100\n0001100100\n0010100000\n0101010011\n0010101110\n0010101111\n0100111011\n1001010001\n1111111110", "output": "88447623" }, { "input": "01101100111000000101011011001110000001011111111000111111100001011010001001011001\n1000000101\n0101101000\n0101110101\n1101011110\n0000101100\n1111111000\n0001001101\n0110111011\n0110110011\n1001011001", "output": "80805519" }, { "input": "11100011000100010110010011101010101010011110001100011010111110011000011010110111\n1110001100\n0110101111\n0100111010\n0101000000\n1001100001\n1010101001\n0000100010\n1010110111\n1100011100\n0100010110", "output": "09250147" }, { "input": "10000110110000010100000010001000111101110110101011110111000100001101000000100010\n0000010100\n0000110001\n0110101011\n1101110001\n1000011011\n0000110100\n0011110111\n1000110010\n0000100010\n0000011011", "output": "40862358" }, { "input": "01000000010000000110100101000110110000100100000001101100001000011111111001010001\n1011000010\n1111101010\n0111110011\n0000000110\n0000001001\n0001111111\n0110010010\n0100000001\n1011001000\n1001010001", "output": "73907059" }, { "input": "01111000111110011001110101110011110000111110010001101100110110100111101011001101\n1110010001\n1001100000\n1100001000\n1010011110\n1011001101\n0111100011\n1101011100\n1110011001\n1111000011\n0010000101", "output": "57680434" }, { "input": "01001100101000100010001011110001000101001001100010010000001001001100101001011111\n1001011111\n1110010111\n0111101011\n1000100010\n0011100101\n0100000010\n0010111100\n0100010100\n1001100010\n0100110010", "output": "93678590" }, { "input": "01110111110000111011101010110110101011010100110111000011101101110101011101001000\n0110000101\n1010101101\n1101010111\n1101011100\n0100110111\n0111011111\n1100011001\n0111010101\n0000111011\n1101001000", "output": "58114879" }, { "input": "11101001111100110101110011010100110011011110100111010110110011000111000011001101\n1100011100\n1100110101\n1011101000\n0011011110\n0011001101\n0100010001\n1110100111\n1010101100\n1110110100\n0101101100", "output": "61146904" }, { "input": "10101010001011010001001001011000100101100001011011101010101110101010001010101000\n0010110101\n1010011010\n1010101000\n1011010001\n1010101011\n0010010110\n0110100010\n1010100101\n0001011011\n0110100001", "output": "23558422" }, { "input": "11110101001100010000110100001110101011011111010100110001000001001010001001101111\n0101101100\n1001101111\n1010101101\n0100101000\n1111110000\n0101010010\n1100010000\n1111010100\n1101000011\n1011111111", "output": "76827631" }, { "input": "10001100110000110111100011001101111110110011110101000011011100001101110000110111\n0011110101\n0101100011\n1000110011\n1011011001\n0111111011\n0101111011\n0000110111\n0100001110\n1000000111\n0110110111", "output": "26240666" }, { "input": "10000100010000111101100100111101111011101000001001100001000110000010010000111101\n1001001111\n0000111101\n1000010001\n0110011101\n0110101000\n1011111001\n0111101110\n1000001001\n1101011111\n0001010100", "output": "21067271" }, { "input": "01101111000110111100011011110001101111001010001100101000110001010101100100000010\n1010001100\n0011010011\n0101010110\n1111001100\n1100011000\n0100101100\n1001100101\n0110111100\n0011001101\n0100000010", "output": "77770029" }, { "input": "10100111011010001011111000000111100000010101000011000010111101010000111010011101\n1010011101\n1010111111\n0110100110\n1111000100\n1110000001\n0000101111\n0011111000\n1000110001\n0101000011\n1010001011", "output": "09448580" }, { "input": "10000111111000011111001010101010010011111001001111000010010100100011000010001100\n1101101110\n1001001111\n0000100101\n1100111010\n0010101010\n1110000110\n1100111101\n0010001100\n1110000001\n1000011111", "output": "99411277" }, { "input": "10110110111011001111101100111100111111011011011011001111110110010011100010000111\n0111010011\n0111101100\n1001101010\n0101000101\n0010000111\n0011111101\n1011001111\n1101111000\n1011011011\n1001001110", "output": "86658594" }, { "input": "01001001100101100011110110111100000110001111001000100000110111110010000000011000\n0100100110\n1000001011\n1000111110\n0000011000\n0101100011\n1101101111\n1111001000\n1011011001\n1000001101\n0010101000", "output": "04536863" }, { "input": "10010100011101000011100100001100101111000010111100000010010000001001001101011101\n1001000011\n1101000011\n1001010001\n1101011101\n1000010110\n0011111101\n0010111100\n0000100100\n1010001000\n0101000110", "output": "21066773" }, { "input": "01111111110101111111011111111111010010000001100000101000100100111001011010001001\n0111111111\n0101111111\n0100101101\n0001100000\n0011000101\n0011100101\n1101001000\n0010111110\n1010001001\n1111000111", "output": "01063858" }, { "input": "00100011111001001010001111000011101000001110100000000100101011101000001001001010\n0010001111\n1001001010\n1010011001\n0011100111\n1000111000\n0011110000\n0000100010\n0001001010\n1111110111\n1110100000", "output": "01599791" }, { "input": "11011101000100110100110011010101100011111010011010010011010010010010100110101111\n0100110100\n1001001010\n0001111101\n1101011010\n1101110100\n1100110101\n0110101111\n0110001111\n0001101000\n1010011010", "output": "40579016" }, { "input": "10000010111101110110011000111110000011100110001111100100000111000011011000001011\n0111010100\n1010110110\n1000001110\n1110000100\n0110001111\n1101110110\n1100001101\n1000001011\n0000000101\n1001000001", "output": "75424967" }, { "input": "11101100101110111110111011111010001111111111000001001001000010001111111110110010\n0101100001\n1111010011\n1110111110\n0100110100\n1110011111\n1000111111\n0010010000\n1110110010\n0011000010\n1111000001", "output": "72259657" }, { "input": "01011110100101111010011000001001100000101001110011010111101011010000110110010101\n0100111100\n0101110011\n0101111010\n0110000010\n0101001111\n1101000011\n0110010101\n0111011010\n0001101110\n1001110011", "output": "22339256" }, { "input": "01100000100101111000100001100010000110000010100100100001100000110011101001110000\n0101111000\n1001110000\n0001000101\n0110110111\n0010100100\n1000011000\n1101110110\n0110000010\n0001011010\n0011001110", "output": "70554591" }, { "input": "11110011011000001001111100110101001000010100100000110011001110011111100100100001\n1010011000\n1111001101\n0100100001\n1111010011\n0100100000\n1001111110\n1010100111\n1000100111\n1000001001\n1100110011", "output": "18124952" }, { "input": "10001001011000100101010110011101011001110010000001010110000101000100101111101010\n0101100001\n1100001100\n1111101010\n1000100101\n0010000001\n0100010010\n0010110110\n0101100111\n0000001110\n1101001110", "output": "33774052" }, { "input": "00110010000111001001001100100010010111101011011110001011111100000101000100000001\n0100000001\n1011011110\n0010111111\n0111100111\n0100111001\n0000010100\n1001011110\n0111001001\n0100010011\n0011001000", "output": "97961250" }, { "input": "01101100001000110101101100101111101110010011010111100011010100010001101000110101\n1001101001\n1000110101\n0110110000\n0111100100\n0011010111\n1110111001\n0001000110\n0000000100\n0001101001\n1011001011", "output": "21954161" }, { "input": "10101110000011010110101011100000101101000110100000101101101101110101000011110010\n0110100000\n1011011011\n0011110010\n0001110110\n0010110100\n1100010010\n0001101011\n1010111000\n0011010110\n0111010100", "output": "78740192" }, { "input": "11000101011100100111010000010001000001001100101100000011000000001100000101011010\n1100010101\n1111101011\n0101011010\n0100000100\n1000110111\n1100100111\n1100101100\n0111001000\n0000110000\n0110011111", "output": "05336882" }, { "input": "11110100010000101110010110001000001011100101100010110011011011111110001100110110\n0101100010\n0100010001\n0000101110\n1100110110\n0101000101\n0011001011\n1111010001\n1000110010\n1111111000\n1010011111", "output": "62020383" }, { "input": "00011001111110000011101011010001010111100110100101000110011111011001100000001100\n0111001101\n0101011110\n0001100111\n1101011111\n1110000011\n0000001100\n0111010001\n1101100110\n1010110100\n0110100101", "output": "24819275" }, { "input": "10111110010011111001001111100101010111010011111001001110101000111110011001111101\n0011111001\n0101011101\n0100001010\n0001110010\n1001111101\n0011101010\n1111001001\n1100100001\n1001101000\n1011111001", "output": "90010504" }, { "input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111", "output": "85948866" }, { "input": "01111100000111110000110010111001111100001001101010110010111010001000101001101010\n0100010101\n1011110101\n1010100100\n1010000001\n1001101010\n0101100110\n1000100010\n0111110000\n1100101110\n0110010110", "output": "77874864" }, { "input": "11100011010000000010011110010111001011111001000111000000001000000000100111100101\n0000000010\n1110001101\n0011010101\n0111100101\n1001000111\n1101001111\n0111010110\n1100101111\n0110000000\n1101101011", "output": "10374003" }, { "input": "01111011100111101110011001000110001111101000111110100100100001011111001011100010\n0110010100\n1100010001\n0111101110\n1001001000\n1010011011\n1000111110\n0010110101\n1011100010\n0101111100\n0110010001", "output": "22955387" }, { "input": "11011010001100000011000100110011010101000110011110110000001100111100001000011111\n0000100010\n1000011111\n1101101000\n0110011110\n0011110000\n1100000011\n0010001100\n0101101000\n0001001100\n1101010100", "output": "25893541" }, { "input": "01011001011111010010101111011001000011001100011101101111011011010011101011110110\n0100001100\n0101100101\n1111111011\n1111010010\n1111101100\n1100011101\n1011000011\n1101001110\n1011110110\n0110001010", "output": "13805878" }, { "input": "11110011011000111111001100111110001111111100000010111100110100110011111111001101\n1111001101\n1001101010\n1100110010\n0011001111\n0001011110\n1000110011\n1000111111\n0110001010\n1001011101\n1100000010", "output": "06369030" }, { "input": "01110011110010000011011001011000001000010110010110011001100001100110001100101000\n0000100001\n0110011000\n1010000010\n1110011101\n0111001111\n1100101000\n0010000011\n0110010000\n1100100101\n0110010110", "output": "46909115" }, { "input": "00001011001111110111111111011111111101110101110100010111010010100101100001010110\n1111110111\n0001010110\n0111011011\n0111000001\n1010010110\n0101110100\n0001000101\n0000111000\n0110100001\n0000101100", "output": "90005541" } ]
1,411,963,199
2,147,483,647
Python 3
OK
TESTS
50
156
0
s = input() a = [] for i in range(10): a.append(input()) p = 0 while(p < 80): for i in range(10): if a[i] == s[p:p+10]: print(i, end='') p += 10 break
Title: Restoring Password Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification. Input Specification: The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. Output Specification: Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. Demo Input: ['01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n', '10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n'] Demo Output: ['12345678\n', '30234919\n'] Note: none
```python s = input() a = [] for i in range(10): a.append(input()) p = 0 while(p < 80): for i in range(10): if a[i] == s[p:p+10]: print(i, end='') p += 10 break ```
3.961
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314", "output": "1762894" }, { "input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585", "output": "2960349" }, { "input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933", "output": "99140444" }, { "input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686", "output": "301124161" }, { "input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495", "output": "30125295" }, { "input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165", "output": "136422" }, { "input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348", "output": "2578628" }, { "input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338", "output": "9168707" }, { "input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657", "output": "144901921" }, { "input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860", "output": "809931" }, { "input": "a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "lol\n3\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "21" } ]
1,621,844,619
2,147,483,647
PyPy 3
OK
TESTS
24
109
0
s = input() k = int(input()) w = list(map(int, input().split())) n = len(s) dlt = ord('a') ans = 0 for i in range(n): #print((i + 1) * w[ord(s[i]) - dlt]) ans += (i + 1) * w[ord(s[i]) - dlt] m = max(w) for i in range(n + 1, n + k + 1): #print(m * i) ans += m * i print(ans)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? Input Specification: The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. Output Specification: Print a single integer — the largest possible value of the resulting string DZY could get. Demo Input: ['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n'] Demo Output: ['41\n'] Note: In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
```python s = input() k = int(input()) w = list(map(int, input().split())) n = len(s) dlt = ord('a') ans = 0 for i in range(n): #print((i + 1) * w[ord(s[i]) - dlt]) ans += (i + 1) * w[ord(s[i]) - dlt] m = max(w) for i in range(n + 1, n + k + 1): #print(m * i) ans += m * i print(ans) ```
3
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1", "output": "0 0 1" }, { "input": "5 3", "output": "0 0 5" }, { "input": "42 6", "output": "3 18 21" }, { "input": "1000000000000 1000", "output": "499500499 499500499000 500000000501" }, { "input": "999999999999 999999", "output": "499999 499998500001 500000999999" }, { "input": "732577309725 132613", "output": "2762066 366285858458 366288689201" }, { "input": "152326362626 15", "output": "4760198832 71402982480 76163181314" }, { "input": "2 1", "output": "0 0 2" }, { "input": "1000000000000 500000000000", "output": "0 0 1000000000000" }, { "input": "100000000000 50000000011", "output": "0 0 100000000000" }, { "input": "1000000000000 32416187567", "output": "15 486242813505 513757186480" }, { "input": "1000000000000 7777777777", "output": "64 497777777728 502222222208" }, { "input": "1000000000000 77777777777", "output": "6 466666666662 533333333332" }, { "input": "100000000000 578485652", "output": "86 49749766072 50250233842" }, { "input": "999999999999 10000000000", "output": "49 490000000000 509999999950" }, { "input": "7 2", "output": "1 2 4" }, { "input": "420506530901 752346673804", "output": "0 0 420506530901" }, { "input": "960375521135 321688347872", "output": "1 321688347872 638687173262" }, { "input": "1000000000000 1000000000000", "output": "0 0 1000000000000" }, { "input": "99999999999 15253636363", "output": "3 45760909089 54239090907" }, { "input": "19 2", "output": "3 6 10" }, { "input": "999999999999 1000000000000", "output": "0 0 999999999999" }, { "input": "1000000000000 5915587276", "output": "84 496909331184 503090668732" }, { "input": "1000000000000 1000000006", "output": "499 499000002994 500999996507" }, { "input": "549755813888 134217728", "output": "2047 274743689216 275012122625" }, { "input": "99999999999 3333333", "output": "14999 49996661667 50003323333" }, { "input": "9 1", "output": "2 2 5" }, { "input": "1000000000000 250000000001", "output": "1 250000000001 749999999998" }, { "input": "5 1", "output": "1 1 3" }, { "input": "3107038133 596040207", "output": "2 1192080414 1914957717" }, { "input": "1000000000000 73786977", "output": "6776 499980556152 500019437072" }, { "input": "1000000000000 73786976", "output": "6776 499980549376 500019443848" }, { "input": "1000000000000 25000000000", "output": "19 475000000000 524999999981" }, { "input": "216929598879 768233755932", "output": "0 0 216929598879" }, { "input": "1000000000000 250000000000", "output": "1 250000000000 749999999999" }, { "input": "1000000000000 100000000001", "output": "4 400000000004 599999999992" }, { "input": "100000000000 100000000001", "output": "0 0 100000000000" }, { "input": "900000000000 100281800001", "output": "4 401127200004 498872799992" }, { "input": "906028900004 109123020071", "output": "4 436492080284 469536819716" }, { "input": "1000000000000 1", "output": "250000000000 250000000000 500000000000" } ]
1,500,491,733
2,147,483,647
Python 3
OK
TESTS
44
77
4,608,000
s=input() l=s.split() n=int(l[0]) k=int(l[1]) a=n//2 p1=a//(k+1) p2=k*p1 p3=n-p2-p1 if p3>=n/2 : print(int(p1),int(p2),int(p3)) else : print(0,0,n)
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input Specification: The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. Output Specification: Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Demo Input: ['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n'] Demo Output: ['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n'] Note: none
```python s=input() l=s.split() n=int(l[0]) k=int(l[1]) a=n//2 p1=a//(k+1) p2=k*p1 p3=n-p2-p1 if p3>=n/2 : print(int(p1),int(p2),int(p3)) else : print(0,0,n) ```
3
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10000", "output": "10800100" }, { "input": "2333", "output": "310060" }, { "input": "9139", "output": "10134010" }, { "input": "9859", "output": "10422001" }, { "input": "5987", "output": "2221201" }, { "input": "3", "output": "37" }, { "input": "4", "output": "46" }, { "input": "5", "output": "55" }, { "input": "7", "output": "73" }, { "input": "9", "output": "91" }, { "input": "10", "output": "109" }, { "input": "15", "output": "154" }, { "input": "51", "output": "613" }, { "input": "99", "output": "1414" }, { "input": "138", "output": "2224" }, { "input": "233", "output": "5050" }, { "input": "666", "output": "27100" }, { "input": "1234", "output": "110206" }, { "input": "3567", "output": "1033003" }, { "input": "4445", "output": "1221301" }, { "input": "5689", "output": "2114002" }, { "input": "6666", "output": "3102004" }, { "input": "7777", "output": "5300200" }, { "input": "8888", "output": "10110061" }, { "input": "9411", "output": "10214200" }, { "input": "5539", "output": "2101114" }, { "input": "6259", "output": "2511100" }, { "input": "2387", "output": "312220" }, { "input": "8515", "output": "10030114" } ]
1,694,594,253
2,147,483,647
Python 3
OK
TESTS
35
1,606
0
k=int(input()) a=10 while k!=0: a+=9 s=sum(list(map(int,str(a)))) # print(s) if s==10: k=k-1 print(a)
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). Output Specification: A single number, denoting the $k$-th smallest perfect integer. Demo Input: ['1\n', '2\n'] Demo Output: ['19\n', '28\n'] Note: The first perfect integer is $19$ and the second one is $28$.
```python k=int(input()) a=10 while k!=0: a+=9 s=sum(list(map(int,str(a)))) # print(s) if s==10: k=k-1 print(a) ```
3
352
A
Jeff and Digits
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
[ "4\n5 0 5 0\n", "11\n5 5 5 5 5 5 5 5 0 5 5\n" ]
[ "0\n", "5555555550\n" ]
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
500
[ { "input": "4\n5 0 5 0", "output": "0" }, { "input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550" }, { "input": "7\n5 5 5 5 5 5 5", "output": "-1" }, { "input": "1\n5", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "11\n5 0 5 5 5 0 0 5 5 5 5", "output": "0" }, { "input": "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "9\n5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10\n5 5 5 5 5 0 0 5 0 5", "output": "0" }, { "input": "3\n5 5 0", "output": "0" }, { "input": "5\n5 5 0 5 5", "output": "0" }, { "input": "14\n0 5 5 0 0 0 0 0 0 5 5 5 5 5", "output": "0" }, { "input": "3\n5 5 5", "output": "-1" }, { "input": "3\n0 5 5", "output": "0" }, { "input": "13\n0 0 5 0 5 0 5 5 0 0 0 0 0", "output": "0" }, { "input": "9\n5 5 0 5 5 5 5 5 5", "output": "0" }, { "input": "8\n0 0 0 0 0 0 0 0", "output": "0" }, { "input": "101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 5 0 0", "output": "5555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "214\n5 0 5 0 5 0 0 0 5 5 0 5 0 5 5 0 5 0 0 0 0 5 5 0 0 5 5 0 0 0 0 5 5 5 5 0 5 0 0 0 0 0 0 5 0 0 0 5 0 0 5 0 0 5 5 0 0 5 5 0 0 0 0 0 5 0 5 0 5 5 0 5 0 0 5 5 5 0 5 0 5 0 5 5 0 5 0 0 0 5 5 0 5 0 5 5 5 5 5 0 0 0 0 0 0 5 0 5 5 0 5 0 5 0 5 5 0 0 0 0 5 0 5 0 5 0 0 5 0 0 5 5 5 5 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 5 0 0 0 5 0 0 5 5 5 0 0 5 5 5 0 0 5 5 0 0 0 5 0 0 5 5 5 5 5 5 0 5 0 0 5 5 5 5 0 5 5 0 0 0 5 5 5 5 0 0 0 0 5 0 0 5 0 0 5 5 0 0", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "80\n0 0 0 0 5 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 0 0 5 5 0 5 0 0 0 0 0 0 5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 5 5 0 0 0", "output": "555555555000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2\n0 0", "output": "0" }, { "input": "3\n5 0 0", "output": "0" }, { "input": "4\n5 5 5 5", "output": "-1" }, { "input": "2\n0 5", "output": "0" }, { "input": "14\n5 5 5 5 5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "18\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "10\n5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "10\n5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "20\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" } ]
1,684,761,769
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
n = int(input()) lst = list(map(int, input().rstrip().split())) d = {} for i in lst: if i not in d: d[i] = 1 else: d[i] += 1 if d[5] > 9 and d[0] > 0: print("5" * 9 * (d[5] // 9) + "0" * d[0]) else: print(0)
Title: Jeff and Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. Output Specification: In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. Demo Input: ['4\n5 0 5 0\n', '11\n5 5 5 5 5 5 5 5 0 5 5\n'] Demo Output: ['0\n', '5555555550\n'] Note: In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
```python n = int(input()) lst = list(map(int, input().rstrip().split())) d = {} for i in lst: if i not in d: d[i] = 1 else: d[i] += 1 if d[5] > 9 and d[0] > 0: print("5" * 9 * (d[5] // 9) + "0" * d[0]) else: print(0) ```
0
377
A
Maze
PROGRAMMING
1,600
[ "dfs and similar" ]
null
null
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
[ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ]
[ "#.X#\nX.#.\n#...\n", "#XXX\n#X#.\nX#..\n...#\n.#.#\n" ]
none
500
[ { "input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#" }, { "input": "3 3 2\n#.#\n...\n#.#", "output": "#X#\nX..\n#.#" }, { "input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#" }, { "input": "1 1 0\n.", "output": "." }, { "input": "2 3 1\n..#\n#..", "output": "X.#\n#.." }, { "input": "2 3 1\n#..\n..#", "output": "#.X\n..#" }, { "input": "3 3 1\n...\n.#.\n..#", "output": "...\n.#X\n..#" }, { "input": "3 3 1\n...\n.#.\n#..", "output": "...\nX#.\n#.." }, { "input": "5 4 4\n#..#\n....\n.##.\n....\n#..#", "output": "#XX#\nXX..\n.##.\n....\n#..#" }, { "input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..", "output": "X#..#\nX.#.#\n#....\n##.#.\n###.." }, { "input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#", "output": "#.....\n#X#.#X\nX#...#\n...#.#" }, { "input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#", "output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#" }, { "input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###", "output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###" }, { "input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################", "output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################" }, { "input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#", "output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#" }, { "input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###", "output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###" }, { "input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######", "output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######" }, { "input": "3 5 1\n#...#\n..#..\n..#..", "output": "#...#\n..#..\nX.#.." }, { "input": "4 5 10\n.....\n.....\n..#..\n..#..", "output": "XXX..\nXXX..\nXX#..\nXX#.." }, { "input": "3 5 3\n.....\n..#..\n..#..", "output": ".....\nX.#..\nXX#.." }, { "input": "3 5 1\n#....\n..#..\n..###", "output": "#....\n..#.X\n..###" }, { "input": "4 5 1\n.....\n.##..\n..#..\n..###", "output": ".....\n.##..\n..#.X\n..###" }, { "input": "3 5 2\n..#..\n..#..\n....#", "output": "X.#..\nX.#..\n....#" }, { "input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########" }, { "input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###", "output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###" }, { "input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..", "output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.." }, { "input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..", "output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.." }, { "input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", "output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########" }, { "input": "4 5 1\n.....\n.###.\n..#..\n..#..", "output": ".....\n.###.\n..#..\n.X#.." }, { "input": "2 5 2\n###..\n###..", "output": "###X.\n###X." }, { "input": "2 5 3\n.....\n..#..", "output": "X....\nXX#.." }, { "input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############", "output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n#####", "output": ".....\n.##.X\n..###\n..###\n#####" }, { "input": "4 4 1\n....\n.#..\n..##\n..##", "output": "....\n.#.X\n..##\n..##" }, { "input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##", "output": "....#\n.##..\n.##.X\n...##\n...##" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n..###", "output": ".....\n.##.X\n..###\n..###\n..###" }, { "input": "4 5 1\n#....\n#.#..\n..###\n..###", "output": "#....\n#.#.X\n..###\n..###" }, { "input": "4 4 3\n....\n.#..\n..##\n..##", "output": "...X\n.#XX\n..##\n..##" }, { "input": "4 7 6\n.......\n....#..\n.##.#..\n....#..", "output": "X......\nX...#..\nX##.#..\nXXX.#.." }, { "input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######", "output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######" } ]
1,665,488,786
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
7
280
23,449,600
def polycarpus(graph, n, m, k): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] visited = set() def inBound(x, y): return 0 <= x < n and 0 <= y < m C = n * m start = None for i in range(n): for j in range(m): if graph[i][j] == '#': C -= 1 if not start and graph[i][j] == '.': start = (i, j) visited.add(start) count = 0 def dfs(p, lim): nonlocal count px, py = p count += 1 if count > lim: graph[px][py] = 'X' for x, y in directions: nx, ny = px + x, py + y if (nx, ny) not in visited and inBound(nx, ny) and graph[nx][ny] == '.': visited.add((nx, ny)) dfs((nx, ny), lim) if k > 0: dfs(start, C - k) for i in range(n): for j in range(m): print(graph[i][j], end="") print() n, m, k = list(map(int, input().split())) maze = [] for _ in range(n): maze.append(list(input())) polycarpus(maze, n, m, k)
Title: Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. Output Specification: Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. Demo Input: ['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n'] Demo Output: ['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n'] Note: none
```python def polycarpus(graph, n, m, k): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] visited = set() def inBound(x, y): return 0 <= x < n and 0 <= y < m C = n * m start = None for i in range(n): for j in range(m): if graph[i][j] == '#': C -= 1 if not start and graph[i][j] == '.': start = (i, j) visited.add(start) count = 0 def dfs(p, lim): nonlocal count px, py = p count += 1 if count > lim: graph[px][py] = 'X' for x, y in directions: nx, ny = px + x, py + y if (nx, ny) not in visited and inBound(nx, ny) and graph[nx][ny] == '.': visited.add((nx, ny)) dfs((nx, ny), lim) if k > 0: dfs(start, C - k) for i in range(n): for j in range(m): print(graph[i][j], end="") print() n, m, k = list(map(int, input().split())) maze = [] for _ in range(n): maze.append(list(input())) polycarpus(maze, n, m, k) ```
-1
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him.
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt", "output": "NO" }, { "input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos", "output": "YES" }, { "input": "3\naaa\naaa\naaa", "output": "NO" }, { "input": "3\naca\noec\nzba", "output": "NO" }, { "input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo", "output": "NO" }, { "input": "3\nxxx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxx\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxxx", "output": "NO" }, { "input": "3\nxax\nxxa\nxax", "output": "NO" }, { "input": "3\nxax\naaa\nxax", "output": "NO" }, { "input": "3\naax\naxa\nxax", "output": "NO" }, { "input": "3\nxaa\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\naax", "output": "NO" }, { "input": "3\nxax\naxa\nxaa", "output": "NO" }, { "input": "3\nxfx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\nafa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxaf", "output": "NO" }, { "input": "3\nxox\nxxx\nxxx", "output": "NO" }, { "input": "3\naxa\naax\nxxa", "output": "NO" }, { "input": "3\nxox\noxx\nxox", "output": "NO" }, { "input": "3\nxox\nooo\nxox", "output": "NO" }, { "input": "3\naaa\naab\nbbb", "output": "NO" }, { "input": "3\nxxx\nsxs\nxsx", "output": "NO" }, { "input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba", "output": "NO" }, { "input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba", "output": "NO" }, { "input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nxox\noxx\nxxx", "output": "NO" }, { "input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox", "output": "NO" }, { "input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox", "output": "NO" }, { "input": "3\naaa\nbab\naba", "output": "NO" } ]
1,604,488,191
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
19
124
307,200
n = int(input()) arr = [] for i in range(n): arr.append(input()) d,nd = arr[0][0],arr[0][1] if d==nd: print('NO') else: check = 0 index = n//2 for i in range(n): for j in range(index+1): if i==j or i+j==n-1: if arr[i][j]==arr[i][n-1-j]==d: continue else: check = 1 break else: if arr[i][j] != nd: check = 1 break if check==1: break if check==0: print('YES') else: print('NO')
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. Output Specification: Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. Demo Input: ['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python n = int(input()) arr = [] for i in range(n): arr.append(input()) d,nd = arr[0][0],arr[0][1] if d==nd: print('NO') else: check = 0 index = n//2 for i in range(n): for j in range(index+1): if i==j or i+j==n-1: if arr[i][j]==arr[i][n-1-j]==d: continue else: check = 1 break else: if arr[i][j] != nd: check = 1 break if check==1: break if check==0: print('YES') else: print('NO') ```
0
863
G
Graphic Settings
PROGRAMMING
3,200
[]
null
null
Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the framerate would be really low), but now he wants to check, maybe his new computer can perform well even with the best possible graphics? There are *m* graphics parameters in the game. *i*-th parameter can be set to any positive integer from 1 to *a**i*, and initially is set to *b**i* (*b**i*<=≤<=*a**i*). So there are different combinations of parameters. Ivan can increase or decrease any of these parameters by 1; after that the game will be restarted with new parameters (and Ivan will have the opportunity to check chosen combination of parameters). Ivan wants to try all *p* possible combinations. Also he wants to return to the initial settings after trying all combinations, because he thinks that initial settings can be somehow best suited for his hardware. But Ivan doesn't really want to make a lot of restarts. So he wants you to tell the following: - If there exists a way to make exactly *p* changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then Ivan wants to know this way. - Otherwise, if there exists a way to make exactly *p*<=-<=1 changes to try all possible combinations (including the initial one), then Ivan wants to know this way. Help Ivan by showing him the way to change parameters!
The first line of input contains one integer number *m* (1<=≤<=*m*<=≤<=6). The second line contains *m* integer numbers *a*1,<=*a*2,<=...,<=*a**m* (2<=≤<=*a**i*<=≤<=1000). It is guaranteed that . The third line contains *m* integer numbers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*a**i*).
If there is a way to make exactly *p* changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then output Cycle in the first line. Then *p* lines must follow, each desribing a change. The line must be either inc x (increase parameter *x* by 1) or dec x (decrease it). Otherwise, if there is a way to make exactly *p*<=-<=1 changes to try all possible combinations (including the initial one), then output Path in the first line. Then *p*<=-<=1 lines must follow, each describing the change the same way as mentioned above. Otherwise, output No.
[ "1\n3\n1\n", "1\n3\n2\n", "2\n3 2\n1 1\n" ]
[ "Path\ninc 1\ninc 1\n", "No\n", "Cycle\ninc 1\ninc 1\ninc 2\ndec 1\ndec 1\ndec 2\n" ]
none
0
[]
1,693,640,173
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_changes = sum(a[i] - b[i] for i in range(m)) p = (max_changes + m) // 2 # Calculate the number of changes required # Create a list to store the changes changes = [] def find_changes(p): if p < 0: return False if p == 0: return True for i in range(m): if b[i] < a[i]: b[i] += 1 changes.append(f'inc {i + 1}') if find_changes(p - 1): return True changes.pop() b[i] -= 1 if b[i] > 1: b[i] -= 1 changes.append(f'dec {i + 1}') if find_changes(p - 1): return True changes.pop() b[i] += 1 return False if find_changes(p): if len(changes) == p: print("Cycle") else: print("Path") for change in changes: print(change) else: print("No")
Title: Graphic Settings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the framerate would be really low), but now he wants to check, maybe his new computer can perform well even with the best possible graphics? There are *m* graphics parameters in the game. *i*-th parameter can be set to any positive integer from 1 to *a**i*, and initially is set to *b**i* (*b**i*<=≤<=*a**i*). So there are different combinations of parameters. Ivan can increase or decrease any of these parameters by 1; after that the game will be restarted with new parameters (and Ivan will have the opportunity to check chosen combination of parameters). Ivan wants to try all *p* possible combinations. Also he wants to return to the initial settings after trying all combinations, because he thinks that initial settings can be somehow best suited for his hardware. But Ivan doesn't really want to make a lot of restarts. So he wants you to tell the following: - If there exists a way to make exactly *p* changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then Ivan wants to know this way. - Otherwise, if there exists a way to make exactly *p*<=-<=1 changes to try all possible combinations (including the initial one), then Ivan wants to know this way. Help Ivan by showing him the way to change parameters! Input Specification: The first line of input contains one integer number *m* (1<=≤<=*m*<=≤<=6). The second line contains *m* integer numbers *a*1,<=*a*2,<=...,<=*a**m* (2<=≤<=*a**i*<=≤<=1000). It is guaranteed that . The third line contains *m* integer numbers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*a**i*). Output Specification: If there is a way to make exactly *p* changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then output Cycle in the first line. Then *p* lines must follow, each desribing a change. The line must be either inc x (increase parameter *x* by 1) or dec x (decrease it). Otherwise, if there is a way to make exactly *p*<=-<=1 changes to try all possible combinations (including the initial one), then output Path in the first line. Then *p*<=-<=1 lines must follow, each describing the change the same way as mentioned above. Otherwise, output No. Demo Input: ['1\n3\n1\n', '1\n3\n2\n', '2\n3 2\n1 1\n'] Demo Output: ['Path\ninc 1\ninc 1\n', 'No\n', 'Cycle\ninc 1\ninc 1\ninc 2\ndec 1\ndec 1\ndec 2\n'] Note: none
```python m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_changes = sum(a[i] - b[i] for i in range(m)) p = (max_changes + m) // 2 # Calculate the number of changes required # Create a list to store the changes changes = [] def find_changes(p): if p < 0: return False if p == 0: return True for i in range(m): if b[i] < a[i]: b[i] += 1 changes.append(f'inc {i + 1}') if find_changes(p - 1): return True changes.pop() b[i] -= 1 if b[i] > 1: b[i] -= 1 changes.append(f'dec {i + 1}') if find_changes(p - 1): return True changes.pop() b[i] += 1 return False if find_changes(p): if len(changes) == p: print("Cycle") else: print("Path") for change in changes: print(change) else: print("No") ```
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
1,695,062,353
2,147,483,647
Python 3
OK
TESTS
25
92
0
n = input() k = n[0].upper() print(k+n[1:])
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python n = input() k = n[0].upper() print(k+n[1:]) ```
3
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "output": "NO" }, { "input": "3 3\n1 1\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n1 2\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n2 2\n1 2 3\n1 2 3", "output": "NO" }, { "input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49", "output": "YES" }, { "input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100", "output": "YES" }, { "input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99", "output": "YES" }, { "input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81", "output": "YES" }, { "input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10", "output": "NO" }, { "input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "1 1\n1 1\n-1000000000\n30", "output": "YES" }, { "input": "3 3\n1 3\n1 3 3\n3 3 3", "output": "YES" }, { "input": "3 3\n1 1\n3 3 3\n2 2 2", "output": "NO" }, { "input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7", "output": "NO" }, { "input": "3 4\n2 2\n5 6 7\n1 2 3 4", "output": "NO" }, { "input": "3 3\n3 3\n1 2 3\n4 5 6", "output": "YES" }, { "input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9", "output": "YES" } ]
1,502,794,665
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
61
4,608,000
na,nb=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) #Case 1: all from a will happen only if max of a is less than b if k==na: i=0 while a[-1]>=b[i]: i+=1 #I elements have been traced if the remaining elements if (nb-i)>=m: print("YES") else: print("NO") else: trace=a[k] #Trace this in b i=0 while trace>=b[i]: i+=1 if (nb-i)>=m: print("YES") else: print("NO")
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. Input Specification: The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. Output Specification: Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). Demo Input: ['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python na,nb=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) #Case 1: all from a will happen only if max of a is less than b if k==na: i=0 while a[-1]>=b[i]: i+=1 #I elements have been traced if the remaining elements if (nb-i)>=m: print("YES") else: print("NO") else: trace=a[k] #Trace this in b i=0 while trace>=b[i]: i+=1 if (nb-i)>=m: print("YES") else: print("NO") ```
-1
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", "output": "-1" }, { "input": "20", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "-1" }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "11", "output": "-1" }, { "input": "21", "output": "-1" }, { "input": "50", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 " }, { "input": "51", "output": "-1" }, { "input": "52", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 " }, { "input": "84", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 " }, { "input": "86", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "33", "output": "-1" }, { "input": "34", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 " }, { "input": "36", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 " }, { "input": "38", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 " }, { "input": "40", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 " }, { "input": "42", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 " }, { "input": "44", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 " }, { "input": "46", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 " }, { "input": "48", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 " } ]
1,666,544,530
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n = int(input()) if n % 2 == 0: l = [] y = [] for i in range(1, n+1): l.append(i) for i in range(1, n+1, 2): y.append(l[i]) y.append(i) print(y) else: print("-1")
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. Input Specification: A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. Output Specification: If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. Demo Input: ['1\n', '2\n', '4\n'] Demo Output: ['-1\n', '2 1 \n', '2 1 4 3 \n'] Note: none
```python n = int(input()) if n % 2 == 0: l = [] y = [] for i in range(1, n+1): l.append(i) for i in range(1, n+1, 2): y.append(l[i]) y.append(i) print(y) else: print("-1") ```
0
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,475,694,466
2,147,483,647
Python 3
OK
TESTS
30
124
0
n = int(input()) arr = sum(list(map(int,input().split()))) cnt=0 for i in range(1,6): if ((arr+i)%(n+1) )!=1: cnt+=1 print(cnt)
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 n = int(input()) arr = sum(list(map(int,input().split()))) cnt=0 for i in range(1,6): if ((arr+i)%(n+1) )!=1: cnt+=1 print(cnt) ```
3