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
794
A
Bank Robbery
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe from the left is called safe *i*. There are *n* banknotes left in all the safes in total. The *i*-th banknote is in safe *x**i*. Oleg is now at safe *a*. There are two security guards, one of which guards the safe *b* such that *b*<=&lt;<=*a*, i.e. the first guard is to the left of Oleg. The other guard guards the safe *c* so that *c*<=&gt;<=*a*, i.e. he is to the right of Oleg. The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather.
The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=&lt;<=*a*<=&lt;<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively. The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of banknotes. The next line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109), denoting that the *i*-th banknote is located in the *x**i*-th safe. Note that *x**i* are not guaranteed to be distinct.
Output a single integer: the maximum number of banknotes Oleg can take.
[ "5 3 7\n8\n4 7 5 5 3 6 2 8\n", "6 5 7\n5\n1 5 7 92 3\n" ]
[ "4\n", "0\n" ]
In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes. For the second sample, Oleg can't take any banknotes without bumping into any of the security guards.
500
[ { "input": "5 3 7\n8\n4 7 5 5 3 6 2 8", "output": "4" }, { "input": "6 5 7\n5\n1 5 7 92 3", "output": "0" }, { "input": "3 2 4\n1\n3", "output": "1" }, { "input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6", "output": "8" }, { "input": "7 3 10\n5\n3 3 3 3 3", "output": "0" }, { "input": "3 2 5\n4\n1 3 4 5", "output": "2" }, { "input": "3 2 4\n1\n1", "output": "0" }, { "input": "6 4 8\n1\n4", "output": "0" }, { "input": "2 1 3\n1\n3", "output": "0" } ]
1,494,668,869
769
Python 3
OK
TESTS
46
109
8,704,000
a, b, c = map(int, input().split()) n = int(input()) k = list(map(int, input().split())) s = 0 for i in k: if b < i < c: s += 1 print(s)
Title: Bank Robbery Time Limit: None seconds Memory Limit: None megabytes Problem Description: A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe from the left is called safe *i*. There are *n* banknotes left in all the safes in total. The *i*-th banknote is in safe *x**i*. Oleg is now at safe *a*. There are two security guards, one of which guards the safe *b* such that *b*<=&lt;<=*a*, i.e. the first guard is to the left of Oleg. The other guard guards the safe *c* so that *c*<=&gt;<=*a*, i.e. he is to the right of Oleg. The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather. Input Specification: The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=&lt;<=*a*<=&lt;<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively. The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of banknotes. The next line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109), denoting that the *i*-th banknote is located in the *x**i*-th safe. Note that *x**i* are not guaranteed to be distinct. Output Specification: Output a single integer: the maximum number of banknotes Oleg can take. Demo Input: ['5 3 7\n8\n4 7 5 5 3 6 2 8\n', '6 5 7\n5\n1 5 7 92 3\n'] Demo Output: ['4\n', '0\n'] Note: In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes. For the second sample, Oleg can't take any banknotes without bumping into any of the security guards.
```python a, b, c = map(int, input().split()) n = int(input()) k = list(map(int, input().split())) s = 0 for i in k: if b < i < c: s += 1 print(s) ```
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,689,784,557
2,147,483,647
Python 3
OK
TESTS
34
46
0
n=int(input()) a=list(map(int,input().split())) x,y=0,0 for i in range(n): k=max(a[0],a[-1]) if i%2==0: x+=k else: y+=k a.remove(k) print(x,y)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n=int(input()) a=list(map(int,input().split())) x,y=0,0 for i in range(n): k=max(a[0],a[-1]) if i%2==0: x+=k else: y+=k a.remove(k) print(x,y) ```
3
390
A
Inna and Alarm Clock
PROGRAMMING
0
[ "implementation" ]
null
null
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square. The morning has come. All *n* alarm clocks in Inna's room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game: - First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal. - Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off. Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks!
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100). Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room.
In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally.
[ "4\n0 0\n0 1\n0 2\n1 0\n", "4\n0 0\n0 1\n1 0\n1 1\n", "4\n1 1\n1 2\n2 3\n3 3\n" ]
[ "2\n", "2\n", "3\n" ]
In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments. In the third sample it is important to note that Inna doesn't have the right to change the type of the segments during the game. That's why she will need 3 horizontal or 3 vertical segments to end the game.
500
[ { "input": "4\n0 0\n0 1\n0 2\n1 0", "output": "2" }, { "input": "4\n0 0\n0 1\n1 0\n1 1", "output": "2" }, { "input": "4\n1 1\n1 2\n2 3\n3 3", "output": "3" }, { "input": "1\n0 0", "output": "1" }, { "input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n97 100\n86 34\n42 36\n44 40\n14 85\n21 60\n76 99\n64 47\n69 13\n49 37\n97 37\n3 70", "output": "31" }, { "input": "21\n54 85\n69 37\n42 87\n53 18\n28 22\n13 3\n62 97\n38 91\n67 19\n100 79\n29 18\n48 40\n68 84\n44 20\n37 34\n73 53\n21 5\n20 73\n24 94\n23 52\n7 55", "output": "20" }, { "input": "19\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19", "output": "1" }, { "input": "12\n1 1\n1 3\n1 5\n2 1\n2 2\n2 4\n3 1\n3 3\n3 5\n4 1\n4 2\n4 3", "output": "4" } ]
1,544,063,287
2,147,483,647
Python 3
OK
TESTS
19
343
7,884,800
n = int(input()) a = [] b = [] for _ in range(n): xy = list(map(str,input().split())) a.append(xy[0]) b.append(xy[1]) aa = list(set(a)) bb = list(set(b)) if(len(aa) > len(bb)): print(len(bb)) else: print(len(aa))
Title: Inna and Alarm Clock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square. The morning has come. All *n* alarm clocks in Inna's room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game: - First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal. - Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off. Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks! Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100). Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room. Output Specification: In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. Demo Input: ['4\n0 0\n0 1\n0 2\n1 0\n', '4\n0 0\n0 1\n1 0\n1 1\n', '4\n1 1\n1 2\n2 3\n3 3\n'] Demo Output: ['2\n', '2\n', '3\n'] Note: In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments. In the third sample it is important to note that Inna doesn't have the right to change the type of the segments during the game. That's why she will need 3 horizontal or 3 vertical segments to end the game.
```python n = int(input()) a = [] b = [] for _ in range(n): xy = list(map(str,input().split())) a.append(xy[0]) b.append(xy[1]) aa = list(set(a)) bb = list(set(b)) if(len(aa) > len(bb)): print(len(bb)) else: print(len(aa)) ```
3
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,690,051,288
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
102,400
n, m = map(int, input().split(" ")) board = [] # chess = [[False for _ in range(n)] for i in range(m)] colour = False # False = black # True = white # row_checker = 0 # col_checker = 0 for row in range(n): col = list(input()) board.append(col) if n % 2 == 0: for col in range(m): for row in range(n): if board[row][col] == '-': continue else: if (row == n - 1 and col != m - 1): # or (col == m - 1 and row != n - 1): board[row][col] = colour else: board[row][col] = colour colour = not colour elif n % 2 != 0: for col in range(m): for row in range(n): if board[row][col] == '-': continue else: board[row][col] = colour colour = not colour for el in board: for i in el: if i is True: print("W", end='') elif i is False: print("B", end='') else: print(i, end='') print()
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 n, m = map(int, input().split(" ")) board = [] # chess = [[False for _ in range(n)] for i in range(m)] colour = False # False = black # True = white # row_checker = 0 # col_checker = 0 for row in range(n): col = list(input()) board.append(col) if n % 2 == 0: for col in range(m): for row in range(n): if board[row][col] == '-': continue else: if (row == n - 1 and col != m - 1): # or (col == m - 1 and row != n - 1): board[row][col] = colour else: board[row][col] = colour colour = not colour elif n % 2 != 0: for col in range(m): for row in range(n): if board[row][col] == '-': continue else: board[row][col] = colour colour = not colour for el in board: for i in el: if i is True: print("W", end='') elif i is False: print("B", end='') else: print(i, end='') print() ```
0
234
A
Lefthanders and Righthanders
PROGRAMMING
1,200
[ "implementation" ]
null
null
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*. But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave. On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other. Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists.
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them.
[ "6\nLLRLLL\n", "4\nRRLL\n" ]
[ "1 4\n2 5\n6 3\n", "3 1\n4 2\n" ]
none
0
[ { "input": "6\nLLRLLL", "output": "1 4\n2 5\n6 3" }, { "input": "4\nRRLL", "output": "3 1\n4 2" }, { "input": "4\nLLRR", "output": "1 3\n2 4" }, { "input": "6\nRLLRRL", "output": "1 4\n2 5\n3 6" }, { "input": "8\nLRLRLLLR", "output": "1 5\n6 2\n3 7\n4 8" }, { "input": "10\nRLLRLRRRLL", "output": "1 6\n2 7\n3 8\n9 4\n5 10" }, { "input": "12\nLRRRRRLRRRRL", "output": "1 7\n2 8\n3 9\n4 10\n5 11\n12 6" }, { "input": "14\nRLLRLLLLRLLLRL", "output": "8 1\n2 9\n3 10\n11 4\n5 12\n6 13\n7 14" }, { "input": "16\nLLLRRRLRRLLRRLLL", "output": "1 9\n2 10\n3 11\n4 12\n5 13\n14 6\n7 15\n16 8" }, { "input": "18\nRRRLLLLRRRLRLRLLRL", "output": "1 10\n11 2\n3 12\n4 13\n5 14\n6 15\n7 16\n8 17\n18 9" }, { "input": "20\nRLRLLRLRRLLRRRRRRLRL", "output": "11 1\n2 12\n3 13\n4 14\n5 15\n6 16\n7 17\n18 8\n9 19\n10 20" }, { "input": "22\nRLLLRLLLRRLRRRLRLLLLLL", "output": "1 12\n2 13\n3 14\n4 15\n5 16\n6 17\n7 18\n8 19\n20 9\n21 10\n11 22" }, { "input": "24\nLRRRLRLLRLRRRRLLLLRRLRLR", "output": "1 13\n2 14\n15 3\n16 4\n5 17\n18 6\n7 19\n8 20\n21 9\n10 22\n23 11\n12 24" }, { "input": "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR", "output": "1 14\n2 15\n16 3\n4 17\n5 18\n6 19\n7 20\n8 21\n9 22\n10 23\n24 11\n12 25\n13 26" }, { "input": "28\nLLLRRRRRLRRLRRRLRLRLRRLRLRRL", "output": "1 15\n2 16\n3 17\n18 4\n5 19\n20 6\n7 21\n8 22\n9 23\n10 24\n25 11\n12 26\n13 27\n28 14" }, { "input": "30\nLRLLRLRRLLRLRLLRRRRRLRLRLRLLLL", "output": "1 16\n2 17\n3 18\n4 19\n5 20\n6 21\n7 22\n23 8\n9 24\n10 25\n11 26\n12 27\n28 13\n14 29\n15 30" }, { "input": "32\nRLRLLRRLLRRLRLLRLRLRLLRLRRRLLRRR", "output": "17 1\n2 18\n19 3\n4 20\n5 21\n22 6\n7 23\n8 24\n9 25\n10 26\n11 27\n12 28\n29 13\n14 30\n15 31\n16 32" }, { "input": "34\nLRRLRLRLLRRRRLLRLRRLRRLRLRRLRRRLLR", "output": "1 18\n2 19\n20 3\n4 21\n5 22\n6 23\n7 24\n8 25\n9 26\n10 27\n28 11\n12 29\n13 30\n14 31\n15 32\n33 16\n17 34" }, { "input": "36\nRRLLLRRRLLLRRLLLRRLLRLLRLRLLRLRLRLLL", "output": "19 1\n20 2\n3 21\n4 22\n5 23\n6 24\n25 7\n8 26\n9 27\n10 28\n11 29\n30 12\n13 31\n14 32\n15 33\n16 34\n35 17\n36 18" }, { "input": "38\nLLRRRLLRRRLRRLRLRRLRRLRLRLLRRRRLLLLRLL", "output": "1 20\n2 21\n22 3\n4 23\n24 5\n6 25\n7 26\n27 8\n9 28\n10 29\n11 30\n12 31\n32 13\n14 33\n34 15\n16 35\n17 36\n37 18\n19 38" }, { "input": "40\nLRRRRRLRLLRRRLLRRLRLLRLRRLRRLLLRRLRRRLLL", "output": "1 21\n2 22\n23 3\n4 24\n5 25\n26 6\n7 27\n8 28\n9 29\n10 30\n31 11\n12 32\n13 33\n14 34\n15 35\n16 36\n17 37\n18 38\n39 19\n20 40" }, { "input": "42\nRLRRLLLLLLLRRRLRLLLRRRLRLLLRLRLRLLLRLRLRRR", "output": "1 22\n2 23\n3 24\n25 4\n5 26\n6 27\n7 28\n8 29\n9 30\n10 31\n11 32\n33 12\n34 13\n35 14\n15 36\n37 16\n17 38\n18 39\n19 40\n20 41\n21 42" }, { "input": "44\nLLLLRRLLRRLLRRLRLLRRRLRLRLLRLRLRRLLRLRRLLLRR", "output": "1 23\n2 24\n3 25\n4 26\n27 5\n6 28\n7 29\n8 30\n31 9\n10 32\n11 33\n12 34\n35 13\n14 36\n15 37\n16 38\n17 39\n18 40\n41 19\n42 20\n21 43\n22 44" }, { "input": "46\nRRRLLLLRRLRLRRRRRLRLLRLRRLRLLLLLLLLRRLRLRLRLLL", "output": "1 24\n2 25\n26 3\n4 27\n5 28\n6 29\n7 30\n31 8\n32 9\n10 33\n34 11\n12 35\n13 36\n14 37\n38 15\n16 39\n40 17\n18 41\n42 19\n20 43\n21 44\n45 22\n23 46" }, { "input": "48\nLLLLRRLRRRRLRRRLRLLLLLRRLLRLLRLLRRLRRLLRLRLRRRRL", "output": "1 25\n2 26\n3 27\n4 28\n29 5\n6 30\n7 31\n32 8\n9 33\n10 34\n35 11\n12 36\n13 37\n38 14\n39 15\n16 40\n41 17\n18 42\n19 43\n20 44\n21 45\n22 46\n23 47\n48 24" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 26\n2 27\n3 28\n4 29\n5 30\n6 31\n7 32\n8 33\n9 34\n10 35\n11 36\n12 37\n13 38\n14 39\n15 40\n16 41\n17 42\n18 43\n19 44\n20 45\n21 46\n22 47\n23 48\n24 49\n25 50" }, { "input": "52\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 27\n2 28\n3 29\n4 30\n5 31\n6 32\n7 33\n8 34\n9 35\n10 36\n11 37\n12 38\n13 39\n14 40\n15 41\n16 42\n17 43\n18 44\n19 45\n20 46\n21 47\n22 48\n23 49\n24 50\n25 51\n26 52" }, { "input": "54\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 28\n2 29\n3 30\n4 31\n5 32\n6 33\n7 34\n8 35\n9 36\n10 37\n11 38\n12 39\n13 40\n14 41\n15 42\n16 43\n17 44\n18 45\n19 46\n20 47\n21 48\n22 49\n23 50\n24 51\n25 52\n26 53\n27 54" }, { "input": "56\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 29\n2 30\n3 31\n4 32\n5 33\n6 34\n7 35\n8 36\n9 37\n10 38\n11 39\n12 40\n13 41\n14 42\n15 43\n16 44\n17 45\n18 46\n19 47\n20 48\n21 49\n22 50\n23 51\n24 52\n25 53\n26 54\n27 55\n28 56" }, { "input": "58\nRRRLLLRLLLLRRLRRRLLRLLRLRLLRLRRRRLLLLLLRLRRLRLRRRLRLRRLRRL", "output": "1 30\n2 31\n3 32\n4 33\n5 34\n6 35\n36 7\n8 37\n9 38\n10 39\n11 40\n41 12\n13 42\n14 43\n44 15\n16 45\n46 17\n18 47\n19 48\n20 49\n21 50\n22 51\n52 23\n24 53\n25 54\n26 55\n27 56\n28 57\n29 58" }, { "input": "60\nRLLLLRRLLRRRLLLLRRRRRLRRRLRRRLLLRLLLRLRRRLRLLLRLLRRLLRRRRRLL", "output": "31 1\n2 32\n3 33\n4 34\n5 35\n36 6\n7 37\n8 38\n9 39\n10 40\n11 41\n42 12\n13 43\n14 44\n15 45\n16 46\n17 47\n48 18\n49 19\n20 50\n21 51\n22 52\n53 23\n24 54\n25 55\n26 56\n27 57\n28 58\n59 29\n30 60" }, { "input": "62\nLRRLRLRLLLLRRLLLLRRRLRLLLLRRRLLLLLLRRRLLLLRRLRRLRLLLLLLLLRRLRR", "output": "1 32\n33 2\n34 3\n4 35\n5 36\n6 37\n7 38\n8 39\n9 40\n10 41\n11 42\n12 43\n13 44\n14 45\n15 46\n16 47\n17 48\n18 49\n50 19\n51 20\n21 52\n53 22\n23 54\n24 55\n25 56\n26 57\n27 58\n28 59\n60 29\n30 61\n31 62" }, { "input": "64\nRLLLLRRRLRLLRRRRLRLLLRRRLLLRRRLLRLLRLRLRRRLLRRRRLRLRRRLLLLRRLLLL", "output": "1 33\n2 34\n3 35\n4 36\n5 37\n6 38\n39 7\n8 40\n9 41\n10 42\n11 43\n12 44\n13 45\n14 46\n15 47\n16 48\n17 49\n18 50\n19 51\n20 52\n21 53\n22 54\n55 23\n56 24\n25 57\n26 58\n27 59\n28 60\n61 29\n62 30\n31 63\n32 64" }, { "input": "66\nLLRRRLLRLRLLRRRRRRRLLLLRRLLLLLLRLLLRLLLLLLRRRLRRLLRRRRRLRLLRLLLLRR", "output": "1 34\n2 35\n3 36\n37 4\n38 5\n6 39\n7 40\n41 8\n9 42\n10 43\n11 44\n12 45\n46 13\n14 47\n15 48\n49 16\n50 17\n18 51\n19 52\n20 53\n21 54\n22 55\n23 56\n24 57\n58 25\n26 59\n27 60\n28 61\n29 62\n30 63\n31 64\n32 65\n33 66" }, { "input": "68\nRRLRLRLLRLRLRRRRRRLRRRLLLLRLLRLRLRLRRRRLRLRLLRRRRLRRLLRLRRLLRLRRLRRL", "output": "35 1\n2 36\n3 37\n4 38\n5 39\n40 6\n7 41\n8 42\n9 43\n10 44\n45 11\n12 46\n13 47\n14 48\n15 49\n50 16\n17 51\n18 52\n19 53\n54 20\n21 55\n56 22\n23 57\n24 58\n25 59\n26 60\n27 61\n28 62\n29 63\n30 64\n31 65\n32 66\n33 67\n68 34" }, { "input": "70\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 36\n2 37\n3 38\n4 39\n5 40\n6 41\n7 42\n8 43\n9 44\n10 45\n11 46\n12 47\n13 48\n14 49\n15 50\n16 51\n17 52\n18 53\n19 54\n20 55\n21 56\n22 57\n23 58\n24 59\n25 60\n26 61\n27 62\n28 63\n29 64\n30 65\n31 66\n32 67\n33 68\n34 69\n35 70" }, { "input": "72\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 37\n2 38\n3 39\n4 40\n5 41\n6 42\n7 43\n8 44\n9 45\n10 46\n11 47\n12 48\n13 49\n14 50\n15 51\n16 52\n17 53\n18 54\n19 55\n20 56\n21 57\n22 58\n23 59\n24 60\n25 61\n26 62\n27 63\n28 64\n29 65\n30 66\n31 67\n32 68\n33 69\n34 70\n35 71\n36 72" }, { "input": "74\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 38\n2 39\n3 40\n4 41\n5 42\n6 43\n7 44\n8 45\n9 46\n10 47\n11 48\n12 49\n13 50\n14 51\n15 52\n16 53\n17 54\n18 55\n19 56\n20 57\n21 58\n22 59\n23 60\n24 61\n25 62\n26 63\n27 64\n28 65\n29 66\n30 67\n31 68\n32 69\n33 70\n34 71\n35 72\n36 73\n37 74" }, { "input": "76\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 39\n2 40\n3 41\n4 42\n5 43\n6 44\n7 45\n8 46\n9 47\n10 48\n11 49\n12 50\n13 51\n14 52\n15 53\n16 54\n17 55\n18 56\n19 57\n20 58\n21 59\n22 60\n23 61\n24 62\n25 63\n26 64\n27 65\n28 66\n29 67\n30 68\n31 69\n32 70\n33 71\n34 72\n35 73\n36 74\n37 75\n38 76" }, { "input": "78\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "1 40\n2 41\n3 42\n4 43\n5 44\n6 45\n7 46\n8 47\n9 48\n10 49\n11 50\n12 51\n13 52\n14 53\n15 54\n16 55\n17 56\n18 57\n19 58\n20 59\n21 60\n22 61\n23 62\n24 63\n25 64\n26 65\n27 66\n28 67\n29 68\n30 69\n31 70\n32 71\n33 72\n34 73\n35 74\n36 75\n37 76\n38 77\n39 78" }, { "input": "80\nLRLRRRRLRRRRLLLLRLLRLRLLRRLRLLLRRLLLLRLLLRLRLLRRRLRRRLRLRRRRRLRLLRLLRRLLLRLRRRLL", "output": "1 41\n2 42\n3 43\n4 44\n45 5\n46 6\n7 47\n8 48\n9 49\n50 10\n11 51\n12 52\n13 53\n14 54\n15 55\n16 56\n17 57\n18 58\n19 59\n20 60\n21 61\n62 22\n23 63\n24 64\n65 25\n26 66\n27 67\n68 28\n29 69\n30 70\n31 71\n72 32\n73 33\n34 74\n35 75\n36 76\n37 77\n38 78\n39 79\n40 80" }, { "input": "82\nRLRRLLRLRLRLLLRLLLRRLLRRLRRRRLLRLLLLRRRRRLLLRRRLLLLRLRRLRRRLRLLLLRRRLRLRLLLRLLLLLR", "output": "42 1\n2 43\n44 3\n4 45\n5 46\n6 47\n48 7\n8 49\n50 9\n10 51\n11 52\n12 53\n13 54\n14 55\n56 15\n16 57\n17 58\n18 59\n60 19\n20 61\n21 62\n22 63\n64 23\n65 24\n25 66\n26 67\n27 68\n69 28\n29 70\n30 71\n31 72\n73 32\n33 74\n34 75\n35 76\n36 77\n78 37\n79 38\n80 39\n81 40\n41 82" }, { "input": "84\nLRLRRRRRRLLLRLRLLLLLRRLRLRLRRRLLRLLLRLRLLLRRRLRLRRLRLRLLLLLLLLRRRRRRLLLRRLRLRLLLRLRR", "output": "1 43\n2 44\n3 45\n46 4\n5 47\n48 6\n7 49\n8 50\n51 9\n10 52\n11 53\n12 54\n55 13\n14 56\n57 15\n16 58\n17 59\n18 60\n19 61\n20 62\n21 63\n22 64\n23 65\n24 66\n25 67\n26 68\n27 69\n70 28\n71 29\n30 72\n31 73\n32 74\n33 75\n34 76\n35 77\n36 78\n79 37\n38 80\n39 81\n40 82\n41 83\n42 84" }, { "input": "86\nRRRLLLRLLRLLRLRLRLLLRLRLRRLLRLLLRLLLLLLRRRLRLLRLLLRRRLRLLLLRLLRLRRLLRLLLRRRLLRLRLLRLLR", "output": "1 44\n45 2\n46 3\n4 47\n5 48\n6 49\n50 7\n8 51\n9 52\n10 53\n11 54\n12 55\n56 13\n14 57\n58 15\n16 59\n17 60\n18 61\n19 62\n20 63\n64 21\n22 65\n23 66\n24 67\n68 25\n26 69\n27 70\n28 71\n72 29\n30 73\n31 74\n32 75\n76 33\n34 77\n35 78\n36 79\n37 80\n38 81\n39 82\n40 83\n84 41\n85 42\n43 86" }, { "input": "88\nLLRLRLRLLLLRRRRRRLRRLLLLLRRLRRLLLLLRLRLRLLLLLRLRLRRLRLRRLRLLRRLRLLLRLLLLRRLLRRLRLRLRRLRR", "output": "1 45\n2 46\n47 3\n4 48\n49 5\n6 50\n7 51\n8 52\n9 53\n10 54\n11 55\n12 56\n57 13\n14 58\n59 15\n60 16\n17 61\n18 62\n63 19\n20 64\n21 65\n22 66\n23 67\n24 68\n25 69\n70 26\n71 27\n28 72\n29 73\n30 74\n31 75\n32 76\n33 77\n34 78\n35 79\n36 80\n37 81\n38 82\n39 83\n40 84\n41 85\n42 86\n43 87\n44 88" }, { "input": "90\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 46\n2 47\n3 48\n4 49\n5 50\n6 51\n7 52\n8 53\n9 54\n10 55\n11 56\n12 57\n13 58\n14 59\n15 60\n16 61\n17 62\n18 63\n19 64\n20 65\n21 66\n22 67\n23 68\n24 69\n25 70\n26 71\n27 72\n28 73\n29 74\n30 75\n31 76\n32 77\n33 78\n34 79\n35 80\n36 81\n37 82\n38 83\n39 84\n40 85\n41 86\n42 87\n43 88\n44 89\n45 90" }, { "input": "92\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 47\n2 48\n3 49\n4 50\n5 51\n6 52\n7 53\n8 54\n9 55\n10 56\n11 57\n12 58\n13 59\n14 60\n15 61\n16 62\n17 63\n18 64\n19 65\n20 66\n21 67\n22 68\n23 69\n24 70\n25 71\n26 72\n27 73\n28 74\n29 75\n30 76\n31 77\n32 78\n33 79\n34 80\n35 81\n36 82\n37 83\n38 84\n39 85\n40 86\n41 87\n42 88\n43 89\n44 90\n45 91\n46 92" }, { "input": "94\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 48\n2 49\n3 50\n4 51\n5 52\n6 53\n7 54\n8 55\n9 56\n10 57\n11 58\n12 59\n13 60\n14 61\n15 62\n16 63\n17 64\n18 65\n19 66\n20 67\n21 68\n22 69\n23 70\n24 71\n25 72\n26 73\n27 74\n28 75\n29 76\n30 77\n31 78\n32 79\n33 80\n34 81\n35 82\n36 83\n37 84\n38 85\n39 86\n40 87\n41 88\n42 89\n43 90\n44 91\n45 92\n46 93\n47 94" }, { "input": "96\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 49\n2 50\n3 51\n4 52\n5 53\n6 54\n7 55\n8 56\n9 57\n10 58\n11 59\n12 60\n13 61\n14 62\n15 63\n16 64\n17 65\n18 66\n19 67\n20 68\n21 69\n22 70\n23 71\n24 72\n25 73\n26 74\n27 75\n28 76\n29 77\n30 78\n31 79\n32 80\n33 81\n34 82\n35 83\n36 84\n37 85\n38 86\n39 87\n40 88\n41 89\n42 90\n43 91\n44 92\n45 93\n46 94\n47 95\n48 96" }, { "input": "98\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL", "output": "1 50\n2 51\n3 52\n4 53\n5 54\n6 55\n7 56\n8 57\n9 58\n10 59\n11 60\n12 61\n13 62\n14 63\n15 64\n16 65\n17 66\n18 67\n19 68\n20 69\n21 70\n22 71\n23 72\n24 73\n25 74\n26 75\n27 76\n28 77\n29 78\n30 79\n31 80\n32 81\n33 82\n34 83\n35 84\n36 85\n37 86\n38 87\n39 88\n40 89\n41 90\n42 91\n43 92\n44 93\n45 94\n46 95\n47 96\n48 97\n49 98" }, { "input": "100\nRLRRRRLLLLRRRRLRRRRRRRRLRLRRLLRRRRRRRRLRRRRLLLLRRRRLRRLRLRRRLLRRLRRLLLRLRRLLLLLLRLRLRLRRLRLRLRRRLLLR", "output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n14 64\n15 65\n16 66\n17 67\n68 18\n69 19\n70 20\n21 71\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n78 28\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n86 36\n37 87\n38 88\n39 89\n40 90\n91 41\n42 92\n93 43\n44 94\n45 95\n46 96\n47 97\n98 48\n99 49\n50 100" }, { "input": "100\nLRLLLLRLLLLRRRRRLRRRRLRRLRRLRLLRRLRRRRLLRRRLLLRLLLRRRRLLRLRLRRLRLLRRLLRRLRRLRRRRRLRRLRLRLRLLLLLLLLRL", "output": "1 51\n2 52\n3 53\n4 54\n5 55\n6 56\n7 57\n8 58\n9 59\n10 60\n11 61\n12 62\n63 13\n14 64\n65 15\n66 16\n17 67\n18 68\n69 19\n70 20\n21 71\n22 72\n73 23\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n91 41\n92 42\n93 43\n44 94\n45 95\n46 96\n97 47\n48 98\n49 99\n50 100" }, { "input": "100\nLLLRRLLRLRLLLRLLLRLRLLRRRLRRLLLRLRLRRLLRLRRRLLLRRLLRLLRRLLRRRRRLRLRRLRLRRLRLRRLLRLRLLRLLLRLLRLLLLRLL", "output": "1 51\n2 52\n3 53\n54 4\n5 55\n6 56\n7 57\n58 8\n9 59\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n74 24\n25 75\n26 76\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n99 49\n50 100" }, { "input": "100\nRLLLLRRLLLLRRRRLLRLRRRLLLRLLRLLLLLRRLLLLLLRRLRRRRRLRLLRLRRRLLLRLRLRLLLRRRLLLLLRRRRRLRRLLLLRLLLRRLLLL", "output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n11 61\n62 12\n13 63\n64 14\n15 65\n16 66\n17 67\n68 18\n19 69\n70 20\n21 71\n22 72\n23 73\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n93 43\n94 44\n45 95\n46 96\n97 47\n98 48\n99 49\n100 50" }, { "input": "100\nRLRRLRLRRLRLLRLLRRRLRRLLLLLRLRLRRRRRRRLLRRRLLRLRLLLRRRLLRRRLLRLRLLLLRRLRLLRLLRLLLLRRLRLRRLRLLLLRLRRR", "output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n23 73\n24 74\n25 75\n26 76\n27 77\n28 78\n29 79\n80 30\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n93 43\n44 94\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100" }, { "input": "100\nLRRLRLRRRRRRLRRLRRLLLLLLRRLLRRLLRLLLLLLRRRLLRLRRRLLRLLRRLRRRLLRLRLLRRLRRRLLLRRRRLLRRRLLLRRRRRLLLLLLR", "output": "1 51\n2 52\n53 3\n4 54\n5 55\n6 56\n57 7\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n64 14\n15 65\n16 66\n67 17\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n24 74\n75 25\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n99 49\n50 100" }, { "input": "100\nRRLRRLRLRLRRRRLLRRLLRLRRLLRRRLLRLRRLRLRRLLLRRLLRRRRRRLLLRRRLLRRLLLLLLRLLLLLLRLLLRRRLRLLRRRRRLLRLLRRR", "output": "1 51\n2 52\n3 53\n54 4\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n64 14\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n73 23\n74 24\n25 75\n26 76\n27 77\n78 28\n79 29\n30 80\n31 81\n32 82\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100" }, { "input": "100\nRRLLLRLRRLRLLRRLRRRLLRRRLRRLLLLLLLLLRRRLLRLRRLRRLRRLRRLRLLLLRLLRRRLLLLRLRRRLLRRRRLRRLLRRRRLRRRLRLLLR", "output": "1 51\n52 2\n3 53\n4 54\n5 55\n6 56\n7 57\n58 8\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n69 19\n20 70\n21 71\n72 22\n23 73\n24 74\n25 75\n76 26\n77 27\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n49 99\n50 100" }, { "input": "100\nLLLLLRRLRRRRRRRLLRRRRRLRRLRLRLLRLRRLLLRRRRLLRRLRLLRLLLRLRLLRRRRRRRRRLRLLLRLRLLLLLRLRRRRLRLLRLRLRLRRL", "output": "1 51\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n17 67\n18 68\n69 19\n20 70\n71 21\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n28 78\n79 29\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n90 40\n91 41\n42 92\n43 93\n44 94\n95 45\n46 96\n47 97\n48 98\n49 99\n50 100" }, { "input": "100\nLLRRRLLLRLLLLRLRLRLRRRLLLRRRLRLLRLLLRRRRRLRRLRRLRRRLRRLRRLLLRLRLLRRRRLRLRRRRRLRRLRLLRRRRLLLRRRRRLLLL", "output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n70 20\n21 71\n72 22\n23 73\n24 74\n25 75\n26 76\n27 77\n78 28\n29 79\n30 80\n31 81\n32 82\n83 33\n34 84\n35 85\n36 86\n37 87\n38 88\n89 39\n90 40\n91 41\n42 92\n43 93\n44 94\n45 95\n46 96\n97 47\n48 98\n99 49\n100 50" } ]
1,648,645,941
2,147,483,647
Python 3
OK
TESTS
60
46
0
def solve() : s='' for i in range(n//2): if st[i]=='R' and st[n//2+i]=='L': s+=f'{n//2+i+1} {i+1}\n' else: s+=f'{i+1} {n//2+i+1}\n' s.strip() with open('output.txt','w') as f : f.write(s) return from sys import stdin input = stdin.readline with open('input.txt','r') as f : args=f.readlines() n=int(args[0]) st=args[1].strip() print(solve()) ''' t=int(input()) for i in range(t) : print(solve()) n=int(input()) x=input().strip() n,m= [int(x) for x in input().split()] n=int(input()) arr=[int(x) for x in input().split()] n,m= [int(x) for x in input().split()] arr=[] for i in range(n): arr.append([int(x) for x in input().split()]) n,m= [int(x) for x in input().split()] arr=[] for i in range(n): arr.append([x for x in input().strip()]) n=int(input()) arr=[] for i in range(n): arr.append([int(x) for x in input().split()]) '''
Title: Lefthanders and Righthanders Time Limit: None seconds Memory Limit: None megabytes Problem Description: One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*. But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave. On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other. Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists. Input Specification: The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. Output Specification: Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them. Demo Input: ['6\nLLRLLL\n', '4\nRRLL\n'] Demo Output: ['1 4\n2 5\n6 3\n', '3 1\n4 2\n'] Note: none
```python def solve() : s='' for i in range(n//2): if st[i]=='R' and st[n//2+i]=='L': s+=f'{n//2+i+1} {i+1}\n' else: s+=f'{i+1} {n//2+i+1}\n' s.strip() with open('output.txt','w') as f : f.write(s) return from sys import stdin input = stdin.readline with open('input.txt','r') as f : args=f.readlines() n=int(args[0]) st=args[1].strip() print(solve()) ''' t=int(input()) for i in range(t) : print(solve()) n=int(input()) x=input().strip() n,m= [int(x) for x in input().split()] n=int(input()) arr=[int(x) for x in input().split()] n,m= [int(x) for x in input().split()] arr=[] for i in range(n): arr.append([int(x) for x in input().split()]) n,m= [int(x) for x in input().split()] arr=[] for i in range(n): arr.append([x for x in input().strip()]) n=int(input()) arr=[] for i in range(n): arr.append([int(x) for x in input().split()]) ''' ```
3
735
D
Taxes
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while for *n*<==<=25 he needs to pay 5 and if *n*<==<=2 he pays only 1 burle. As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial *n* in several parts *n*1<=+<=*n*2<=+<=...<=+<=*n**k*<==<=*n* (here *k* is arbitrary, even *k*<==<=1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition *n**i*<=≥<=2 should hold for all *i* from 1 to *k*. Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split *n* in parts.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt.
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
[ "4\n", "27\n" ]
[ "2\n", "3\n" ]
none
1,750
[ { "input": "4", "output": "2" }, { "input": "27", "output": "3" }, { "input": "3", "output": "1" }, { "input": "5", "output": "1" }, { "input": "10", "output": "2" }, { "input": "2000000000", "output": "2" }, { "input": "26", "output": "2" }, { "input": "7", "output": "1" }, { "input": "2", "output": "1" }, { "input": "11", "output": "1" }, { "input": "1000000007", "output": "1" }, { "input": "1000000009", "output": "1" }, { "input": "1999999999", "output": "3" }, { "input": "1000000011", "output": "2" }, { "input": "101", "output": "1" }, { "input": "103", "output": "1" }, { "input": "1001", "output": "3" }, { "input": "1003", "output": "3" }, { "input": "10001", "output": "3" }, { "input": "10003", "output": "3" }, { "input": "129401294", "output": "2" }, { "input": "234911024", "output": "2" }, { "input": "192483501", "output": "3" }, { "input": "1234567890", "output": "2" }, { "input": "719241201", "output": "3" }, { "input": "9", "output": "2" }, { "input": "33", "output": "2" }, { "input": "25", "output": "2" }, { "input": "15", "output": "2" }, { "input": "147", "output": "3" }, { "input": "60119912", "output": "2" }, { "input": "45", "output": "2" }, { "input": "21", "output": "2" }, { "input": "9975", "output": "2" }, { "input": "17", "output": "1" }, { "input": "99", "output": "2" }, { "input": "49", "output": "2" }, { "input": "243", "output": "2" }, { "input": "43", "output": "1" }, { "input": "39", "output": "2" }, { "input": "6", "output": "2" }, { "input": "8", "output": "2" }, { "input": "12", "output": "2" }, { "input": "13", "output": "1" }, { "input": "14", "output": "2" }, { "input": "16", "output": "2" }, { "input": "18", "output": "2" }, { "input": "19", "output": "1" }, { "input": "20", "output": "2" }, { "input": "22", "output": "2" }, { "input": "23", "output": "1" }, { "input": "24", "output": "2" }, { "input": "962", "output": "2" }, { "input": "29", "output": "1" }, { "input": "55", "output": "2" }, { "input": "125", "output": "3" }, { "input": "1999999929", "output": "2" }, { "input": "493", "output": "2" }, { "input": "10000021", "output": "2" }, { "input": "541", "output": "1" }, { "input": "187", "output": "3" }, { "input": "95", "output": "3" }, { "input": "999991817", "output": "3" }, { "input": "37998938", "output": "2" }, { "input": "1847133842", "output": "2" }, { "input": "1000000005", "output": "3" }, { "input": "19828", "output": "2" }, { "input": "998321704", "output": "2" }, { "input": "370359", "output": "3" }, { "input": "115", "output": "2" }, { "input": "200000015", "output": "3" }, { "input": "479001600", "output": "2" }, { "input": "536870912", "output": "2" }, { "input": "10759922", "output": "2" }, { "input": "1999999927", "output": "1" }, { "input": "123", "output": "3" }, { "input": "200743933", "output": "3" }, { "input": "949575615", "output": "3" }, { "input": "99990001", "output": "1" }, { "input": "715827883", "output": "1" }, { "input": "5592406", "output": "2" }, { "input": "8388609", "output": "3" }, { "input": "1908903481", "output": "3" }, { "input": "1076153021", "output": "3" }, { "input": "344472101", "output": "3" } ]
1,603,260,053
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
140
0
import math #for i in range(1, 100+1): # print(i) n=int(input()) if n==2 or n==3: print(1) if n==4: print(2) if n>4: m1=True for i in range(4, n+1): c=True for j in range(2, int(math.sqrt(i))+1): if i%j==0: c=False break if c: d=n-i if d==0: print(1) break c1=True for k in range(2, int(math.sqrt(d))+1): if d%k==0: c1=False break if c1: m1=False #print(i, d) print(2) break if m1: print(3)
Title: Taxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while for *n*<==<=25 he needs to pay 5 and if *n*<==<=2 he pays only 1 burle. As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial *n* in several parts *n*1<=+<=*n*2<=+<=...<=+<=*n**k*<==<=*n* (here *k* is arbitrary, even *k*<==<=1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition *n**i*<=≥<=2 should hold for all *i* from 1 to *k*. Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split *n* in parts. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. Output Specification: Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. Demo Input: ['4\n', '27\n'] Demo Output: ['2\n', '3\n'] Note: none
```python import math #for i in range(1, 100+1): # print(i) n=int(input()) if n==2 or n==3: print(1) if n==4: print(2) if n>4: m1=True for i in range(4, n+1): c=True for j in range(2, int(math.sqrt(i))+1): if i%j==0: c=False break if c: d=n-i if d==0: print(1) break c1=True for k in range(2, int(math.sqrt(d))+1): if d%k==0: c1=False break if c1: m1=False #print(i, d) print(2) break if m1: print(3) ```
0
598
C
Nearest vectors
PROGRAMMING
2,300
[ "geometry", "sortings" ]
null
null
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors. The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=&gt;<=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
[ "4\n-1 0\n0 -1\n1 0\n1 1\n", "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n" ]
[ "3 4\n", "6 5" ]
none
0
[ { "input": "4\n-1 0\n0 -1\n1 0\n1 1", "output": "3 4" }, { "input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6", "output": "5 6" }, { "input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7", "output": "1 3" }, { "input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2", "output": "13 16" }, { "input": "2\n351 -4175\n-328 -657", "output": "2 1" }, { "input": "3\n620 -1189\n8101 -2770\n3347 3473", "output": "1 2" }, { "input": "4\n-7061 -5800\n-3471 -9470\n-7639 2529\n5657 -6522", "output": "1 2" }, { "input": "5\n-7519 -3395\n-32 -257\n-4827 -1889\n9545 -7037\n2767 583", "output": "3 1" }, { "input": "6\n-5120 -3251\n8269 -7984\n841 3396\n3136 -7551\n-1280 -3013\n-3263 -3278", "output": "1 6" }, { "input": "7\n-2722 6597\n-3303 200\n6508 -1021\n-1107 -1042\n6875 7616\n-3047 6749\n662 -1979", "output": "1 6" }, { "input": "8\n-36 749\n5126 943\n1165 533\n-1647 -5725\n5031 6532\n5956 8447\n2297 -2284\n1986 6937", "output": "5 6" }, { "input": "9\n-391 -1706\n995 -5756\n-5013 -154\n1121 3160\n-7111 8303\n-7303 -2414\n-7791 -935\n7576 -9361\n1072 203", "output": "3 7" }, { "input": "10\n-9920 -5477\n9691 -3200\n754 885\n-1895 1768\n-941 1588\n6293 -2631\n-2288 9129\n4067 696\n-6754 9869\n-5747 701", "output": "5 9" }, { "input": "2\n1 0\n-1 0", "output": "1 2" }, { "input": "2\n0 1\n0 -1", "output": "1 2" }, { "input": "2\n2131 -3249\n-2131 3249", "output": "2 1" }, { "input": "3\n-5 1\n-5 -1\n5 0", "output": "1 2" }, { "input": "3\n-100 1\n-100 -1\n0 100", "output": "1 2" }, { "input": "3\n1 10\n10 1\n10 -1", "output": "3 2" }, { "input": "3\n3 0\n0 3\n1 -3", "output": "3 1" }, { "input": "3\n1 1\n-1 0\n1 -1", "output": "3 1" }, { "input": "3\n-1 0\n10 -1\n1 0", "output": "2 3" }, { "input": "4\n1 10\n10 1\n-2 -2\n10 -1", "output": "4 2" }, { "input": "3\n-6 0\n6 1\n6 -1", "output": "3 2" }, { "input": "3\n114 1\n-514 0\n114 -1", "output": "3 1" }, { "input": "4\n-1 0\n0 -1\n-1 1\n1 0", "output": "3 1" }, { "input": "4\n2 1\n2 -1\n-1 1\n-1 -1", "output": "2 1" }, { "input": "3\n3 1\n3 -1\n0 3", "output": "2 1" }, { "input": "3\n1 1\n9000 1\n9000 -1", "output": "3 2" }, { "input": "3\n1 0\n-1 1\n-1 -1", "output": "2 3" }, { "input": "6\n1 1\n-1 -1\n0 20\n100 1\n-100 0\n100 -1", "output": "6 4" }, { "input": "4\n1 0\n0 1\n-1 0\n-13 -1", "output": "3 4" }, { "input": "3\n1 0\n-1 0\n1 -1", "output": "3 1" }, { "input": "3\n100 1\n-100 0\n100 -1", "output": "3 1" }, { "input": "3\n-100 1\n100 0\n-100 -1", "output": "1 3" }, { "input": "3\n1 100\n0 -100\n-1 100", "output": "1 3" }, { "input": "11\n-7945 386\n7504 -576\n-6020 -8277\n930 9737\n1682 474\n-8279 1197\n2790 2607\n-5514 -9601\n-3159 5939\n-1806 4207\n-9073 -2138", "output": "10 9" }, { "input": "3\n1 0\n10000 -1\n1 1", "output": "2 1" }, { "input": "4\n-7125 -1643\n-1235 4071\n-75 -8717\n2553 9278", "output": "4 2" }, { "input": "5\n-6 0\n6 1\n6 -1\n0 6\n0 -6", "output": "3 2" }, { "input": "4\n5 5\n5 -5\n-555 1\n-555 -1", "output": "3 4" }, { "input": "4\n1 1\n-1 1\n-1 -1\n2 -1", "output": "4 1" }, { "input": "4\n-1 -100\n1 -100\n-100 -100\n100 -100", "output": "1 2" }, { "input": "3\n1 0\n1 -1\n-4 -6", "output": "2 1" }, { "input": "4\n-1 -100\n1 -100\n100 -100\n-100 -100", "output": "1 2" }, { "input": "4\n-1 0\n0 -2\n-3 3\n4 0", "output": "3 1" }, { "input": "4\n-2 0\n0 -3\n-5 5\n4 0", "output": "3 1" }, { "input": "3\n1 -100\n0 100\n-1 -100", "output": "3 1" }, { "input": "5\n10000 2\n10000 -1\n10000 -5\n10000 -9\n10000 -13", "output": "2 1" }, { "input": "8\n-9580 8545\n-9379 -1139\n5824 -391\n-8722 2765\n-1357 -5547\n-7700 217\n9323 -7008\n957 -8356", "output": "6 2" }, { "input": "4\n5 5\n5 -5\n-500 1\n-500 -1", "output": "3 4" }, { "input": "3\n30 1\n30 -1\n0 30", "output": "2 1" }, { "input": "4\n3966 -1107\n8007 -5457\n-7753 4945\n-2209 -4221", "output": "2 1" }, { "input": "4\n1 9999\n0 1\n10000 0\n10000 -1", "output": "4 3" }, { "input": "3\n10000 1\n10000 -1\n-10000 0", "output": "2 1" }, { "input": "13\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n13 14\n12 13", "output": "12 13" }, { "input": "4\n2 1\n2 -1\n0 1\n-1 0", "output": "2 1" }, { "input": "4\n10 3\n10 -3\n-500 1\n-500 -1", "output": "3 4" }, { "input": "4\n1 10000\n-1 1\n10000 0\n10000 -1", "output": "4 3" }, { "input": "3\n0 1\n1 0\n1 -1", "output": "3 2" }, { "input": "3\n1 0\n0 1\n1 -1", "output": "3 1" }, { "input": "4\n1 1\n-1 1\n1 -2\n-1 -2", "output": "4 3" }, { "input": "4\n0 -1\n-1 0\n-1 1\n1 0", "output": "3 2" }, { "input": "3\n-100 1\n-100 -1\n1 1", "output": "1 2" }, { "input": "3\n-3 1\n-3 -1\n2 -3", "output": "1 2" }, { "input": "3\n1 -1\n1 0\n0 1", "output": "1 2" }, { "input": "5\n-5 1\n0 5\n4 1\n0 -4\n-5 -1", "output": "1 5" }, { "input": "4\n1 10000\n0 1\n10000 0\n9999 -1", "output": "1 2" }, { "input": "4\n2 3\n2 -3\n-3 2\n-3 -2", "output": "3 4" }, { "input": "3\n1 -3\n1 0\n0 1", "output": "1 2" }, { "input": "3\n1 0\n-1 0\n-1 -1", "output": "2 3" }, { "input": "4\n-2 1\n-2 -1\n1 1\n1 -1", "output": "1 2" }, { "input": "3\n1 -1\n-1 1\n-1 -2", "output": "3 1" }, { "input": "3\n1 0\n-1 -1\n1 -1", "output": "3 1" }, { "input": "3\n5 5\n-5 0\n5 -5", "output": "3 1" }, { "input": "4\n1 -2\n1 0\n-1 0\n10 -1", "output": "4 2" }, { "input": "3\n-1000 1\n-1000 -1\n1000 0", "output": "1 2" }, { "input": "6\n1 1\n1 -1\n-1 1\n-1 -1\n1 -10000\n-1 -10000", "output": "6 5" }, { "input": "3\n1 1\n-1 0\n0 -1", "output": "2 3" }, { "input": "4\n5000 1\n5000 -1\n-2 -1\n2 -1", "output": "2 1" }, { "input": "3\n1 0\n-1 1\n-1 -5", "output": "3 1" }, { "input": "3\n-5374 1323\n-4463 -8462\n6118 -7918", "output": "2 3" }, { "input": "4\n-6427 -6285\n-5386 -5267\n-3898 7239\n-3905 7252", "output": "4 3" }, { "input": "10\n-7 -3\n-2 8\n9 -9\n0 1\n4 5\n5 3\n-3 0\n10 2\n4 -1\n2 -10", "output": "4 2" }, { "input": "4\n9999 1\n9999 -1\n-9998 1\n-10000 -1", "output": "2 1" }, { "input": "4\n10000 9999\n9999 9998\n9998 9997\n9997 9996", "output": "2 1" }, { "input": "4\n-6285 -6427\n-5267 -5386\n7239 -3898\n7252 -3905", "output": "3 4" }, { "input": "4\n-6427 6285\n-5386 5267\n3898 -7239\n3905 -7252", "output": "4 3" }, { "input": "4\n-6427 -6285\n-5386 -5267\n-3898 -7239\n-3905 -7252", "output": "3 4" }, { "input": "3\n0 1\n-1 -1\n1 -1", "output": "2 3" }, { "input": "4\n10000 1\n9998 -1\n-9999 1\n-9999 -1", "output": "3 4" }, { "input": "3\n100 0\n100 2\n100 -1", "output": "3 1" }, { "input": "3\n-1 1\n-1 -1\n1 0", "output": "1 2" }, { "input": "4\n9844 9986\n181 9967\n-9812 -9925\n-194 -9900", "output": "1 2" }, { "input": "4\n9800 9981\n61 9899\n-9926 -9932\n-149 -9926", "output": "3 4" }, { "input": "4\n-9901 9900\n-10000 9899\n9899 9801\n9899 9900", "output": "3 4" }, { "input": "4\n9934 9989\n199 9949\n-9917 -9974\n-197 -9901", "output": "3 4" }, { "input": "3\n-1 1\n1 0\n-1 -1", "output": "1 3" }, { "input": "3\n1 1\n-10 -10\n-10 -9", "output": "3 2" }, { "input": "3\n1 0\n10000 -1\n-1 0", "output": "2 1" }, { "input": "4\n9999 1\n9999 -1\n-10000 1\n-10000 -1", "output": "3 4" }, { "input": "3\n-5 1\n-5 -1\n1 0", "output": "1 2" }, { "input": "3\n1 0\n10000 1\n-1 0", "output": "1 2" }, { "input": "4\n-9990 9995\n9994 -9991\n-9999 -9992\n9993 9992", "output": "2 4" }, { "input": "8\n1 0\n1 1\n0 1\n-1 1\n-1 0\n-1 -1\n0 -1\n1 -2", "output": "7 8" }, { "input": "3\n-9930 9932\n9909 -9909\n-9932 -9931", "output": "3 2" }, { "input": "4\n9876 9977\n127 9938\n-9820 -9934\n-120 -9921", "output": "3 4" }, { "input": "3\n10000 -1\n-1 0\n0 -1", "output": "3 1" }, { "input": "4\n6427 -6285\n5386 -5267\n3898 7239\n3905 7252", "output": "3 4" }, { "input": "4\n9811 9970\n155 9994\n-9826 -9977\n-159 -9986", "output": "1 2" }, { "input": "4\n9851 9917\n74 9921\n-9855 -9916\n-77 -9984", "output": "1 2" }, { "input": "4\n9826 9977\n159 9986\n-9811 -9970\n-155 -9994", "output": "3 4" }, { "input": "4\n9849 9986\n148 9980\n-9800 -9999\n-116 -9927", "output": "3 4" }, { "input": "4\n9822 9967\n111 9905\n-9943 -9986\n-163 -9953", "output": "1 2" }, { "input": "4\n9959 9995\n113 9940\n-9965 -9931\n-148 -9945", "output": "1 2" }, { "input": "4\n9851 9972\n153 9983\n-9866 -9926\n-183 -9946", "output": "1 2" }, { "input": "4\n9816 -9979\n127 -9940\n-9876 9915\n-190 9978", "output": "2 1" }, { "input": "4\n9887 -9917\n138 -9977\n-9826 9995\n-68 9971", "output": "2 1" }, { "input": "4\n9936 -9965\n135 -9949\n-9928 9980\n-123 9908", "output": "2 1" }, { "input": "4\n9981 -9985\n191 -9956\n-9893 9937\n-171 9962", "output": "2 1" }, { "input": "4\n-9811 9970\n-155 9994\n9826 -9977\n159 -9986", "output": "2 1" }, { "input": "4\n9808 9899\n179 9966\n-9870 -9961\n-179 -9950", "output": "3 4" }, { "input": "4\n9815 -9936\n168 -9937\n-9896 9995\n-180 9969", "output": "2 1" }, { "input": "4\n1 1\n1 -1\n-100 1\n-100 -1", "output": "3 4" }, { "input": "4\n9965 114\n87 9916\n-9957 -106\n-95 -9929", "output": "3 4" }, { "input": "4\n9895 -9949\n188 -9978\n-9810 9935\n-151 9914", "output": "2 1" }, { "input": "4\n-9957 106\n-95 9929\n9965 -114\n87 -9916", "output": "2 1" }, { "input": "4\n-9862 9980\n-174 9917\n9845 -9967\n173 -9980", "output": "2 1" }, { "input": "4\n9944 9926\n9927 9935\n-9961 -9929\n-9997 -9991", "output": "3 4" }, { "input": "4\n9917 9909\n196 9925\n-9971 -9991\n-183 -9977", "output": "3 4" } ]
1,665,208,755
3,555
PyPy 3-64
WRONG_ANSWER
TESTS
28
327
22,425,600
def main(): from sys import stdin, setrecursionlimit # setrecursionlimit(1000000) input = stdin.readline def iinput(): return int(input()) def sinput(): return input().rstrip() def i0input(): return int(input()) - 1 def linput(): return list(input().split()) def liinput(): return list(map(int, input().split())) def miinput(): return map(int, input().split()) def li0input(): return list(map(lambda x: int(x) - 1, input().split())) def mi0input(): return map(lambda x: int(x) - 1, input().split()) INF = 1000000000000000000 mm = 998244353937624761 from functools import cmp_to_key from math import sqrt def f(r1, r2): x1, y1 = r1 x2, y2 = r2 return x2 * y1 - y2 * x1 def ff(r1, r2): x1, y1, _ = r1 x2, y2, _ = r2 return x2 * y1 - y2 * x1 def cood_to_key(x, y): c = (x << 20) + y return c ^ mm cood = [] xy_to_i = dict() N = iinput() for i in range(1, N+1): x, y = miinput() cood.append((x, y)) xy_to_i[cood_to_key(x, y)] = i cood.sort(key=cmp_to_key(f)) cood_1 = [] cood_2 = [] for x, y in cood: if y == 0: if x > 0: cood_1.append((x, y)) else: cood_2.append((x, y)) elif y > 0: cood_1.append((x, y)) else: cood_2.append((x, y)) cood = cood_1 + cood_2 cood.append(cood[0]) res = [] for i in range(N): x1, y1 = cood[i] x2, y2 = cood[i+1] inp = x1 * x2 + y1 * y2 try: sgn = inp // abs(inp) except ZeroDivisionError: sgn = 0 norm = (x1 ** 2 + y1 ** 2) * (x2 ** 2 + y2 ** 2) res.append((norm, sgn * (inp) ** 2, i)) idx = max(res, key=cmp_to_key(ff))[2] x1, y1 = cood[idx] x2, y2 = cood[idx+1] # print(cood, idx) print(xy_to_i[cood_to_key(x1, y1)], xy_to_i[cood_to_key(x2, y2)]) main()
Title: Nearest vectors Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π. Input Specification: First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors. The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=&gt;<=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions). Output Specification: Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any. Demo Input: ['4\n-1 0\n0 -1\n1 0\n1 1\n', '6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n'] Demo Output: ['3 4\n', '6 5'] Note: none
```python def main(): from sys import stdin, setrecursionlimit # setrecursionlimit(1000000) input = stdin.readline def iinput(): return int(input()) def sinput(): return input().rstrip() def i0input(): return int(input()) - 1 def linput(): return list(input().split()) def liinput(): return list(map(int, input().split())) def miinput(): return map(int, input().split()) def li0input(): return list(map(lambda x: int(x) - 1, input().split())) def mi0input(): return map(lambda x: int(x) - 1, input().split()) INF = 1000000000000000000 mm = 998244353937624761 from functools import cmp_to_key from math import sqrt def f(r1, r2): x1, y1 = r1 x2, y2 = r2 return x2 * y1 - y2 * x1 def ff(r1, r2): x1, y1, _ = r1 x2, y2, _ = r2 return x2 * y1 - y2 * x1 def cood_to_key(x, y): c = (x << 20) + y return c ^ mm cood = [] xy_to_i = dict() N = iinput() for i in range(1, N+1): x, y = miinput() cood.append((x, y)) xy_to_i[cood_to_key(x, y)] = i cood.sort(key=cmp_to_key(f)) cood_1 = [] cood_2 = [] for x, y in cood: if y == 0: if x > 0: cood_1.append((x, y)) else: cood_2.append((x, y)) elif y > 0: cood_1.append((x, y)) else: cood_2.append((x, y)) cood = cood_1 + cood_2 cood.append(cood[0]) res = [] for i in range(N): x1, y1 = cood[i] x2, y2 = cood[i+1] inp = x1 * x2 + y1 * y2 try: sgn = inp // abs(inp) except ZeroDivisionError: sgn = 0 norm = (x1 ** 2 + y1 ** 2) * (x2 ** 2 + y2 ** 2) res.append((norm, sgn * (inp) ** 2, i)) idx = max(res, key=cmp_to_key(ff))[2] x1, y1 = cood[idx] x2, y2 = cood[idx+1] # print(cood, idx) print(xy_to_i[cood_to_key(x1, y1)], xy_to_i[cood_to_key(x2, y2)]) main() ```
0
99
B
Help Chef Gerasim
PROGRAMMING
1,300
[ "implementation", "sortings" ]
B. Help Chef Gerasim
0
256
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently. To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
[ "5\n270\n250\n250\n230\n250\n", "5\n250\n250\n250\n250\n250\n", "5\n270\n250\n249\n230\n250\n" ]
[ "20 ml. from cup #4 to cup #1.\n", "Exemplary pages.\n", "Unrecoverable configuration.\n" ]
none
1,000
[ { "input": "5\n270\n250\n250\n230\n250", "output": "20 ml. from cup #4 to cup #1." }, { "input": "5\n250\n250\n250\n250\n250", "output": "Exemplary pages." }, { "input": "5\n270\n250\n249\n230\n250", "output": "Unrecoverable configuration." }, { "input": "4\n200\n190\n210\n200", "output": "10 ml. from cup #2 to cup #3." }, { "input": "4\n1\n2\n3\n4", "output": "Unrecoverable configuration." }, { "input": "1\n0", "output": "Exemplary pages." }, { "input": "2\n0\n0", "output": "Exemplary pages." }, { "input": "2\n0\n1", "output": "Unrecoverable configuration." }, { "input": "2\n0\n2", "output": "1 ml. from cup #1 to cup #2." }, { "input": "2\n1\n0", "output": "Unrecoverable configuration." }, { "input": "2\n1\n1", "output": "Exemplary pages." }, { "input": "2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "2\n2\n0", "output": "1 ml. from cup #2 to cup #1." }, { "input": "2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "2\n2\n2", "output": "Exemplary pages." }, { "input": "3\n0\n0\n0", "output": "Exemplary pages." }, { "input": "3\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "3\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "3\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "3\n0\n1\n1", "output": "Unrecoverable configuration." }, { "input": "3\n0\n1\n2", "output": "1 ml. from cup #1 to cup #3." }, { "input": "3\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "3\n0\n2\n1", "output": "1 ml. from cup #1 to cup #2." }, { "input": "3\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "3\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "3\n1\n0\n1", "output": "Unrecoverable configuration." }, { "input": "3\n1\n0\n2", "output": "1 ml. from cup #2 to cup #3." }, { "input": "3\n1\n1\n0", "output": "Unrecoverable configuration." }, { "input": "3\n1\n1\n1", "output": "Exemplary pages." }, { "input": "3\n1\n1\n2", "output": "Unrecoverable configuration." }, { "input": "3\n1\n2\n0", "output": "1 ml. from cup #3 to cup #2." }, { "input": "3\n1\n2\n1", "output": "Unrecoverable configuration." }, { "input": "3\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "3\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "3\n2\n0\n1", "output": "1 ml. from cup #2 to cup #1." }, { "input": "3\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "3\n2\n1\n0", "output": "1 ml. from cup #3 to cup #1." }, { "input": "3\n2\n1\n1", "output": "Unrecoverable configuration." }, { "input": "3\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "3\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "3\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "3\n2\n2\n2", "output": "Exemplary pages." }, { "input": "4\n0\n0\n0\n0", "output": "Exemplary pages." }, { "input": "4\n0\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n1\n2", "output": "1 ml. from cup #1 to cup #4." }, { "input": "4\n0\n1\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n2\n1", "output": "1 ml. from cup #1 to cup #3." }, { "input": "4\n0\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n1\n1", "output": "1 ml. from cup #1 to cup #2." }, { "input": "4\n0\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n1\n2", "output": "1 ml. from cup #2 to cup #4." }, { "input": "4\n1\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n2\n1", "output": "1 ml. from cup #2 to cup #3." }, { "input": "4\n1\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n0\n2", "output": "1 ml. from cup #3 to cup #4." }, { "input": "4\n1\n1\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n1\n1", "output": "Exemplary pages." }, { "input": "4\n1\n1\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n2\n0", "output": "1 ml. from cup #4 to cup #3." }, { "input": "4\n1\n1\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n0\n1", "output": "1 ml. from cup #3 to cup #2." }, { "input": "4\n1\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n1\n0", "output": "1 ml. from cup #4 to cup #2." }, { "input": "4\n1\n2\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n1\n1", "output": "1 ml. from cup #2 to cup #1." }, { "input": "4\n2\n0\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n0\n1", "output": "1 ml. from cup #3 to cup #1." }, { "input": "4\n2\n1\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n1\n0", "output": "1 ml. from cup #4 to cup #1." }, { "input": "4\n2\n1\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n2\n2", "output": "Exemplary pages." }, { "input": "27\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n2626\n5599\n5599\n5599\n5599\n5599\n8572\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599", "output": "2973 ml. from cup #11 to cup #17." }, { "input": "98\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n1204\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n197\n702\n702\n702\n702\n702\n702\n702\n702\n702", "output": "Unrecoverable configuration." }, { "input": "54\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6859\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n5389\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124", "output": "735 ml. from cup #37 to cup #29." }, { "input": "50\n9636\n9678\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9596\n9636\n9636\n9636\n9636\n9636\n9636", "output": "Unrecoverable configuration." }, { "input": "19\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n82\n5001\n9919\n5001\n5001", "output": "Unrecoverable configuration." }, { "input": "74\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n3918\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n6742\n5330\n5330", "output": "1412 ml. from cup #36 to cup #72." } ]
1,658,178,629
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
import sys input = sys.stdin.readline n = int(input()) w = [int(input()) for _ in range(n)] x = sum(w)/n d = [] for i in range(n): if w[i] != x: d.append((w[i], i)) c = len(d) if c == 0: print('Exemplary pages.') elif c != 2: print('Unrecoverable configuration.') else: d.sort() if d[0][0] + d[1][0] == x*2: print(f'{x-d[0][0]} ml. from cup #{d[0][1]+1} to cup #{d[1][1]+1}.') else: print('Unrecoverable configuration.')
Title: Help Chef Gerasim Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently. To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. Input Specification: The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. Output Specification: If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). Demo Input: ['5\n270\n250\n250\n230\n250\n', '5\n250\n250\n250\n250\n250\n', '5\n270\n250\n249\n230\n250\n'] Demo Output: ['20 ml. from cup #4 to cup #1.\n', 'Exemplary pages.\n', 'Unrecoverable configuration.\n'] Note: none
```python import sys input = sys.stdin.readline n = int(input()) w = [int(input()) for _ in range(n)] x = sum(w)/n d = [] for i in range(n): if w[i] != x: d.append((w[i], i)) c = len(d) if c == 0: print('Exemplary pages.') elif c != 2: print('Unrecoverable configuration.') else: d.sort() if d[0][0] + d[1][0] == x*2: print(f'{x-d[0][0]} ml. from cup #{d[0][1]+1} to cup #{d[1][1]+1}.') else: print('Unrecoverable configuration.') ```
0
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe reposted PoLyCaRp\n" ]
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "output": "2" }, { "input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp", "output": "2" }, { "input": "1\niuNtwVf reposted POlYcarP", "output": "2" }, { "input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS", "output": "11" }, { "input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl", "output": "6" }, { "input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj", "output": "9" }, { "input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI", "output": "3" } ]
1,620,896,935
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
77
7,065,600
import random import math from collections import defaultdict import itertools from sys import stdin, stdout import operator def main(): z = '' #p = lambda *a: print(*a, flush = True) d = defaultdict() d['polycarp'] = [0, None] for _ in range(int(stdin.readline())): s = input().lower() m = s.split(' ') d[m[0]] = [0, m[2]] #print('polycarp' == m[2]) if d[m[2]][0] == 0: p = d[m[0]] while p[1] != None: d[p[1]][0] +=1 p = d[p[1]] print(d['polycarp'][0]+1) # z += str(ans) + '\n' # stdout.write(z) #for interactive problems #print("? {} {}".format(l,m), flush=True) #or print this after each print statement #sys.stdout.flush() if __name__ == "__main__": main()
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. Output Specification: Print a single integer — the maximum length of a repost chain. Demo Input: ['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n'] Demo Output: ['6\n', '2\n', '2\n'] Note: none
```python import random import math from collections import defaultdict import itertools from sys import stdin, stdout import operator def main(): z = '' #p = lambda *a: print(*a, flush = True) d = defaultdict() d['polycarp'] = [0, None] for _ in range(int(stdin.readline())): s = input().lower() m = s.split(' ') d[m[0]] = [0, m[2]] #print('polycarp' == m[2]) if d[m[2]][0] == 0: p = d[m[0]] while p[1] != None: d[p[1]][0] +=1 p = d[p[1]] print(d['polycarp'][0]+1) # z += str(ans) + '\n' # stdout.write(z) #for interactive problems #print("? {} {}".format(l,m), flush=True) #or print this after each print statement #sys.stdout.flush() if __name__ == "__main__": main() ```
0
839
A
Arya and Bran
PROGRAMMING
900
[ "implementation" ]
null
null
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
[ "2 3\n1 2\n", "3 17\n10 10 10\n", "1 9\n10\n" ]
[ "2", "3", "-1" ]
In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
500
[ { "input": "2 3\n1 2", "output": "2" }, { "input": "3 17\n10 10 10", "output": "3" }, { "input": "1 9\n10", "output": "-1" }, { "input": "10 70\n6 5 2 3 3 2 1 4 3 2", "output": "-1" }, { "input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "output": "18" }, { "input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "output": "30" }, { "input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47", "output": "40" }, { "input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9", "output": "-1" }, { "input": "37 30\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", "output": "30" }, { "input": "100 456\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "57" }, { "input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100", "output": "38" }, { "input": "7 43\n4 3 7 9 3 8 10", "output": "-1" }, { "input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8", "output": "-1" }, { "input": "30 177\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 8", "output": "-1" }, { "input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5", "output": "-1" }, { "input": "100 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": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69", "output": "13" }, { "input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53", "output": "85" }, { "input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5", "output": "100" }, { "input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6", "output": "98" }, { "input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1", "output": "18" }, { "input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2", "output": "21" }, { "input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1", "output": "-1" }, { "input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91", "output": "45" }, { "input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90", "output": "-1" }, { "input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50", "output": "97" }, { "input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9", "output": "24" }, { "input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42", "output": "21" }, { "input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100", "output": "1" }, { "input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5", "output": "13" }, { "input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92", "output": "14" }, { "input": "2 16\n10 6", "output": "2" }, { "input": "2 8\n7 8", "output": "2" }, { "input": "2 9\n4 8", "output": "2" }, { "input": "3 19\n9 9 1", "output": "3" }, { "input": "4 32\n9 9 9 5", "output": "4" }, { "input": "2 15\n14 1", "output": "2" }, { "input": "2 3\n3 3", "output": "1" }, { "input": "3 10\n10 1 1", "output": "2" }, { "input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4", "output": "4" }, { "input": "4 15\n14 3 3 3", "output": "2" }, { "input": "5 40\n10 10 10 10 1", "output": "5" }, { "input": "4 31\n9 9 8 5", "output": "4" }, { "input": "4 31\n20 7 1 1", "output": "-1" }, { "input": "2 10\n9 1", "output": "2" }, { "input": "10 50\n100 10 1 1 1 1 1 1 1 1", "output": "7" }, { "input": "2 11\n10 2", "output": "2" }, { "input": "3 21\n10 10 1", "output": "3" }, { "input": "2 2\n1 2", "output": "2" }, { "input": "3 2\n1 8 8", "output": "2" }, { "input": "2 11\n10 1", "output": "2" }, { "input": "2 16\n12 4", "output": "2" }, { "input": "3 11\n9 2 2", "output": "2" }, { "input": "3 11\n4 3 4", "output": "3" }, { "input": "2 13\n7 6", "output": "2" }, { "input": "3 24\n14 3 4", "output": "-1" }, { "input": "2 13\n10 3", "output": "2" }, { "input": "3 11\n9 2 1", "output": "2" }, { "input": "2 15\n12 3", "output": "2" }, { "input": "2 14\n11 4", "output": "2" } ]
1,693,758,712
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
a,b=map(int,input().split()) l=list(map(int,input().split())) k=0 f=0 ans=-1 for i in range(a): if b<=0: ans=i+1 break k+=l[i] if k>8: b-=8 k-=8 else: b-=k k=0 if i==a-1 and b<=0: print(a) else: print(ans)
Title: Arya and Bran Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Demo Input: ['2 3\n1 2\n', '3 17\n10 10 10\n', '1 9\n10\n'] Demo Output: ['2', '3', '-1'] Note: In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
```python a,b=map(int,input().split()) l=list(map(int,input().split())) k=0 f=0 ans=-1 for i in range(a): if b<=0: ans=i+1 break k+=l[i] if k>8: b-=8 k-=8 else: b-=k k=0 if i==a-1 and b<=0: print(a) else: print(ans) ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,681,477,235
2,147,483,647
Python 3
OK
TESTS
34
61
0
def seanddi(): n=int(input()) a=[int(i) for i in input().split()] l=0 r=n-1 s=s1=s2=0 while l<=r: if s%2==0: if a[r]<a[l]: s1+=a[l] l+=1 else: s1+=a[r] r-=1 else: if a[r]<a[l]: s2+=a[l] l+=1 else: s2+=a[r] r-=1 s+=1 print(s1,s2) seanddi()
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python def seanddi(): n=int(input()) a=[int(i) for i in input().split()] l=0 r=n-1 s=s1=s2=0 while l<=r: if s%2==0: if a[r]<a[l]: s1+=a[l] l+=1 else: s1+=a[r] r-=1 else: if a[r]<a[l]: s2+=a[l] l+=1 else: s2+=a[r] r-=1 s+=1 print(s1,s2) seanddi() ```
3
787
B
Not Afraid
PROGRAMMING
1,300
[ "greedy", "implementation", "math" ]
null
null
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick and one Morty. They're gathering in *m* groups. Each person can be in many groups and a group can contain an arbitrary number of members. Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn't considered this possibility). Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there's a group such that every member in that group is a traitor (they will plan and destroy the world). Summer knows that if there's a possibility that world ends (there's a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there's at least one scenario (among all 2*n* possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104) — number of universes and number of groups respectively. The next *m* lines contain the information about the groups. *i*-th of them first contains an integer *k* (number of times someone joined *i*-th group, *k*<=&gt;<=0) followed by *k* integers *v**i*,<=1,<=*v**i*,<=2,<=...,<=*v**i*,<=*k*. If *v**i*,<=*j* is negative, it means that Rick from universe number <=-<=*v**i*,<=*j* has joined this group and otherwise it means that Morty from universe number *v**i*,<=*j* has joined it. Sum of *k* for all groups does not exceed 104.
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
[ "4 2\n1 -3\n4 -2 3 2 -3\n", "5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n", "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
1,000
[ { "input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES" }, { "input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO" }, { "input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES" }, { "input": "2 1\n2 -2 2", "output": "NO" }, { "input": "7 7\n1 -2\n1 6\n2 7 -6\n2 -6 4\n2 -4 -6\n3 -5 7 -5\n1 -6", "output": "YES" }, { "input": "100 50\n2 62 -62\n2 19 -19\n2 38 -38\n2 -84 84\n2 -16 16\n2 67 -67\n2 41 -41\n2 -32 32\n2 32 -32\n2 -62 62\n2 89 -89\n2 -84 84\n2 96 -96\n2 -11 11\n2 59 -59\n2 -13 13\n2 -70 70\n2 -3 3\n2 -41 41\n2 -74 74\n2 47 -47\n2 87 -87\n2 17 -17\n2 20 -20\n2 -14 14\n2 -67 67\n2 -95 95\n2 -15 15\n2 -49 49\n2 75 -75\n2 -11 11\n2 -35 35\n2 -10 10\n2 -70 70\n2 -82 82\n2 33 -33\n2 14 -14\n2 -23 23\n2 83 -83\n2 21 -21\n2 86 -86\n2 -51 51\n2 -21 21\n2 -83 83\n2 94 -94\n2 -8 8\n2 75 -75\n2 69 -69\n2 -18 18\n2 42 -42", "output": "NO" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 1\n2 1 -1", "output": "NO" }, { "input": "1 50\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 1 -1\n2 1 -1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 -1 1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 1 -1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 -1 1\n2 1 -1\n2 -1 1\n2 1 -1\n2 1 -1\n2 1 -1\n2 -1 1\n2 -1 1\n2 -1 1", "output": "NO" }, { "input": "10000 1\n2 -6748 6748", "output": "NO" }, { "input": "10000 1\n1 2550", "output": "YES" }, { "input": "10000 1\n10 5365 -2216 -866 -7450 -6342 4329 -777 -4329 5225 -2884", "output": "NO" }, { "input": "3 1\n3 1 1 2", "output": "YES" }, { "input": "5 1\n2 -1 -1", "output": "YES" }, { "input": "4 1\n3 1 1 -1", "output": "NO" }, { "input": "4 1\n4 3 3 3 3", "output": "YES" }, { "input": "1 1\n2 1 1", "output": "YES" }, { "input": "2 1\n2 2 2", "output": "YES" }, { "input": "4 2\n2 1 -1\n1 1", "output": "YES" }, { "input": "7 2\n3 -1 1 7\n7 -5 4 2 4 7 -3 4", "output": "YES" }, { "input": "4 1\n1 -1", "output": "YES" }, { "input": "10 1\n2 4 4", "output": "YES" }, { "input": "1 2\n2 1 -1\n2 -1 -1", "output": "YES" }, { "input": "10000 1\n2 -3 -3", "output": "YES" }, { "input": "1 2\n2 1 1\n2 -1 -1", "output": "YES" }, { "input": "5 1\n2 1 1", "output": "YES" }, { "input": "3 1\n2 3 3", "output": "YES" }, { "input": "4 1\n2 1 1", "output": "YES" }, { "input": "4 2\n3 -1 1 2\n3 -2 4 3", "output": "YES" } ]
1,490,283,691
2,191
Python 3
OK
TESTS
65
78
6,348,800
import sys n, m = map(int, input().split()) a = [] for _ in range(m): a.append(set(map(int, input().split()[1:]))) for i in a: for j in i: if -j in i: break else: print("YES") sys.exit() print("NO")
Title: Not Afraid Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick and one Morty. They're gathering in *m* groups. Each person can be in many groups and a group can contain an arbitrary number of members. Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn't considered this possibility). Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there's a group such that every member in that group is a traitor (they will plan and destroy the world). Summer knows that if there's a possibility that world ends (there's a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there's at least one scenario (among all 2*n* possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end. Input Specification: The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104) — number of universes and number of groups respectively. The next *m* lines contain the information about the groups. *i*-th of them first contains an integer *k* (number of times someone joined *i*-th group, *k*<=&gt;<=0) followed by *k* integers *v**i*,<=1,<=*v**i*,<=2,<=...,<=*v**i*,<=*k*. If *v**i*,<=*j* is negative, it means that Rick from universe number <=-<=*v**i*,<=*j* has joined this group and otherwise it means that Morty from universe number *v**i*,<=*j* has joined it. Sum of *k* for all groups does not exceed 104. Output Specification: In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise. Demo Input: ['4 2\n1 -3\n4 -2 3 2 -3\n', '5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n', '7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
```python import sys n, m = map(int, input().split()) a = [] for _ in range(m): a.append(set(map(int, input().split()[1:]))) for i in a: for j in i: if -j in i: break else: print("YES") sys.exit() print("NO") ```
3
221
A
Little Elephant and Function
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists.
[ "1\n", "2\n" ]
[ "1 ", "2 1 " ]
none
500
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "2 1 " }, { "input": "3", "output": "3 1 2 " }, { "input": "4", "output": "4 1 2 3 " }, { "input": "5", "output": "5 1 2 3 4 " }, { "input": "6", "output": "6 1 2 3 4 5 " }, { "input": "7", "output": "7 1 2 3 4 5 6 " }, { "input": "1000", "output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "999", "output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "998", "output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "997", "output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "900", "output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "101", "output": "101 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 " }, { "input": "3", "output": "3 1 2 " }, { "input": "67", "output": "67 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 " }, { "input": "779", "output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "195", "output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "907", "output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "971", "output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "683", "output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "99", "output": "99 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 " }, { "input": "811", "output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "875", "output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "291", "output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3", "output": "3 1 2 " }, { "input": "419", "output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "779", "output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "195", "output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "907", "output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "21", "output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 " }, { "input": "22", "output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 " }, { "input": "23", "output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 " }, { "input": "24", "output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 " }, { "input": "25", "output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 " } ]
1,684,932,218
2,147,483,647
Python 3
OK
TESTS
34
92
0
""" Logic: 1. function keeps calling itself till 1, then swaps from 1 to n 2. so max element should be 1st element, then rest should be in ascending order """ n = int(input()) lst = [str(i) for i in range(1, n)] print(str(n), " ".join(lst))
Title: Little Elephant and Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. Output Specification: In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Demo Input: ['1\n', '2\n'] Demo Output: ['1 ', '2 1 '] Note: none
```python """ Logic: 1. function keeps calling itself till 1, then swaps from 1 to n 2. so max element should be 1st element, then rest should be in ascending order """ n = int(input()) lst = [str(i) for i in range(1, n)] print(str(n), " ".join(lst)) ```
3
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,689,194,795
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1689194794.809438")# 1689194794.809485
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
```python print("_RANDOM_GUESS_1689194794.809438")# 1689194794.809485 ```
0
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,694,842,992
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input("n')) s=input("string") fs="" if s.islower()==True and s.isalpha()==True: for i in range(n-1): if i==(n-1): fs+=s else: inx=s.index('\n') word=s[0]+str(inx-2)+s[inx-1] fs+=word+'\n' s=s[inx+1:] print(fs)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n=int(input("n')) s=input("string") fs="" if s.islower()==True and s.isalpha()==True: for i in range(n-1): if i==(n-1): fs+=s else: inx=s.index('\n') word=s[0]+str(inx-2)+s[inx-1] fs+=word+'\n' s=s[inx+1:] print(fs) ```
-1
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,553,875,601
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
18
124
0
str=input() nc=str.count('n') ic=str.count('i') tc=str.count('t') ec=str.count("e") print(min((nc-1)//2,ec//3,ic,tc))
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python str=input() nc=str.count('n') ic=str.count('i') tc=str.count('t') ec=str.count("e") print(min((nc-1)//2,ec//3,ic,tc)) ```
0
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "output": "840" }, { "input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "output": "922" }, { "input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "output": "674" }, { "input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "output": "848" }, { "input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "output": "902" }, { "input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "output": "798" }, { "input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "output": "632" }, { "input": "1\n4", "output": "4" }, { "input": "2\n1 4", "output": "4" }, { "input": "3\n1 2 4", "output": "6" }, { "input": "2\n9 3", "output": "12" }, { "input": "2\n1000000000 1001", "output": "1000000000" }, { "input": "3\n1 8 4", "output": "12" }, { "input": "3\n7 4 4", "output": "8" }, { "input": "5\n2 3 4 5 3", "output": "14" }, { "input": "2\n4 5", "output": "4" }, { "input": "3\n2 4 5", "output": "6" }, { "input": "3\n2 2 3", "output": "4" }, { "input": "2\n2 3", "output": "2" }, { "input": "4\n2 3 7 7", "output": "16" }, { "input": "2\n999999999 2", "output": "2" }, { "input": "2\n2 5", "output": "2" }, { "input": "3\n5 3 1", "output": "8" }, { "input": "4\n3 2 5 7", "output": "14" } ]
1,578,588,724
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
n = int(input()) result = 0 minOdd = 99999999 i = 1 while(i <= n): num = int(input()) if(num % 2 != 0): minOdd = min(minOdd, num) result = result + num i = i + 1 if(result % 2 == 0): print(result) else: print(result - minOdd)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. Input Specification: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Specification: Print the maximum possible even sum that can be obtained if we use some of the given integers. Demo Input: ['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n'] Demo Output: ['6', '3999999996'] Note: In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
```python n = int(input()) result = 0 minOdd = 99999999 i = 1 while(i <= n): num = int(input()) if(num % 2 != 0): minOdd = min(minOdd, num) result = result + num i = i + 1 if(result % 2 == 0): print(result) else: print(result - minOdd) ```
-1
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,592,992,856
2,147,483,647
Python 3
OK
TESTS
102
124
6,758,400
a=input() b=input() n=len(a) a=int(a,2) b=int(b,2) r=bin(a^b)[2:] print('0'*(n-len(r))+str(r))
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 a=input() b=input() n=len(a) a=int(a,2) b=int(b,2) r=bin(a^b)[2:] print('0'*(n-len(r))+str(r)) ```
3.956411
687
A
NP-Hard Problem
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges.
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty.
[ "4 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n" ]
[ "1\n2 \n2\n1 3 \n", "-1\n" ]
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
500
[ { "input": "4 2\n1 2\n2 3", "output": "1\n2 \n2\n1 3 " }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "-1" }, { "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "output": "-1" }, { "input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "output": "-1" }, { "input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1", "output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 " }, { "input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3", "output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 " }, { "input": "10 17\n5 1\n8 1\n2 1\n2 6\n3 1\n5 7\n3 7\n8 6\n4 7\n2 7\n9 7\n10 7\n3 6\n4 1\n9 1\n8 7\n10 1", "output": "7\n5 3 2 8 4 9 10 \n3\n1 7 6 " }, { "input": "10 15\n5 9\n7 8\n2 9\n1 9\n3 8\n3 9\n5 8\n1 8\n6 9\n7 9\n4 8\n4 9\n10 9\n10 8\n6 8", "output": "2\n9 8 \n8\n1 5 7 3 4 10 6 2 " }, { "input": "10 9\n4 9\n1 9\n10 9\n2 9\n3 9\n6 9\n5 9\n7 9\n8 9", "output": "1\n9 \n9\n1 4 10 2 3 6 5 7 8 " }, { "input": "2 1\n1 2", "output": "1\n2 \n1\n1 " }, { "input": "10 10\n6 4\n9 1\n3 6\n6 7\n4 2\n9 6\n8 6\n5 7\n1 4\n6 10", "output": "6\n9 4 3 7 8 10 \n4\n1 6 2 5 " }, { "input": "20 22\n20 8\n1 3\n3 18\n14 7\n19 6\n7 20\n14 8\n8 10\n2 5\n11 2\n4 19\n14 2\n7 11\n15 1\n12 15\n7 6\n11 13\n1 16\n9 12\n1 19\n17 3\n11 20", "output": "-1" }, { "input": "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15", "output": "-1" }, { "input": "1000 1\n839 771", "output": "1\n839 \n1\n771 " }, { "input": "1000 1\n195 788", "output": "1\n788 \n1\n195 " }, { "input": "100000 1\n42833 64396", "output": "1\n64396 \n1\n42833 " }, { "input": "100000 1\n26257 21752", "output": "1\n26257 \n1\n21752 " }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "-1" } ]
1,498,828,892
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
842
16,896,000
n,m=map(int,input().split()) l=[[] for i in range(n+1)] for i in range(m) : a,b=map(int,input().split()) l[a].append(b) l[b].append(a) z=[-1]*(n+1) v=[-1]*(n+1) g=[a] l1=[a] l2=[] v[a]=1 while len(g)>0 : for x in l[g[0]] : if v[x]==-1 : if v[g[0]]==1 : v[x]=2 l2.append(x) z[x]=g[0] g.append(x) else : v[x]=1 l1.append(x) z[x]=g[0] g.append(x) else : if v[x]==v[g[0]] : print(-1) exit() del(g[0]) print(len(l1)) print(*l1) print(len(l2)) print(*l2)
Title: NP-Hard Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. Output Specification: If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. Demo Input: ['4 2\n1 2\n2 3\n', '3 3\n1 2\n2 3\n1 3\n'] Demo Output: ['1\n2 \n2\n1 3 \n', '-1\n'] Note: In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
```python n,m=map(int,input().split()) l=[[] for i in range(n+1)] for i in range(m) : a,b=map(int,input().split()) l[a].append(b) l[b].append(a) z=[-1]*(n+1) v=[-1]*(n+1) g=[a] l1=[a] l2=[] v[a]=1 while len(g)>0 : for x in l[g[0]] : if v[x]==-1 : if v[g[0]]==1 : v[x]=2 l2.append(x) z[x]=g[0] g.append(x) else : v[x]=1 l1.append(x) z[x]=g[0] g.append(x) else : if v[x]==v[g[0]] : print(-1) exit() del(g[0]) print(len(l1)) print(*l1) print(len(l2)) print(*l2) ```
0
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output the only number — answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 2\n2 4\n1 4", "output": "8" }, { "input": "2 3\n1 7\n1 2\n1 5", "output": "12" }, { "input": "4 1\n2 2", "output": "4" }, { "input": "4 2\n1 10\n4 4", "output": "22" }, { "input": "4 3\n1 4\n6 4\n1 7", "output": "19" }, { "input": "5 1\n10 5", "output": "25" }, { "input": "5 2\n3 9\n2 2", "output": "31" }, { "input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "output": "42" }, { "input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7", "output": "41" }, { "input": "10 1\n9 4", "output": "36" }, { "input": "10 2\n14 3\n1 3", "output": "30" }, { "input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10", "output": "71" }, { "input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4", "output": "70" }, { "input": "10 4\n1 5\n5 2\n1 9\n3 3", "output": "33" }, { "input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4", "output": "716" }, { "input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4", "output": "8218" }, { "input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10", "output": "84715" }, { "input": "100000 3\n2975 2\n35046 4\n61979 9", "output": "703945" }, { "input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9", "output": "8794569" }, { "input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3", "output": "85022733" }, { "input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5", "output": "749254060" }, { "input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3", "output": "1332923354" }, { "input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5", "output": "996523209" }, { "input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6", "output": "630991750" }, { "input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8", "output": "931584598" }, { "input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6", "output": "1447294907" }, { "input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1", "output": "1634907859" }, { "input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10", "output": "1305347138" }, { "input": "200000000 3\n65170000 7\n20790088 1\n74616133 4", "output": "775444620" }, { "input": "200000000 2\n11823018 6\n100000000 9", "output": "970938108" }, { "input": "200000000 1\n100000000 6", "output": "600000000" }, { "input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5", "output": "1152034197" }, { "input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6", "output": "1095537357" }, { "input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5", "output": "83" }, { "input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10", "output": "54980855" }, { "input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6", "output": "939368573" }, { "input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5", "output": "1158946383" }, { "input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3", "output": "1131379312" }, { "input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9", "output": "79" }, { "input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7", "output": "45116295" }, { "input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6", "output": "1489289257" }, { "input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3", "output": "961871671" }, { "input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4", "output": "664376069" } ]
1,623,226,789
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
#%% ints = lambda x, f: f(map(int, x.split(" "))) cons = ints(input(), list) ins = [] for i in range(cons[1]): ins.append(ints(input(), tuple)) s = lambda x: x[0] * x[1] ins.sort(key=s, reverse=True) sack = 0 i = 0 while cons[0] > 0 and i < len(ins): if ins[i][0] <= cons[0]: cons[0] -= ins[i][0] sack += (ins[i][0] * ins[i][1]) i+=1 print(sack)
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. Output Specification: Output the only number — answer to the problem. Demo Input: ['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n'] Demo Output: ['62\n', '7\n'] Note: none
```python #%% ints = lambda x, f: f(map(int, x.split(" "))) cons = ints(input(), list) ins = [] for i in range(cons[1]): ins.append(ints(input(), tuple)) s = lambda x: x[0] * x[1] ins.sort(key=s, reverse=True) sack = 0 i = 0 while cons[0] > 0 and i < len(ins): if ins[i][0] <= cons[0]: cons[0] -= ins[i][0] sack += (ins[i][0] * ins[i][1]) i+=1 print(sack) ```
0
524
A
Возможно, вы знаете этих людей?
PROGRAMMING
1,600
[ "implementation" ]
null
null
Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*. В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую вероятность быть знакомыми для пользователя. Эта функция работает следующим образом. Зафиксируем пользователя *x*. Пусть некоторый другой человек *y*, не являющийся другом *x* на текущий момент, является другом не менее, чем для *k*% друзей *x*. Тогда он является предполагаемым другом для *x*. У каждого человека в социальной сети есть свой уникальный идентификатор — это целое число от 1 до 109. Вам дан список пар пользователей, являющихся друзьями. Определите для каждого упомянутого пользователя множество его предполагаемых друзей.
В первой строке следуют два целых числа *m* и *k* (1<=≤<=*m*<=≤<=100, 0<=≤<=*k*<=≤<=100) — количество пар друзей и необходимый процент общих друзей для того, чтобы считаться предполагаемым другом. В последующих *m* строках записано по два числа *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109, *a**i*<=≠<=*b**i*), обозначающих идентификаторы пользователей, являющихся друзьями. Гарантируется, что каждая пара людей фигурирует в списке не более одного раза.
Для всех упомянутых людей в порядке возрастания id выведите информацию о предполагаемых друзьях. Информация должна иметь вид "*id*:<= *k* *id*1 *id*2 ... *id**k*", где *id* — это id самого человека, *k* — количество его предполагаемых друзей, а *id*1, *id*2, ..., *id**k* — идентификаторы его предполагаемых друзей в возрастающем порядке.
[ "5 51\n10 23\n23 42\n39 42\n10 39\n39 58\n", "5 100\n1 2\n1 3\n1 4\n2 3\n2 4\n" ]
[ "10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42\n", "1: 0\n2: 0\n3: 1 4\n4: 1 3\n" ]
none
500
[ { "input": "5 51\n10 23\n23 42\n39 42\n10 39\n39 58", "output": "10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42" }, { "input": "5 100\n1 2\n1 3\n1 4\n2 3\n2 4", "output": "1: 0\n2: 0\n3: 1 4\n4: 1 3" }, { "input": "4 1\n1 2\n1 3\n2 3\n4 5", "output": "1: 0\n2: 0\n3: 0\n4: 0\n5: 0" }, { "input": "10 0\n648169314 459970755\n973677547 255163231\n982998000 498743911\n959912791 891928\n404623428 891928\n474720235 271683165\n709045873 539751127\n973677547 179588015\n629049356 622519100\n624998275 958914560", "output": "891928: 15 179588015 255163231 271683165 459970755 474720235 498743911 539751127 622519100 624998275 629049356 648169314 709045873 958914560 973677547 982998000\n179588015: 16 891928 255163231 271683165 404623428 459970755 474720235 498743911 539751127 622519100 624998275 629049356 648169314 709045873 958914560 959912791 982998000\n255163231: 16 891928 179588015 271683165 404623428 459970755 474720235 498743911 539751127 622519100 624998275 629049356 648169314 709045873 958914560 959912791 982998000\n27168..." }, { "input": "10 100\n60976680 603454792\n575754027 696647370\n7534463 570826751\n117972518 472387015\n35713567 439985965\n439985965 928160845\n443596853 828504858\n689509731 117972518\n909843480 592765058\n251752353 490387136", "output": "7534463: 0\n35713567: 1 928160845\n60976680: 0\n117972518: 0\n251752353: 0\n439985965: 0\n443596853: 0\n472387015: 1 689509731\n490387136: 0\n570826751: 0\n575754027: 0\n592765058: 0\n603454792: 0\n689509731: 1 472387015\n696647370: 0\n828504858: 0\n909843480: 0\n928160845: 1 35713567" }, { "input": "10 50\n389900784 512305545\n839319681 243581524\n653226215 616982889\n448655722 826601897\n681021965 23289895\n719595063 481480420\n919744525 839319681\n231872856 784056465\n971842495 248017394\n653226215 297224467", "output": "23289895: 0\n231872856: 0\n243581524: 1 919744525\n248017394: 0\n297224467: 1 616982889\n389900784: 0\n448655722: 0\n481480420: 0\n512305545: 0\n616982889: 1 297224467\n653226215: 0\n681021965: 0\n719595063: 0\n784056465: 0\n826601897: 0\n839319681: 0\n919744525: 1 243581524\n971842495: 0" }, { "input": "10 0\n180745113 666631448\n362104151 349631376\n214251560 538865550\n562805929 576329835\n64121410 646478528\n283223383 861810719\n773038401 214251560\n64208401 693054606\n493180926 960545197\n159614568 831490031", "output": "64121410: 17 64208401 159614568 180745113 214251560 283223383 349631376 362104151 493180926 538865550 562805929 576329835 666631448 693054606 773038401 831490031 861810719 960545197\n64208401: 17 64121410 159614568 180745113 214251560 283223383 349631376 362104151 493180926 538865550 562805929 576329835 646478528 666631448 773038401 831490031 861810719 960545197\n159614568: 17 64121410 64208401 180745113 214251560 283223383 349631376 362104151 493180926 538865550 562805929 576329835 646478528 666631448 693..." }, { "input": "10 50\n946010975 207263044\n923545573 749203275\n862015642 426425906\n749203275 839134958\n910721783 289091881\n827003531 333726912\n49704846 538788252\n382891592 207263044\n333726912 438209022\n974360048 49704846", "output": "49704846: 0\n207263044: 0\n289091881: 0\n333726912: 0\n382891592: 1 946010975\n426425906: 0\n438209022: 1 827003531\n538788252: 1 974360048\n749203275: 0\n827003531: 1 438209022\n839134958: 1 923545573\n862015642: 0\n910721783: 0\n923545573: 1 839134958\n946010975: 1 382891592\n974360048: 1 538788252" }, { "input": "10 100\n570936669 651631651\n508122950 793810569\n374422919 757639639\n395046911 359158844\n544971368 55608511\n554227847 109843524\n199021332 421407912\n82125712 395046911\n923097829 637659245\n754413496 971876441", "output": "55608511: 0\n82125712: 1 359158844\n109843524: 0\n199021332: 0\n359158844: 1 82125712\n374422919: 0\n395046911: 0\n421407912: 0\n508122950: 0\n544971368: 0\n554227847: 0\n570936669: 0\n637659245: 0\n651631651: 0\n754413496: 0\n757639639: 0\n793810569: 0\n923097829: 0\n971876441: 0" }, { "input": "1 0\n42 23", "output": "23: 0\n42: 0" }, { "input": "1 1\n42 23", "output": "23: 0\n42: 0" }, { "input": "1 50\n42 23", "output": "23: 0\n42: 0" }, { "input": "1 99\n42 23", "output": "23: 0\n42: 0" }, { "input": "1 100\n42 23", "output": "23: 0\n42: 0" }, { "input": "2 49\n42 23\n23 14", "output": "14: 1 42\n23: 0\n42: 1 14" }, { "input": "2 50\n42 23\n23 19", "output": "19: 1 42\n23: 0\n42: 1 19" }, { "input": "2 51\n42 23\n23 19", "output": "19: 1 42\n23: 0\n42: 1 19" }, { "input": "3 49\n42 23\n23 19\n32 23", "output": "19: 2 32 42\n23: 0\n32: 2 19 42\n42: 2 19 32" }, { "input": "3 50\n42 23\n23 19\n32 23", "output": "19: 2 32 42\n23: 0\n32: 2 19 42\n42: 2 19 32" }, { "input": "3 51\n42 23\n23 19\n32 23", "output": "19: 2 32 42\n23: 0\n32: 2 19 42\n42: 2 19 32" }, { "input": "10 50\n642733947 618790811\n508838679 118350938\n175990043 144671010\n246628250 434416712\n77433126 913934904\n414906480 399777199\n252618318 930317425\n316103842 356219969\n530311152 441130575\n15047025 839165125", "output": "15047025: 0\n77433126: 0\n118350938: 0\n144671010: 0\n175990043: 0\n246628250: 0\n252618318: 0\n316103842: 0\n356219969: 0\n399777199: 0\n414906480: 0\n434416712: 0\n441130575: 0\n508838679: 0\n530311152: 0\n618790811: 0\n642733947: 0\n839165125: 0\n913934904: 0\n930317425: 0" }, { "input": "10 0\n106531296 450097353\n947110486 953723914\n774225709 111023810\n774225709 642354614\n559826213 258125349\n768234906 870027419\n4234645 388060649\n870027419 545107061\n484961505 497401821\n76024092 367527096", "output": "4234645: 16 76024092 106531296 111023810 258125349 367527096 450097353 484961505 497401821 545107061 559826213 642354614 768234906 774225709 870027419 947110486 953723914\n76024092: 16 4234645 106531296 111023810 258125349 388060649 450097353 484961505 497401821 545107061 559826213 642354614 768234906 774225709 870027419 947110486 953723914\n106531296: 16 4234645 76024092 111023810 258125349 367527096 388060649 484961505 497401821 545107061 559826213 642354614 768234906 774225709 870027419 947110486 953723..." }, { "input": "10 50\n384319275 425419607\n201879842 153061155\n308316219 268723666\n20837191 401468340\n969142307 78803322\n55247385 365896022\n479817129 222255243\n980789245 697120853\n550086907 652472194\n203728124 229637404", "output": "20837191: 0\n55247385: 0\n78803322: 0\n153061155: 0\n201879842: 0\n203728124: 0\n222255243: 0\n229637404: 0\n268723666: 0\n308316219: 0\n365896022: 0\n384319275: 0\n401468340: 0\n425419607: 0\n479817129: 0\n550086907: 0\n652472194: 0\n697120853: 0\n969142307: 0\n980789245: 0" }, { "input": "10 100\n620468113 665248777\n541840309 963681159\n144393749 136223789\n800116851 648535048\n730845154 277782209\n142473309 2838660\n14940106 355463174\n745034887 545886019\n570717131 701899093\n250611530 857683655", "output": "2838660: 0\n14940106: 0\n136223789: 0\n142473309: 0\n144393749: 0\n250611530: 0\n277782209: 0\n355463174: 0\n541840309: 0\n545886019: 0\n570717131: 0\n620468113: 0\n648535048: 0\n665248777: 0\n701899093: 0\n730845154: 0\n745034887: 0\n800116851: 0\n857683655: 0\n963681159: 0" }, { "input": "5 66\n4242 1\n4242 2\n4242 3\n2323 1\n2323 2", "output": "1: 1 2\n2: 1 1\n3: 2 1 2\n2323: 1 4242\n4242: 1 2323" }, { "input": "5 67\n4242 1\n4242 2\n4242 3\n2323 1\n2323 2", "output": "1: 1 2\n2: 1 1\n3: 2 1 2\n2323: 1 4242\n4242: 0" }, { "input": "6 49\n4242 1\n4242 2\n4242 3\n4242 4\n2323 1\n2323 2", "output": "1: 3 2 3 4\n2: 3 1 3 4\n3: 3 1 2 4\n4: 3 1 2 3\n2323: 1 4242\n4242: 1 2323" }, { "input": "6 50\n4242 1\n4242 2\n4242 3\n4242 4\n2323 1\n2323 2", "output": "1: 3 2 3 4\n2: 3 1 3 4\n3: 3 1 2 4\n4: 3 1 2 3\n2323: 1 4242\n4242: 1 2323" }, { "input": "6 51\n4242 1\n4242 2\n4242 3\n4242 4\n2323 1\n2323 2", "output": "1: 1 2\n2: 1 1\n3: 3 1 2 4\n4: 3 1 2 3\n2323: 1 4242\n4242: 0" }, { "input": "11 12\n4242 1\n4242 2\n4242 3\n4242 4\n4242 5\n4242 6\n4242 7\n4242 8\n2323 1\n2323 2\n2323 3", "output": "1: 7 2 3 4 5 6 7 8\n2: 7 1 3 4 5 6 7 8\n3: 7 1 2 4 5 6 7 8\n4: 7 1 2 3 5 6 7 8\n5: 7 1 2 3 4 6 7 8\n6: 7 1 2 3 4 5 7 8\n7: 7 1 2 3 4 5 6 8\n8: 7 1 2 3 4 5 6 7\n2323: 1 4242\n4242: 1 2323" }, { "input": "11 13\n4242 1\n4242 2\n4242 3\n4242 4\n4242 5\n4242 6\n4242 7\n4242 8\n2323 1\n2323 2\n2323 3", "output": "1: 7 2 3 4 5 6 7 8\n2: 7 1 3 4 5 6 7 8\n3: 7 1 2 4 5 6 7 8\n4: 7 1 2 3 5 6 7 8\n5: 7 1 2 3 4 6 7 8\n6: 7 1 2 3 4 5 7 8\n7: 7 1 2 3 4 5 6 8\n8: 7 1 2 3 4 5 6 7\n2323: 1 4242\n4242: 1 2323" }, { "input": "79 58\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31", "output": "1: 1 2\n2: 1 1\n3: 28 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\n4: 28 3 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\n5: 28 3 4 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\n6: 28 3 4 5 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\n7: 28 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31\n8: 28 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2..." } ]
1,426,950,248
3,848
Python 3
WRONG_ANSWER
PRETESTS
0
30
0
d = {} s = input() m,k = [int(x) for x in s.split()] for i in range(m): s = input().split() f = s[0] in d.keys() if f: a = 1 d[s[0]] = d[s[0]]+' '+s[1] if not f: d[s[0]] = s[1] f = s[1] in d.keys() if f: d[s[1]] = d[s[1]]+' '+s[0] if not f: d[s[1]] = s[0] keys = d.keys() ans = {} for i in keys: for j in keys: sm = 0 if i != j: for c in keys: if c in d[i] and c in d[j]: sm += 1 if k*len(d[i].split()) <= sm*100: if i in ans.keys(): ans[i] = ans[i]+' '+j else: ans[i] = j heh = list(ans.keys()) heh.sort() for i in heh: s = i+': ' +str(len(ans[i].split()))+ ' '+ans[i] print(s)
Title: Возможно, вы знаете этих людей? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*. В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую вероятность быть знакомыми для пользователя. Эта функция работает следующим образом. Зафиксируем пользователя *x*. Пусть некоторый другой человек *y*, не являющийся другом *x* на текущий момент, является другом не менее, чем для *k*% друзей *x*. Тогда он является предполагаемым другом для *x*. У каждого человека в социальной сети есть свой уникальный идентификатор — это целое число от 1 до 109. Вам дан список пар пользователей, являющихся друзьями. Определите для каждого упомянутого пользователя множество его предполагаемых друзей. Input Specification: В первой строке следуют два целых числа *m* и *k* (1<=≤<=*m*<=≤<=100, 0<=≤<=*k*<=≤<=100) — количество пар друзей и необходимый процент общих друзей для того, чтобы считаться предполагаемым другом. В последующих *m* строках записано по два числа *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109, *a**i*<=≠<=*b**i*), обозначающих идентификаторы пользователей, являющихся друзьями. Гарантируется, что каждая пара людей фигурирует в списке не более одного раза. Output Specification: Для всех упомянутых людей в порядке возрастания id выведите информацию о предполагаемых друзьях. Информация должна иметь вид "*id*:<= *k* *id*1 *id*2 ... *id**k*", где *id* — это id самого человека, *k* — количество его предполагаемых друзей, а *id*1, *id*2, ..., *id**k* — идентификаторы его предполагаемых друзей в возрастающем порядке. Demo Input: ['5 51\n10 23\n23 42\n39 42\n10 39\n39 58\n', '5 100\n1 2\n1 3\n1 4\n2 3\n2 4\n'] Demo Output: ['10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42\n', '1: 0\n2: 0\n3: 1 4\n4: 1 3\n'] Note: none
```python d = {} s = input() m,k = [int(x) for x in s.split()] for i in range(m): s = input().split() f = s[0] in d.keys() if f: a = 1 d[s[0]] = d[s[0]]+' '+s[1] if not f: d[s[0]] = s[1] f = s[1] in d.keys() if f: d[s[1]] = d[s[1]]+' '+s[0] if not f: d[s[1]] = s[0] keys = d.keys() ans = {} for i in keys: for j in keys: sm = 0 if i != j: for c in keys: if c in d[i] and c in d[j]: sm += 1 if k*len(d[i].split()) <= sm*100: if i in ans.keys(): ans[i] = ans[i]+' '+j else: ans[i] = j heh = list(ans.keys()) heh.sort() for i in heh: s = i+': ' +str(len(ans[i].split()))+ ' '+ans[i] print(s) ```
0
810
B
Summer sell-off
PROGRAMMING
1,300
[ "greedy", "sortings" ]
null
null
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem.
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day.
Print a single integer denoting the maximal number of products that shop can sell.
[ "4 2\n2 1\n3 5\n2 3\n1 5\n", "4 1\n0 2\n0 3\n3 5\n0 6\n" ]
[ "10", "5" ]
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
1,000
[ { "input": "4 2\n2 1\n3 5\n2 3\n1 5", "output": "10" }, { "input": "4 1\n0 2\n0 3\n3 5\n0 6", "output": "5" }, { "input": "1 1\n5 8", "output": "8" }, { "input": "2 1\n8 12\n6 11", "output": "19" }, { "input": "2 1\n6 7\n5 7", "output": "13" }, { "input": "2 1\n5 7\n6 7", "output": "13" }, { "input": "2 1\n7 8\n3 6", "output": "13" }, { "input": "2 1\n9 10\n5 8", "output": "17" }, { "input": "2 1\n3 6\n7 8", "output": "13" }, { "input": "1 0\n10 20", "output": "10" }, { "input": "2 1\n99 100\n3 6", "output": "105" }, { "input": "4 2\n2 10\n3 10\n9 9\n5 10", "output": "27" }, { "input": "2 1\n3 4\n2 8", "output": "7" }, { "input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2", "output": "1889" }, { "input": "2 1\n10 5\n2 4", "output": "9" }, { "input": "2 1\n50 51\n30 40", "output": "90" }, { "input": "3 2\n5 10\n5 10\n7 9", "output": "27" }, { "input": "3 1\n1000 1000\n50 100\n2 2", "output": "1102" }, { "input": "2 1\n2 4\n12 12", "output": "16" }, { "input": "2 1\n4 4\n1 2", "output": "6" }, { "input": "2 1\n4000 4000\n1 2", "output": "4002" }, { "input": "2 1\n5 6\n2 4", "output": "9" }, { "input": "3 2\n10 10\n10 10\n1 2", "output": "22" }, { "input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4", "output": "25" }, { "input": "2 1\n30 30\n10 20", "output": "50" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "2 1\n10 2\n2 10", "output": "6" }, { "input": "2 1\n4 5\n3 9", "output": "10" }, { "input": "2 1\n100 100\n5 10", "output": "110" }, { "input": "2 1\n14 28\n15 28", "output": "43" }, { "input": "2 1\n100 1\n20 40", "output": "41" }, { "input": "2 1\n5 10\n6 10", "output": "16" }, { "input": "2 1\n29 30\n10 20", "output": "49" }, { "input": "1 0\n12 12", "output": "12" }, { "input": "2 1\n7 8\n4 7", "output": "14" }, { "input": "2 1\n5 5\n2 4", "output": "9" }, { "input": "2 1\n1 2\n228 2", "output": "4" }, { "input": "2 1\n5 10\n100 20", "output": "30" }, { "input": "2 1\n1000 1001\n2 4", "output": "1004" }, { "input": "2 1\n3 9\n7 7", "output": "13" }, { "input": "2 0\n1 1\n1 1", "output": "2" }, { "input": "4 1\n10 10\n10 10\n10 10\n4 6", "output": "36" }, { "input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64", "output": "772" }, { "input": "2 1\n10 18\n17 19", "output": "35" }, { "input": "3 0\n1 1\n1 1\n1 1", "output": "3" }, { "input": "2 1\n4 7\n8 9", "output": "15" }, { "input": "4 2\n2 10\n3 10\n9 10\n5 10", "output": "27" }, { "input": "2 1\n5 7\n3 6", "output": "11" }, { "input": "2 1\n3 4\n12 12", "output": "16" }, { "input": "2 1\n10 11\n9 20", "output": "28" }, { "input": "2 1\n7 8\n2 4", "output": "11" }, { "input": "2 1\n5 10\n7 10", "output": "17" }, { "input": "4 2\n2 10\n3 10\n5 10\n9 10", "output": "27" }, { "input": "2 1\n99 100\n5 10", "output": "109" }, { "input": "4 2\n2 10\n3 10\n5 10\n9 9", "output": "27" }, { "input": "2 1\n3 7\n5 7", "output": "11" }, { "input": "2 1\n10 10\n3 6", "output": "16" }, { "input": "2 1\n100 1\n2 4", "output": "5" }, { "input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "5" }, { "input": "3 1\n3 7\n4 5\n2 3", "output": "12" }, { "input": "2 1\n3 9\n7 8", "output": "13" }, { "input": "2 1\n10 2\n3 4", "output": "6" }, { "input": "2 1\n40 40\n3 5", "output": "45" }, { "input": "2 1\n5 3\n1 2", "output": "5" }, { "input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4", "output": "45" }, { "input": "3 1\n1 5\n1 5\n4 4", "output": "7" }, { "input": "4 0\n1 1\n1 1\n1 1\n1 1", "output": "4" }, { "input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2", "output": "2005" }, { "input": "2 1\n15 30\n50 59", "output": "80" }, { "input": "2 1\n8 8\n3 5", "output": "13" }, { "input": "2 1\n4 5\n2 5", "output": "8" }, { "input": "3 2\n3 3\n1 2\n1 2", "output": "7" }, { "input": "3 1\n2 5\n2 5\n4 4", "output": "10" }, { "input": "2 1\n3 10\n50 51", "output": "56" }, { "input": "4 2\n2 4\n2 4\n9 10\n9 10", "output": "26" }, { "input": "2 1\n3 5\n8 8", "output": "13" }, { "input": "2 1\n100 150\n70 150", "output": "240" }, { "input": "2 1\n4 5\n3 6", "output": "10" }, { "input": "2 1\n20 10\n3 5", "output": "15" }, { "input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533", "output": "435467000" }, { "input": "2 1\n8 7\n3 6", "output": "13" }, { "input": "2 1\n7 8\n3 5", "output": "12" }, { "input": "2 1\n10 10\n1 3", "output": "12" }, { "input": "2 1\n9 10\n2 4", "output": "13" }, { "input": "3 1\n10 11\n12 13\n8 10", "output": "32" }, { "input": "2 1\n5 10\n7 7", "output": "17" }, { "input": "4 2\n90 91\n2 10\n2 10\n2 10", "output": "100" }, { "input": "2 1\n2 4\n4 4", "output": "8" }, { "input": "2 1\n2 3\n4 3", "output": "6" }, { "input": "2 1\n40 45\n50 52", "output": "95" }, { "input": "3 1\n1 4\n2 4\n3 4", "output": "8" }, { "input": "2 1\n1 2\n1000 1000", "output": "1002" }, { "input": "2 1\n80 100\n70 95", "output": "175" } ]
1,588,515,043
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
982
11,571,200
l1 = [int(num) for num in input().split()] n = l1[0] f = l1[1] list1 = [] list2 = [] list3 = [] final = [] for i in range(n): l2 = [int(x) for x in input().split()] if l2[0] >= l2[1]: list1.append(l2[1]) list2.append(l2[1]) list3.append(l2[1]) else: list1.append(l2[0]) if 2 * l2[0] >= l2[1]: list2.append(l2[1]) list3.append(l2[1]) else: list2.append(2 * l2[0]) list3.append(2 * l2[0]) list2.sort(reverse=True) for i in range(f): final.append(list2[i]) list1[list3.index(list2[i])] = 0 final.extend(list1) print(sum(final))
Title: Summer sell-off Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input Specification: The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day. Output Specification: Print a single integer denoting the maximal number of products that shop can sell. Demo Input: ['4 2\n2 1\n3 5\n2 3\n1 5\n', '4 1\n0 2\n0 3\n3 5\n0 6\n'] Demo Output: ['10', '5'] Note: In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
```python l1 = [int(num) for num in input().split()] n = l1[0] f = l1[1] list1 = [] list2 = [] list3 = [] final = [] for i in range(n): l2 = [int(x) for x in input().split()] if l2[0] >= l2[1]: list1.append(l2[1]) list2.append(l2[1]) list3.append(l2[1]) else: list1.append(l2[0]) if 2 * l2[0] >= l2[1]: list2.append(l2[1]) list3.append(l2[1]) else: list2.append(2 * l2[0]) list3.append(2 * l2[0]) list2.sort(reverse=True) for i in range(f): final.append(list2[i]) list1[list3.index(list2[i])] = 0 final.extend(list1) print(sum(final)) ```
0
474
B
Worms
PROGRAMMING
1,200
[ "binary search", "implementation" ]
null
null
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding. Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained. Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot. The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
[ "5\n2 7 3 4 9\n3\n1 25 11\n" ]
[ "1\n5\n3\n" ]
For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
1,000
[ { "input": "5\n2 7 3 4 9\n3\n1 25 11", "output": "1\n5\n3" } ]
1,672,990,901
2,147,483,647
Python 3
OK
TESTS
38
327
10,444,800
import bisect n = int(input()) a = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) l = [a[0]] masha = [] s = 0 for i in range(1,n): l.append(l[-1]+a[i]) for i in range(m): s = bisect.bisect_left(l, q[i]) masha.append(s+1) print(*masha,sep='\n')
Title: Worms Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding. Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained. Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot. The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms. Output Specification: Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. Demo Input: ['5\n2 7 3 4 9\n3\n1 25 11\n'] Demo Output: ['1\n5\n3\n'] Note: For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
```python import bisect n = int(input()) a = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) l = [a[0]] masha = [] s = 0 for i in range(1,n): l.append(l[-1]+a[i]) for i in range(m): s = bisect.bisect_left(l, q[i]) masha.append(s+1) print(*masha,sep='\n') ```
3
380
C
Sereja and Brackets
PROGRAMMING
2,000
[ "data structures", "schedules" ]
null
null
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")". Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries. You can find the definitions for a subsequence and a correct bracket sequence in the notes.
The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query.
Print the answer to each question on a single line. Print the answers in the order they go in the input.
[ "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n" ]
[ "0\n0\n2\n10\n4\n6\n6\n" ]
A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> &lt; *k*<sub class="lower-index">2</sub> &lt; ... &lt; *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|). A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not. For the third query required sequence will be «()». For the fourth query required sequence will be «()(())(())».
1,500
[ { "input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10", "output": "0\n0\n2\n10\n4\n6\n6" }, { "input": "(((((()((((((((((()((()(((((\n1\n8 15", "output": "0" }, { "input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 46\n57 63\n29 48\n51 75\n14 72\n5 70\n51 73\n10 64\n31 56\n50 54\n15 78\n78 82\n1 11\n1 70\n1 19\n10 22\n13 36\n3 10\n34 40\n51 76\n64 71\n36 75\n24 71\n1 63\n5 14\n46 67\n32 56\n39 43\n43 56\n61 82\n2 78\n1 21\n10 72\n49 79\n12 14\n53 79\n15 31\n7 47", "output": "4\n4\n2\n4\n2\n12\n16\n2\n12\n4\n0\n12\n0\n6\n18\n6\n2\n6\n6\n0\n2\n0\n6\n8\n18\n4\n2\n4\n2\n2\n2\n18\n8\n12\n2\n0\n2\n6\n12" }, { "input": "))(()))))())())))))())((()()))))()))))))))))))\n9\n26 42\n21 22\n6 22\n7 26\n43 46\n25 27\n32 39\n22 40\n2 45", "output": "4\n0\n6\n8\n0\n2\n2\n10\n20" }, { "input": "(()((((()(())((((((((()((((((()((((\n71\n15 29\n17 18\n5 26\n7 10\n16 31\n26 35\n2 30\n16 24\n2 24\n7 12\n15 18\n12 13\n25 30\n1 30\n12 13\n16 20\n6 35\n20 28\n18 23\n9 31\n12 35\n14 17\n8 16\n3 10\n12 33\n7 19\n2 33\n7 17\n21 27\n10 30\n29 32\n9 28\n18 32\n28 31\n31 33\n4 26\n15 27\n10 17\n8 14\n11 28\n8 23\n17 33\n4 14\n3 6\n6 34\n19 23\n4 21\n16 27\n14 27\n6 19\n31 32\n29 32\n9 17\n1 21\n2 31\n18 29\n16 26\n15 18\n4 5\n13 20\n9 28\n18 30\n1 32\n2 9\n16 24\n1 20\n4 15\n16 23\n19 34\n5 22\n5 23", "output": "2\n0\n8\n2\n4\n2\n10\n2\n10\n4\n0\n0\n0\n10\n0\n0\n10\n2\n2\n8\n4\n0\n6\n2\n4\n6\n12\n6\n2\n6\n2\n6\n4\n2\n0\n8\n2\n4\n6\n4\n8\n4\n6\n0\n10\n2\n6\n2\n2\n6\n0\n2\n4\n8\n12\n2\n2\n0\n0\n0\n6\n2\n12\n4\n2\n8\n6\n2\n4\n6\n8" }, { "input": "(((())((((()()((((((()((()(((((((((((()((\n6\n20 37\n28 32\n12 18\n7 25\n21 33\n4 5", "output": "4\n0\n2\n6\n4\n2" }, { "input": "(((()((((()()()(()))((((()(((()))()((((()))()((())\n24\n37 41\n13 38\n31 34\n14 16\n29 29\n12 46\n1 26\n15 34\n8 47\n11 23\n6 32\n2 22\n9 27\n17 40\n6 15\n4 49\n12 33\n3 48\n22 47\n19 48\n10 27\n23 25\n4 44\n27 48", "output": "2\n16\n0\n2\n0\n26\n16\n12\n30\n8\n18\n14\n14\n12\n6\n34\n16\n32\n18\n18\n12\n0\n30\n16" }, { "input": ")()((((((((((((((((()(((()()(()((((((()(((((((()()))((((())(((((((((()(((((((((\n51\n29 53\n31 69\n54 59\n3 52\n26 46\n14 62\n6 54\n39 56\n17 27\n46 74\n60 72\n18 26\n38 46\n4 27\n22 52\n44 49\n42 77\n2 20\n39 57\n61 70\n33 54\n10 30\n67 70\n46 66\n17 77\n5 52\n33 77\n26 32\n1 72\n40 78\n38 68\n19 47\n30 53\n19 29\n52 71\n1 11\n22 53\n17 42\n2 51\n4 12\n24 76\n22 34\n21 69\n11 69\n36 52\n17 31\n57 58\n54 62\n23 71\n5 46\n51 53", "output": "12\n14\n4\n18\n6\n22\n18\n8\n4\n12\n2\n4\n2\n4\n16\n2\n14\n2\n8\n2\n10\n6\n2\n10\n24\n18\n16\n4\n26\n14\n14\n10\n12\n6\n6\n2\n16\n10\n18\n0\n22\n6\n20\n22\n10\n8\n2\n4\n22\n10\n0" }, { "input": "(\n1\n1 1", "output": "0" }, { "input": ")\n1\n1 1", "output": "0" }, { "input": "()\n1\n1 2", "output": "2" }, { "input": ")(\n1\n1 2", "output": "0" } ]
1,642,223,716
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
10,752,000
s = input() for i in range(int(input())): x, y = map(int, input().split()) t, r = 0, 0 for j in s[x - 1:y]: if j == '(': t += 1 elif j == ')' and t: t, r = t - 1, r + 1 print(r * 2)
Title: Sereja and Brackets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")". Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries. You can find the definitions for a subsequence and a correct bracket sequence in the notes. Input Specification: The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query. Output Specification: Print the answer to each question on a single line. Print the answers in the order they go in the input. Demo Input: ['())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n'] Demo Output: ['0\n0\n2\n10\n4\n6\n6\n'] Note: A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> &lt; *k*<sub class="lower-index">2</sub> &lt; ... &lt; *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|). A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not. For the third query required sequence will be «()». For the fourth query required sequence will be «()(())(())».
```python s = input() for i in range(int(input())): x, y = map(int, input().split()) t, r = 0, 0 for j in s[x - 1:y]: if j == '(': t += 1 elif j == ')' and t: t, r = t - 1, r + 1 print(r * 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,698,469,644
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
12
1,778
11,878,400
n = int(input()) l = list(map(int,input().split(' '))) change = [] can_sell = True i = 0 while i <n: if l[i] == 25: change.append(25) elif l[i] == 100: if 25 in change and 50 in change: change.append(100) change.remove(25) change.remove(50) else: can_sell = False break elif l[i] == 50: if 25 in change: change.append(50) change.remove(25) else: can_sell = False break i+=1 if can_sell: print('YES') else: print('NO')
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 = [] can_sell = True i = 0 while i <n: if l[i] == 25: change.append(25) elif l[i] == 100: if 25 in change and 50 in change: change.append(100) change.remove(25) change.remove(50) else: can_sell = False break elif l[i] == 50: if 25 in change: change.append(50) change.remove(25) else: can_sell = False break i+=1 if can_sell: print('YES') else: print('NO') ```
0
0
none
none
none
0
[ "none" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
0
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,505,653,941
441
Python 3
OK
TESTS
96
77
5,529,600
def getNumb(n): res1 = 0 while n % 5 == 0: res1 += 1 n /= 5 res2 = 0 while n % 2 == 0: res2 += 1 n /= 2 return (res1, res2) i, n = map(int, input().split()) a = getNumb(i) print(i * 5 ** (max(n - a[0], 0)) * 2 ** (max(n - a[1], 0)))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python def getNumb(n): res1 = 0 while n % 5 == 0: res1 += 1 n /= 5 res2 = 0 while n % 2 == 0: res2 += 1 n /= 2 return (res1, res2) i, n = map(int, input().split()) a = getNumb(i) print(i * 5 ** (max(n - a[0], 0)) * 2 ** (max(n - a[1], 0))) ```
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,671,791,602
2,147,483,647
Python 3
OK
TESTS
20
46
0
a=int(input()) for i in range(a): x=str(input()) if(len(x)>10): print(x[0]+str(len(x)-2)+x[-1]) else: print(x)
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 a=int(input()) for i in range(a): x=str(input()) if(len(x)>10): print(x[0]+str(len(x)-2)+x[-1]) else: print(x) ```
3.977
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1" }, { "input": "20\n5 3 7 2 1 6 4", "output": "6" }, { "input": "10\n5 1 1 1 1 1 5", "output": "6" }, { "input": "50\n10 1 10 1 10 1 10", "output": "1" }, { "input": "77\n11 11 11 11 11 11 10", "output": "1" }, { "input": "1\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n100 100 100 100 100 100 100", "output": "3" }, { "input": "999\n10 20 10 20 30 20 10", "output": "3" }, { "input": "433\n109 58 77 10 39 125 15", "output": "7" }, { "input": "1\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n1 0 1 0 1 0 1", "output": "1" }, { "input": "997\n1 1 0 0 1 0 1", "output": "1" }, { "input": "1000\n1 1 1 1 1 1 1", "output": "6" }, { "input": "1000\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n1 0 0 0 0 0 0", "output": "1" }, { "input": "1000\n0 0 0 0 0 0 1", "output": "7" }, { "input": "1000\n1 0 0 1 0 0 1", "output": "1" }, { "input": "509\n105 23 98 0 7 0 155", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "2\n1 1 0 0 0 0 0", "output": "2" }, { "input": "1\n0 0 0 0 0 1 0", "output": "6" }, { "input": "10\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n0 0 0 0 0 6 0", "output": "6" }, { "input": "3\n0 1 0 0 0 0 0", "output": "2" }, { "input": "10\n0 0 0 0 0 0 10", "output": "7" }, { "input": "28\n1 2 3 4 5 6 7", "output": "7" }, { "input": "100\n5 5 5 5 5 5 5", "output": "6" }, { "input": "4\n1 0 0 0 0 0 1", "output": "7" }, { "input": "2\n0 0 0 0 0 0 1", "output": "7" }, { "input": "7\n0 0 0 0 0 0 7", "output": "7" }, { "input": "7\n2 1 1 1 1 1 0", "output": "6" }, { "input": "2\n0 0 1 1 0 0 0", "output": "4" }, { "input": "6\n1 1 1 1 1 1 0", "output": "6" }, { "input": "5\n1 1 1 0 0 1 1", "output": "7" }, { "input": "100\n10 20 30 10 10 10 10", "output": "7" }, { "input": "1\n0 0 0 1 0 0 0", "output": "4" }, { "input": "70\n10 10 10 10 10 10 10", "output": "7" }, { "input": "22\n1 2 3 4 5 6 10", "output": "7" }, { "input": "5\n0 0 0 1 0 0 0", "output": "4" }, { "input": "2\n0 0 0 1 0 0 0", "output": "4" }, { "input": "6\n1 0 0 0 0 0 2", "output": "7" }, { "input": "10\n1 2 2 1 2 1 1", "output": "7" }, { "input": "5\n0 0 0 0 0 0 10", "output": "7" }, { "input": "4\n0 1 1 0 0 0 0", "output": "3" }, { "input": "100\n0 0 0 0 0 1 0", "output": "6" } ]
1,646,035,075
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
92
0
pg=int(input()) a=list(map(int, input().split())) cnt = 0 while pg>0: pg -= a[cnt] cnt = (cnt+1)%7 print(pg) print(cnt)
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. Input Specification: The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. Output Specification: Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Demo Input: ['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n'] Demo Output: ['6\n', '1\n'] Note: Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
```python pg=int(input()) a=list(map(int, input().split())) cnt = 0 while pg>0: pg -= a[cnt] cnt = (cnt+1)%7 print(pg) print(cnt) ```
0
290
D
Orange
PROGRAMMING
1,400
[ "*special", "implementation" ]
null
null
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive.
Output the required string.
[ "AprilFool\n14\n" ]
[ "AprILFooL\n" ]
none
0
[ { "input": "AprilFool\n14", "output": "AprILFooL" }, { "input": "abcdefabc\n3", "output": "ABCdefABC" }, { "input": "fgWjSAlPOvcAbCdDEFjz\n7", "output": "FGwjsAlpovCABCDDEFjz" }, { "input": "sm\n26", "output": "SM" }, { "input": "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\n12", "output": "GnLFoqpEztpIBKvvLHADvGpGFqBtnLGmt" }, { "input": "sPWSFWWqZBPon\n3", "output": "spwsfwwqzBpon" }, { "input": "fQHHXCdeaintxHWcFcaSGWFvqnYMEByMlSNKumiFgnJB\n0", "output": "fqhhxcdeaintxhwcfcasgwfvqnymebymlsnkumifgnjb" }, { "input": "RtsUOGkraqKyjTktAXloOEmQj\n18", "output": "RtsuOGKRAQKyJtKtAxLOOEMQJ" }, { "input": "DuFhhnq\n4", "output": "Dufhhnq" }, { "input": "RvpuYTxsbDiJDOLauRlfatcfwvtnDzKyaewGrZ\n22", "output": "RVPUyTxSBDIJDOLAURLFATCFwVTNDzKyAEwGRz" }, { "input": "isfvbcBEEPaXUDhbVhwddjEutVQqNdlimIKjUnajDQ\n2", "output": "isfvBcBeepAxudhBvhwddjeutvqqndlimikjunAjdq" }, { "input": "VtQISIHREYaEGPustEkzJRN\n20", "output": "vTQISIHREyAEGPuSTEKzJRN" }, { "input": "jWBVk\n17", "output": "JwBvK" }, { "input": "VWOibsVSFkxPCmyZLWIOxFbfXdlsNzxVcUVf\n8", "output": "vwoiBsvsFkxpCmyzlwioxFBFxDlsnzxvCuvF" }, { "input": "HXyXuYceFtVUMyLqi\n21", "output": "HxyxUyCEFTvUMyLQI" }, { "input": "tAjlldiqGZUayJZHFQHFJVRukaIKepPVucrkyPtMrhIXoxZbw\n12", "output": "tAJLLDIqGzuAyJzHFqHFJvruKAIKEppvuCrKyptmrHIxoxzBw" }, { "input": "fBUycJpfGhsfIVnXAovyoDyndkhv\n9", "output": "FBuyCjpFGHsFIvnxAovyoDynDkHv" }, { "input": "uehLuNwrjO\n0", "output": "uehlunwrjo" }, { "input": "gfSAltDEjuPqEsOFuiTpcUpCOiENCLbHHnCgvCQtW\n13", "output": "GFsALtDEJupqEsoFuItpCupCoIEnCLBHHnCGvCqtw" }, { "input": "SICNEaKsjCnvOEcVqFHLIC\n16", "output": "sICNEAKsJCNvOECvqFHLIC" }, { "input": "LdsmfiNFkPfJgRxytsSJMQZnDTZZ\n11", "output": "lDsmFInFKpFJGrxytssJmqznDtzz" }, { "input": "xedzyPU\n13", "output": "xEDzypu" }, { "input": "kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26", "output": "KGQOPTBELCDUCOZGNNRYXGPCRQWSLOQEIBYFWDI" }, { "input": "WHbBHzhSNkCZOAOwiKdu\n17", "output": "wHBBHzHsNKCzOAOwIKDu" }, { "input": "Ik\n3", "output": "ik" }, { "input": "WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5", "output": "wlwBrjvrozAkkxqECEDlrCnmvxqtlkBsy" }, { "input": "IOJRIQefPFxpUj\n18", "output": "IOJRIQEFPFxPuJ" }, { "input": "vPuebwksPlxuevRLuWcACTBBgVnmcAUsQUficgEAhoEm\n9", "output": "vpuEBwksplxuEvrluwCACtBBGvnmCAusquFICGEAHoEm" }, { "input": "hQfrRArEPuVAQGfcSuoVKBKvY\n22", "output": "HQFRRAREPUVAQGFCSUOVKBKVy" }, { "input": "TtQEIg\n24", "output": "TTQEIG" }, { "input": "abczxy\n0", "output": "abczxy" }, { "input": "aaaaaaAAAaaaaAaaAaaAaaaaAAaAAAaaAAaaaAAaaaaaAaaAAa\n2", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, { "input": "aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, { "input": "bBbAbbbbaaAAAaabbBbaaabBaaaBaBbAaBabaAAAaaaaBabbb\n4", "output": "BBBABBBBAAAAAAABBBBAAABBAAABABBAABABAAAAAAAABABBB" }, { "input": "BCABcbacbcbAAACCabbaccAabAAaaCCBcBAcCcbaABCCAcCb\n4", "output": "BCABCBACBCBAAACCABBACCAABAAAACCBCBACCCBAABCCACCB" }, { "input": "cdccAAaBBAADdaCDBbDcaDDabdadAbBccCCCDDBADDcdAdC\n4", "output": "CDCCAAABBAADDACDBBDCADDABDADABBCCCCCDDBADDCDADC" }, { "input": "EcCEECdCEBaaeCBEBbAaCAeEdeCEedCAdDeEbcACdCcCCd\n4", "output": "eCCeeCDCeBAAeCBeBBAACAeeDeCeeDCADDeeBCACDCCCCD" }, { "input": "cefEDAbedffbaCcEDfEeCEaAcCeFCcEabEecdEdcaFFde\n4", "output": "CefeDABeDffBACCeDfeeCeAACCefCCeABeeCDeDCAffDe" }, { "input": "nifzlTLaeWxTD\n0", "output": "nifzltlaewxtd" }, { "input": "LiqWMLEULRhW\n1", "output": "liqwmleulrhw" }, { "input": "qH\n2", "output": "qh" }, { "input": "R\n26", "output": "R" }, { "input": "MDJivQRiOIVRcCdkSuUlNbMEOkIVJRMTAnHbkVaOmOblLfignh\n25", "output": "MDJIVQRIOIVRCCDKSUULNBMEOKIVJRMTANHBKVAOMOBLLFIGNH" }, { "input": "pFgLGSkFnGpNKALeDPGlciUNTTlCtAPlFhaIRutCFaFo\n24", "output": "PFGLGSKFNGPNKALEDPGLCIUNTTLCTAPLFHAIRUTCFAFO" } ]
1,660,304,002
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
0
import sys input = sys.stdin.readline s = list(input()[:-1].lower()) n = int(input()) for i in range(len(s)): if ord(s[i]) - 96 < n: s[i] = s[i].upper() print(''.join(s))
Title: Orange Time Limit: None seconds Memory Limit: None megabytes Problem Description: Input Specification: The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive. Output Specification: Output the required string. Demo Input: ['AprilFool\n14\n'] Demo Output: ['AprILFooL\n'] Note: none
```python import sys input = sys.stdin.readline s = list(input()[:-1].lower()) n = int(input()) for i in range(len(s)): if ord(s[i]) - 96 < n: s[i] = s[i].upper() print(''.join(s)) ```
0
586
A
Alena's Schedule
PROGRAMMING
900
[ "implementation" ]
null
null
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces.
Print a single number — the number of pairs during which Alena stays at the university.
[ "5\n0 1 0 1 1\n", "7\n1 0 1 0 0 1 0\n", "1\n0\n" ]
[ "4\n", "4\n", "0\n" ]
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
500
[ { "input": "5\n0 1 0 1 1", "output": "4" }, { "input": "7\n1 0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 0", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "11\n0 0 0 0 0 0 0 0 0 0 1", "output": "1" }, { "input": "12\n1 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0", "output": "16" }, { "input": "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1", "output": "28" }, { "input": "63\n1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0", "output": "39" }, { "input": "80\n0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1", "output": "52" }, { "input": "99\n1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1", "output": "72" }, { "input": "100\n0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0", "output": "65" }, { "input": "11\n0 1 1 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "11\n0 1 0 1 0 0 1 1 0 1 1", "output": "8" }, { "input": "11\n1 0 1 0 1 1 0 1 1 1 0", "output": "10" }, { "input": "11\n1 0 0 0 0 0 1 0 1 1 1", "output": "6" }, { "input": "22\n0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0", "output": "7" }, { "input": "22\n0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1", "output": "16" }, { "input": "22\n1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0", "output": "11" }, { "input": "22\n1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 1", "output": "14" }, { "input": "33\n0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0", "output": "26" }, { "input": "33\n0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 0 1", "output": "27" }, { "input": "33\n1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0", "output": "25" }, { "input": "33\n1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 1 1", "output": "24" }, { "input": "44\n0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0", "output": "19" }, { "input": "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1", "output": "32" }, { "input": "44\n1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0", "output": "23" }, { "input": "44\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1", "output": "32" }, { "input": "55\n0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0", "output": "23" }, { "input": "55\n0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1", "output": "39" }, { "input": "55\n1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0", "output": "32" }, { "input": "55\n1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1", "output": "36" }, { "input": "66\n0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 0", "output": "41" }, { "input": "66\n0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 1", "output": "42" }, { "input": "66\n1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 0", "output": "46" }, { "input": "66\n1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 1", "output": "46" }, { "input": "77\n0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0", "output": "47" }, { "input": "77\n0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1", "output": "44" }, { "input": "77\n1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0", "output": "45" }, { "input": "77\n1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1", "output": "51" }, { "input": "88\n0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0", "output": "44" }, { "input": "88\n0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1", "output": "59" }, { "input": "88\n1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0", "output": "53" }, { "input": "88\n1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1", "output": "63" }, { "input": "99\n0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0", "output": "56" }, { "input": "99\n0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1", "output": "58" }, { "input": "99\n1 1 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0", "output": "65" }, { "input": "99\n1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1", "output": "77" }, { "input": "90\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", "output": "0" }, { "input": "90\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", "output": "90" }, { "input": "95\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", "output": "0" }, { "input": "95\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", "output": "95" }, { "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": "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": "100" } ]
1,502,726,885
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
4,608,000
n=int(input()) l = input() l = [int(i) for i in l.split()] t= 0 if n==1 and l[0]==1:print(1) elif n==1 and l[0]==0: print(0) else: for i in range(len(l)-1): if l[i]==0 and l[i+1]==1: t+=1 if l[i]==1 and i<=n-3 and l[i+1]==0 and l[i+2]==0: t-=1 if l[i]==1 : t+=1 print(t)
Title: Alena's Schedule Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces. Output Specification: Print a single number — the number of pairs during which Alena stays at the university. Demo Input: ['5\n0 1 0 1 1\n', '7\n1 0 1 0 0 1 0\n', '1\n0\n'] Demo Output: ['4\n', '4\n', '0\n'] Note: In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
```python n=int(input()) l = input() l = [int(i) for i in l.split()] t= 0 if n==1 and l[0]==1:print(1) elif n==1 and l[0]==0: print(0) else: for i in range(len(l)-1): if l[i]==0 and l[i+1]==1: t+=1 if l[i]==1 and i<=n-3 and l[i+1]==0 and l[i+2]==0: t-=1 if l[i]==1 : t+=1 print(t) ```
0
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair.
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32", "output": "25" }, { "input": "50\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50", "output": "1" }, { "input": "50\n50 50 49 49 48 48 47 47 46 46 45 45 44 44 43 43 42 42 41 41 40 40 39 39 38 38 37 37 36 36 35 35 34 34 33 33 32 32 31 31 30 30 29 29 28 28 27 27 26 26 25 25 24 24 23 23 22 22 21 21 20 20 19 19 18 18 17 17 16 16 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1", "output": "1" }, { "input": "50\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 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", "output": "50" }, { "input": "50\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "50" }, { "input": "10\n2 9 4 1 6 7 10 3 1 5 8 6 2 3 10 7 4 8 5 9", "output": "9" } ]
1,592,683,423
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
13,516,800
n=int(input()) arr=[int(x) for x in input().split()] count=0 max=0 brr=[] for i in range(len(arr)): if arr[i] not in brr: brr.append(arr[i]) count+=1 if max<count: max=count else: brr.remove(arr[i]) count-=1 if max<count: max=count print(max)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair. Output Specification: Print single integer — the maximum number of socks that were on the table at the same time. Demo Input: ['1\n1 1\n', '3\n2 1 1 3 2 3\n'] Demo Output: ['1\n', '2\n'] Note: In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
```python n=int(input()) arr=[int(x) for x in input().split()] count=0 max=0 brr=[] for i in range(len(arr)): if arr[i] not in brr: brr.append(arr[i]) count+=1 if max<count: max=count else: brr.remove(arr[i]) count-=1 if max<count: max=count print(max) ```
0
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,692,068,867
2,147,483,647
Python 3
OK
TESTS
85
92
0
p = input() instructions = set("HQ9") for char in p: if char in instructions: print("YES") break else: print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python p = input() instructions = set("HQ9") for char in p: if char in instructions: print("YES") break else: print("NO") ```
3
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,586,874,822
2,147,483,647
Python 3
OK
TESTS
32
108
0
s,v1,v2,t1,t2=map(int,input().split()) if 2*t1+v1*s > 2*t2+v2*s: print("Second") elif 2*t1+v1*s < 2*t2+v2*s: print("First") else: 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()) if 2*t1+v1*s > 2*t2+v2*s: print("Second") elif 2*t1+v1*s < 2*t2+v2*s: print("First") else: print("Friendship") ```
3
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,411,613,587
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
155
3,584,000
ints = int(input()) nums = list(map(int, input().split(' '))) left = [1]*ints right = [1]*ints #how many you can extend to the left #[1, 1, 2, 1, 2, 3] #the 3 can go to [1, 2, 3] #both 2s can go to [1, 2] for i in range(ints-1): if nums[i+1] >= nums[i]: left[i+1] += left[i] #how many you can extend to the right #the 2nd 1 can go to [1, 2] #the 3rd 1 can go to [1, 2, 3] nums.reverse() for i in range(ints-1): if nums[i+1] <= nums[i]: right[i+1] += right[i] nums.reverse() right.reverse() maximum = 2 for i in range(1, ints-1): if nums[i-1]+1 < nums[i+1]: maximum = max(maximum, left[i-1] + right[i+1] + 1) else: maximum = max(maximum, max(left[i-1]+1, right[i+1]+1)) maximum=max(maximum, left[ints-2]+1, right[1]+1) print(maximum)
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 ints = int(input()) nums = list(map(int, input().split(' '))) left = [1]*ints right = [1]*ints #how many you can extend to the left #[1, 1, 2, 1, 2, 3] #the 3 can go to [1, 2, 3] #both 2s can go to [1, 2] for i in range(ints-1): if nums[i+1] >= nums[i]: left[i+1] += left[i] #how many you can extend to the right #the 2nd 1 can go to [1, 2] #the 3rd 1 can go to [1, 2, 3] nums.reverse() for i in range(ints-1): if nums[i+1] <= nums[i]: right[i+1] += right[i] nums.reverse() right.reverse() maximum = 2 for i in range(1, ints-1): if nums[i-1]+1 < nums[i+1]: maximum = max(maximum, left[i-1] + right[i+1] + 1) else: maximum = max(maximum, max(left[i-1]+1, right[i+1]+1)) maximum=max(maximum, left[ints-2]+1, right[1]+1) print(maximum) ```
0
721
B
Passwords
PROGRAMMING
1,100
[ "implementation", "math", "sortings", "strings" ]
null
null
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice. Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that. Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
[ "5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n", "4 100\n11\n22\n1\n2\n22\n" ]
[ "1 15\n", "3 4\n" ]
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds. Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
1,000
[ { "input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15" }, { "input": "4 100\n11\n22\n1\n2\n22", "output": "3 4" }, { "input": "1 1\na1\na1", "output": "1 1" }, { "input": "1 100\na1\na1", "output": "1 1" }, { "input": "2 1\nabc\nAbc\nAbc", "output": "1 7" }, { "input": "2 2\nabc\nAbc\nabc", "output": "1 2" }, { "input": "2 1\nab\nabc\nab", "output": "1 1" }, { "input": "2 2\nab\nabc\nab", "output": "1 1" }, { "input": "2 1\nab\nabc\nabc", "output": "7 7" }, { "input": "2 2\nab\nabc\nabc", "output": "2 2" }, { "input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no", "output": "1 1" }, { "input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa", "output": "25 25" }, { "input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9", "output": "3 11" }, { "input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB", "output": "44 50" }, { "input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL", "output": "36 65" }, { "input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr", "output": "1 65" }, { "input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288", "output": "6 25" }, { "input": "3 1\na\nb\naa\naa", "output": "13 13" }, { "input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc", "output": "9 11" }, { "input": "4 2\n1\n2\n11\n22\n22", "output": "8 9" }, { "input": "2 1\n1\n12\n12", "output": "7 7" }, { "input": "3 1\nab\nabc\nabd\nabc", "output": "7 13" }, { "input": "2 1\na\nab\nab", "output": "7 7" }, { "input": "5 2\na\nb\nc\nab\naa\naa", "output": "9 15" }, { "input": "6 1\n1\n2\n11\n22\n111\n2222\n22", "output": "13 19" }, { "input": "3 1\n1\n2\n11\n11", "output": "13 13" }, { "input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac", "output": "12 20" }, { "input": "4 2\na\nb\nc\nd\na", "output": "1 9" }, { "input": "4 1\n1\n2\n3\n4\n4", "output": "1 19" }, { "input": "5 1\na\nb\nc\nd\nef\nef", "output": "25 25" }, { "input": "6 4\n1\n2\n22\n33\n44\n555\n555", "output": "11 11" }, { "input": "5 2\na\nb\nc\nd\nab\nab", "output": "15 15" }, { "input": "6 2\n1\n2\n3\n4\n5\n23\n23", "output": "16 16" }, { "input": "4 2\na\nb\naa\nbb\naa", "output": "8 9" }, { "input": "5 4\na\nbb\ncc\ndd\nee\nbb", "output": "2 10" }, { "input": "4 1\na\nb\nc\nab\nab", "output": "19 19" }, { "input": "7 100\na\nb\nc\nd\ne\ng\nab\nab", "output": "7 7" }, { "input": "6 1\na\nb\nc\nd\ne\naa\naa", "output": "31 31" }, { "input": "4 1\na\nas\nasd\nasde\nasde", "output": "19 19" }, { "input": "5 2\n1\n2\n3\n11\n22\n22", "output": "9 15" }, { "input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii", "output": "15 30" }, { "input": "3 1\na\nab\nbc\nab", "output": "7 13" }, { "input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc", "output": "4 11" } ]
1,652,374,387
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
N, K = list(map(int, input().split())) X = [] for i in range(N): X.append(input()) P = len(input()) X.sort() x, y = 0, 0 for i in range(N): if len(X[i]) > P: break elif len(X[i]) == P: y+=1 else: y+=1 x+=1 x+=1 if x%K==0: print(x+(((x//K)-1)*5), end=" ") else: print(x+((x//K)*5), end=" ") if y%K==0: print(y+(((y//K)-1)*5)) else: print(y+((y//K)*5))
Title: Passwords Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice. Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that. Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. Output Specification: Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. Demo Input: ['5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n', '4 100\n11\n22\n1\n2\n22\n'] Demo Output: ['1 15\n', '3 4\n'] Note: Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds. Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
```python N, K = list(map(int, input().split())) X = [] for i in range(N): X.append(input()) P = len(input()) X.sort() x, y = 0, 0 for i in range(N): if len(X[i]) > P: break elif len(X[i]) == P: y+=1 else: y+=1 x+=1 x+=1 if x%K==0: print(x+(((x//K)-1)*5), end=" ") else: print(x+((x//K)*5), end=" ") if y%K==0: print(y+(((y//K)-1)*5)) else: print(y+((y//K)*5)) ```
0
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" }, { "input": "22", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "0" }, { "input": "6", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "0" }, { "input": "9", "output": "0" }, { "input": "13", "output": "4" }, { "input": "14", "output": "4" }, { "input": "16", "output": "4" }, { "input": "17", "output": "4" }, { "input": "19", "output": "4" }, { "input": "21", "output": "4" }, { "input": "23", "output": "0" }, { "input": "24", "output": "0" } ]
1,415,379,706
2,147,483,647
Python 3
OK
TESTS
25
124
0
import sys import math n = int(sys.stdin.readline()) if(n - 10 == 10): print(15) elif(n - 10 >= 1 and n - 10 <= 11): print(4) else: print(0)
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. Input Specification: The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. Output Specification: Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. Demo Input: ['12\n', '20\n', '10\n'] Demo Output: ['4', '15', '0'] Note: In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
```python import sys import math n = int(sys.stdin.readline()) if(n - 10 == 10): print(15) elif(n - 10 >= 1 and n - 10 <= 11): print(4) else: print(0) ```
3.969
7
D
Palindrome Degree
PROGRAMMING
2,200
[ "hashing", "strings" ]
D. Palindrome Degree
1
256
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For example, "abaaba" has degree equals to 3. You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.
The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive.
Output the only number — the sum of the polindrome degrees of all the string's prefixes.
[ "a2A\n", "abacaba\n" ]
[ "1", "6" ]
none
0
[ { "input": "a2A", "output": "1" }, { "input": "abacaba", "output": "6" }, { "input": "CCeCeCCCee", "output": "4" }, { "input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop", "output": "3" }, { "input": "odribmizzsgholprdsth", "output": "1" }, { "input": "z", "output": "1" } ]
1,431,098,811
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
1,433,600
__author__ = 'Darren' def solve(): string = input() n = len(string) dp = [0 for i in range(n+1)] degree_sum = 0 forward, backward, power = 0, 0, 1 for i in range(n): forward = c_add(c_mul(forward, 31), ord(string[i])) backward = c_add(c_mul(ord(string[i]), power), backward) if forward == backward: dp[i+1] = dp[(i+1)//2] + 1 degree_sum += dp[i+1] power = c_mul(power, 31) print(degree_sum) def c_mul(a, b): return eval(hex((a * b) & 0xFFFFFFFF)) def c_add(a, b): return eval(hex((a + b) & 0xFFFFFFFF)) if __name__ == '__main__': solve()
Title: Palindrome Degree Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For example, "abaaba" has degree equals to 3. You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes. Input Specification: The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. Output Specification: Output the only number — the sum of the polindrome degrees of all the string's prefixes. Demo Input: ['a2A\n', 'abacaba\n'] Demo Output: ['1', '6'] Note: none
```python __author__ = 'Darren' def solve(): string = input() n = len(string) dp = [0 for i in range(n+1)] degree_sum = 0 forward, backward, power = 0, 0, 1 for i in range(n): forward = c_add(c_mul(forward, 31), ord(string[i])) backward = c_add(c_mul(ord(string[i]), power), backward) if forward == backward: dp[i+1] = dp[(i+1)//2] + 1 degree_sum += dp[i+1] power = c_mul(power, 31) print(degree_sum) def c_mul(a, b): return eval(hex((a * b) & 0xFFFFFFFF)) def c_add(a, b): return eval(hex((a + b) & 0xFFFFFFFF)) if __name__ == '__main__': solve() ```
0
736
E
Chess Championship
PROGRAMMING
2,900
[ "constructive algorithms", "flows", "greedy", "math" ]
null
null
Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were *m* players participating and each pair of players played exactly one game. The victory gives 2 points, draw — 1 points, lose — 0 points. Ostap is lazy, so he never tries to remember the outcome of each game. Instead, he computes the total number of points earned by each of the players (the sum of his points in all games which he took part in), sort these value in non-ascending order and then remembers first *n* integers in this list. Now the Great Strategist Ostap wonders whether he remembers everything correct. He considers that he is correct if there exists at least one tournament results table such that it will produce the given integers. That means, if we count the sum of points for each player, sort them and take first *n* elements, the result will coincide with what Ostap remembers. Can you check if such table exists?
The first line of the input contains two integers *m* and *n* (1<=≤<=*n*<=≤<=*m*<=≤<=3000) — the number of participants of the tournament and the number of top results Ostap remembers. The second line contains *n* integers, provided in non-ascending order — the number of points earned by top participants as Ostap remembers them. It's guaranteed that this integers are non-negative and do not exceed 2·*m*.
If there is no tournament such that Ostap can obtain the given set of integers using the procedure described in the statement, then print "no" in the only line of the output. Otherwise, the first line of the output should contain the word "yes". Next *m* lines should provide the description of any valid tournament. Each of these lines must contain *m* characters 'X', 'W', 'D' and 'L'. Character 'X' should always be located on the main diagonal (and only there), that is on the *i*-th position of the *i*-th string. Character 'W' on the *j*-th position of the *i*-th string means that the *i*-th player won the game against the *j*-th. In the same way character 'L' means loose and 'D' means draw. The table you print must be consistent and the points earned by best *n* participants should match the memory of Ostap. If there are many possible answers, print any of them.
[ "5 5\n8 6 4 2 0\n", "5 1\n9\n" ]
[ "yes\nXWWWW\nLXWWW\nLLXWW\nLLLXW\nLLLLX\n", "no\n" ]
none
2,500
[]
1,689,258,794
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1689258794.626286")# 1689258794.626302
Title: Chess Championship Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were *m* players participating and each pair of players played exactly one game. The victory gives 2 points, draw — 1 points, lose — 0 points. Ostap is lazy, so he never tries to remember the outcome of each game. Instead, he computes the total number of points earned by each of the players (the sum of his points in all games which he took part in), sort these value in non-ascending order and then remembers first *n* integers in this list. Now the Great Strategist Ostap wonders whether he remembers everything correct. He considers that he is correct if there exists at least one tournament results table such that it will produce the given integers. That means, if we count the sum of points for each player, sort them and take first *n* elements, the result will coincide with what Ostap remembers. Can you check if such table exists? Input Specification: The first line of the input contains two integers *m* and *n* (1<=≤<=*n*<=≤<=*m*<=≤<=3000) — the number of participants of the tournament and the number of top results Ostap remembers. The second line contains *n* integers, provided in non-ascending order — the number of points earned by top participants as Ostap remembers them. It's guaranteed that this integers are non-negative and do not exceed 2·*m*. Output Specification: If there is no tournament such that Ostap can obtain the given set of integers using the procedure described in the statement, then print "no" in the only line of the output. Otherwise, the first line of the output should contain the word "yes". Next *m* lines should provide the description of any valid tournament. Each of these lines must contain *m* characters 'X', 'W', 'D' and 'L'. Character 'X' should always be located on the main diagonal (and only there), that is on the *i*-th position of the *i*-th string. Character 'W' on the *j*-th position of the *i*-th string means that the *i*-th player won the game against the *j*-th. In the same way character 'L' means loose and 'D' means draw. The table you print must be consistent and the points earned by best *n* participants should match the memory of Ostap. If there are many possible answers, print any of them. Demo Input: ['5 5\n8 6 4 2 0\n', '5 1\n9\n'] Demo Output: ['yes\nXWWWW\nLXWWW\nLLXWW\nLLLXW\nLLLLX\n', 'no\n'] Note: none
```python print("_RANDOM_GUESS_1689258794.626286")# 1689258794.626302 ```
0
988
A
Diverse Team
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$.
[ "5 3\n15 13 15 15 12\n", "5 4\n15 13 15 15 12\n", "4 4\n20 10 40 30\n" ]
[ "YES\n1 2 5 \n", "NO\n", "YES\n1 2 3 4 \n" ]
All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
0
[ { "input": "5 3\n15 13 15 15 12", "output": "YES\n1 2 5 " }, { "input": "5 4\n15 13 15 15 12", "output": "NO" }, { "input": "4 4\n20 10 40 30", "output": "YES\n1 2 3 4 " }, { "input": "1 1\n1", "output": "YES\n1 " }, { "input": "100 53\n16 17 1 2 27 5 9 9 53 24 17 33 35 24 20 48 56 73 12 14 39 55 58 13 59 73 29 26 40 33 22 29 34 22 55 38 63 66 36 13 60 42 10 15 21 9 11 5 23 37 79 47 26 3 79 53 44 8 71 75 42 11 34 39 79 33 10 26 23 23 17 14 54 41 60 31 83 5 45 4 14 35 6 60 28 48 23 18 60 36 21 28 7 34 9 25 52 43 54 19", "output": "YES\n1 2 3 4 5 6 7 9 10 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 31 33 36 37 38 39 41 42 43 44 45 47 49 50 51 52 54 57 58 59 60 73 74 76 77 79 80 83 " }, { "input": "2 2\n100 100", "output": "NO" }, { "input": "2 2\n100 99", "output": "YES\n1 2 " }, { "input": "100 100\n63 100 75 32 53 24 73 98 76 15 70 48 8 81 88 58 95 78 27 92 14 16 72 43 46 39 66 38 64 42 59 9 22 51 4 6 10 94 28 99 68 80 35 50 45 20 47 7 30 26 49 91 77 19 96 57 65 1 11 13 31 12 82 87 93 34 62 3 21 79 56 41 89 18 44 23 74 86 2 33 69 36 61 67 25 83 5 84 90 37 40 29 97 60 52 55 54 71 17 85", "output": "YES\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 " }, { "input": "100 41\n54 16 42 3 45 6 9 72 100 13 24 57 35 5 89 13 97 27 43 9 73 89 48 16 48 55 18 15 55 28 30 6 18 41 100 61 9 42 35 54 57 25 73 15 42 54 49 5 72 48 30 55 4 43 94 5 60 92 93 23 89 75 53 92 74 93 89 28 69 6 3 49 15 28 49 57 54 55 30 57 69 18 89 6 25 23 93 74 30 13 87 53 6 42 4 54 60 30 4 35", "output": "NO" }, { "input": "100 2\n70 64 70 32 70 64 32 70 64 32 32 64 70 64 64 32 64 64 64 70 70 64 64 64 64 70 32 64 70 64 32 70 70 70 64 70 64 70 64 32 70 32 70 64 64 64 32 70 64 70 70 32 70 32 32 32 70 32 70 32 64 64 70 32 32 64 70 64 32 32 64 64 32 32 70 70 32 70 32 64 32 70 64 64 32 64 32 64 70 32 70 32 70 64 64 64 70 70 64 70", "output": "YES\n1 2 " } ]
1,652,665,782
2,147,483,647
PyPy 3-64
OK
TESTS
10
62
28,467,200
n,k = (map(int,input().split())) arr = list(map(int,input().split())) s = set(arr) if k>len(s) : print("NO") else : dif = [] ans="" i = 0 while len(dif)<k : while i<n : if arr[i] not in dif : dif.append(arr[i]) ans+=str(i+1)+" " break i+=1 print("YES") print(ans)
Title: Diverse Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them. Input Specification: The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. Output Specification: If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$. Demo Input: ['5 3\n15 13 15 15 12\n', '5 4\n15 13 15 15 12\n', '4 4\n20 10 40 30\n'] Demo Output: ['YES\n1 2 5 \n', 'NO\n', 'YES\n1 2 3 4 \n'] Note: All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
```python n,k = (map(int,input().split())) arr = list(map(int,input().split())) s = set(arr) if k>len(s) : print("NO") else : dif = [] ans="" i = 0 while len(dif)<k : while i<n : if arr[i] not in dif : dif.append(arr[i]) ans+=str(i+1)+" " break i+=1 print("YES") print(ans) ```
3
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*.
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces.
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1", "output": "6" }, { "input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "5\n1 0\n1 0\n1 0\n0 1\n0 1", "output": "4" } ]
1,630,591,667
466
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> #define fi first #define se second #define INF 100000000000000000LL #define ll long long #define debug(x) cout << #x << " "<< x <<endl; #define debug_vector(v) cout << #v << " "; _print(v); const ll inf =1e9+44; const int MAX=3e5+9; const ll MOD= 1e9+7; const double eps=1e-10; double const PI=3.1415926535897931; using namespace std; int dx[4] = {1 ,0 , - 1, 0}; int dy[4] = {0 ,1 , 0 , -1}; void _print(vector<int> v){ cout << "[ "; for ( auto u : v) cout << u << " "; cout << " ]"<< endl; } int main(){ int n , m; cin >> n ; vector < int > a(2 , 0); vector <int > b(2 , 0); for (int i = 0 ; i < n ; i++){ int x, y; cin >> x >>y; a[x]++; b[y]++; } cout << min(n-a[0] , n-a[1]) + min(n-b[0] , n-b[1]); }
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*. Input Specification: The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces. Output Specification: In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. Demo Input: ['5\n0 1\n1 0\n0 1\n1 1\n0 1\n'] Demo Output: ['3\n'] Note: none
```python #include<bits/stdc++.h> #define fi first #define se second #define INF 100000000000000000LL #define ll long long #define debug(x) cout << #x << " "<< x <<endl; #define debug_vector(v) cout << #v << " "; _print(v); const ll inf =1e9+44; const int MAX=3e5+9; const ll MOD= 1e9+7; const double eps=1e-10; double const PI=3.1415926535897931; using namespace std; int dx[4] = {1 ,0 , - 1, 0}; int dy[4] = {0 ,1 , 0 , -1}; void _print(vector<int> v){ cout << "[ "; for ( auto u : v) cout << u << " "; cout << " ]"<< endl; } int main(){ int n , m; cin >> n ; vector < int > a(2 , 0); vector <int > b(2 , 0); for (int i = 0 ; i < n ; i++){ int x, y; cin >> x >>y; a[x]++; b[y]++; } cout << min(n-a[0] , n-a[1]) + min(n-b[0] , n-b[1]); } ```
-1
230
A
Dragons
PROGRAMMING
1,000
[ "greedy", "sortings" ]
null
null
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals *s*. If Kirito starts duelling with the *i*-th (1<=≤<=*i*<=≤<=*n*) dragon and Kirito's strength is not greater than the dragon's strength *x**i*, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by *y**i*. Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.
The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
[ "2 2\n1 99\n100 0\n", "10 1\n100 100\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength is too small to defeat the only dragon and win.
500
[ { "input": "2 2\n1 99\n100 0", "output": "YES" }, { "input": "10 1\n100 100", "output": "NO" }, { "input": "123 2\n78 10\n130 0", "output": "YES" }, { "input": "999 2\n1010 10\n67 89", "output": "YES" }, { "input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1", "output": "YES" }, { "input": "2 2\n3 5\n1 2", "output": "YES" }, { "input": "1 2\n1 0\n1 0", "output": "NO" }, { "input": "5 10\n20 1\n4 3\n5 1\n100 1\n4 2\n101 1\n10 0\n10 2\n17 3\n12 84", "output": "YES" }, { "input": "2 2\n1 98\n100 0", "output": "NO" }, { "input": "2 2\n1 2\n3 5", "output": "YES" }, { "input": "5 3\n13 20\n3 10\n15 5", "output": "YES" }, { "input": "2 5\n1 1\n2 1\n3 1\n4 1\n5 1", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n4 0", "output": "YES" }, { "input": "10 4\n20 1\n3 5\n2 4\n1 3", "output": "YES" }, { "input": "10 1\n1 1", "output": "YES" }, { "input": "4 1\n100 1000", "output": "NO" }, { "input": "5 1\n6 7", "output": "NO" }, { "input": "10 1\n10 10", "output": "NO" }, { "input": "6 2\n496 0\n28 8128", "output": "NO" }, { "input": "4 2\n2 1\n10 3", "output": "NO" }, { "input": "11 2\n22 0\n33 0", "output": "NO" }, { "input": "1 2\n100 1\n100 1", "output": "NO" }, { "input": "10 3\n12 0\n13 0\n14 0", "output": "NO" }, { "input": "50 3\n39 0\n38 0\n37 0", "output": "YES" }, { "input": "14 3\n1 5\n1 6\n1 7", "output": "YES" }, { "input": "1 3\n1 10\n1 11\n1 9", "output": "NO" }, { "input": "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10", "output": "NO" }, { "input": "9983 34\n6626 5976\n4448 3568\n2794 2309\n3741 8806\n4754 129\n2780 9275\n5785 9243\n3915 6159\n2609 4331\n238 6756\n6987 3887\n3384 5711\n4349 5563\n1135 4483\n9151 1584\n1500 766\n1608 4440\n7768 5005\n7205 2360\n9088 2933\n3923 7814\n7538 9372\n7504 165\n5277 1636\n2061 4384\n7668 1422\n9582 2121\n5483 7967\n487 2944\n7432 5794\n8208 8970\n5747 3800\n4322 3920\n8261 9319", "output": "YES" }, { "input": "1 10\n8 8\n54 3\n1 8\n26 3\n16 1\n29 9\n38 10\n57 8\n48 6\n17 9", "output": "NO" }, { "input": "5 10\n7 0\n7 0\n10 0\n10 0\n7 2\n4 2\n9 0\n6 1\n7 0\n7 0", "output": "NO" }, { "input": "2 3\n1 1\n1 10\n17 2", "output": "NO" }, { "input": "100 5\n99 100\n199 1\n199 1\n199 1\n202 1", "output": "YES" }, { "input": "1 1\n10000 1", "output": "NO" } ]
1,699,473,791
2,147,483,647
Python 3
OK
TESTS
54
248
0
def bubbleSort(arr , bonus): n = len(arr) # Traverse through all array elements for i in range(n): # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than the next element if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] bonus[j], bonus[j+1] = bonus[j+1], bonus[j] s,n=input().split() s,n=int(s),int(n) x=[] y=[] for i in range(n): a=input().split() x.append(int(a[0])) y.append(int(a[1])) win = 0 bubbleSort (x, y) for i in range(n): if s>x[i]: s += y[i] win+=1 else: print("NO") break if(win==n):print("YES")
Title: Dragons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals *s*. If Kirito starts duelling with the *i*-th (1<=≤<=*i*<=≤<=*n*) dragon and Kirito's strength is not greater than the dragon's strength *x**i*, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by *y**i*. Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss. Input Specification: The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. Output Specification: On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. Demo Input: ['2 2\n1 99\n100 0\n', '10 1\n100 100\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength is too small to defeat the only dragon and win.
```python def bubbleSort(arr , bonus): n = len(arr) # Traverse through all array elements for i in range(n): # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than the next element if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] bonus[j], bonus[j+1] = bonus[j+1], bonus[j] s,n=input().split() s,n=int(s),int(n) x=[] y=[] for i in range(n): a=input().split() x.append(int(a[0])) y.append(int(a[1])) win = 0 bubbleSort (x, y) for i in range(n): if s>x[i]: s += y[i] win+=1 else: print("NO") break if(win==n):print("YES") ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,638,540,552
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
s = str(input()) a = "" for i in range(len(s) - 1, -1 ,-1): a += s[i] print(a)
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python s = str(input()) a = "" for i in range(len(s) - 1, -1 ,-1): a += s[i] print(a) ```
0
520
B
Two Buttons
PROGRAMMING
1,400
[ "dfs and similar", "graphs", "greedy", "implementation", "math", "shortest paths" ]
null
null
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*. Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result?
The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space .
Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*.
[ "4 6\n", "10 1\n" ]
[ "2\n", "9\n" ]
In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
1,000
[ { "input": "4 6", "output": "2" }, { "input": "10 1", "output": "9" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "1 3", "output": "3" }, { "input": "3 1", "output": "2" }, { "input": "2 10", "output": "5" }, { "input": "100 99", "output": "1" }, { "input": "99 100", "output": "50" }, { "input": "10 17", "output": "3" }, { "input": "666 6666", "output": "255" }, { "input": "6666 666", "output": "6000" }, { "input": "1 8192", "output": "13" }, { "input": "1 8193", "output": "27" }, { "input": "9999 10000", "output": "5000" }, { "input": "10000 9999", "output": "1" }, { "input": "10000 1", "output": "9999" }, { "input": "1234 5678", "output": "528" }, { "input": "9102 9103", "output": "4552" }, { "input": "8192 1", "output": "8191" }, { "input": "9912 1023", "output": "8889" }, { "input": "100 500", "output": "41" }, { "input": "9997 9999", "output": "4999" }, { "input": "5000 10000", "output": "1" }, { "input": "4000 7997", "output": "3" }, { "input": "1 10000", "output": "20" }, { "input": "1 8191", "output": "14" }, { "input": "9999 10000", "output": "5000" }, { "input": "9097 9998", "output": "4099" }, { "input": "886 9383", "output": "305" }, { "input": "1 9", "output": "7" }, { "input": "1918 10000", "output": "671" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "2" }, { "input": "2 10000", "output": "19" }, { "input": "3 10000", "output": "17" }, { "input": "4 10000", "output": "18" }, { "input": "9998 10000", "output": "4999" }, { "input": "5000 10000", "output": "1" }, { "input": "5001 10000", "output": "2" }, { "input": "10000 1", "output": "9999" }, { "input": "1 9999", "output": "21" }, { "input": "7777 9999", "output": "2779" }, { "input": "2 100", "output": "9" }, { "input": "10 8722", "output": "18" }, { "input": "848 4561", "output": "283" }, { "input": "9967 9973", "output": "4982" }, { "input": "5555 10000", "output": "556" }, { "input": "999 10000", "output": "378" }, { "input": "3 6", "output": "1" }, { "input": "9 38", "output": "8" } ]
1,697,560,423
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
46
0
a,b=input().split() a,b=int(a), int(b) j=0 while a!=b: j+=1 if (a-1)*2<b: a*=2 else: a-=1 print(j)
Title: Two Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*. Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result? Input Specification: The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . Output Specification: Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. Demo Input: ['4 6\n', '10 1\n'] Demo Output: ['2\n', '9\n'] Note: In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
```python a,b=input().split() a,b=int(a), int(b) j=0 while a!=b: j+=1 if (a-1)*2<b: a*=2 else: a-=1 print(j) ```
0
389
A
Fox and Number Game
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. Please help Ciel to find this minimal sum.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output a single integer — the required minimal sum.
[ "2\n1 2\n", "3\n2 4 6\n", "2\n12 18\n", "5\n45 12 27 30 18\n" ]
[ "2\n", "6\n", "12\n", "15\n" ]
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 4 6", "output": "6" }, { "input": "2\n12 18", "output": "12" }, { "input": "5\n45 12 27 30 18", "output": "15" }, { "input": "2\n1 1", "output": "2" }, { "input": "2\n100 100", "output": "200" }, { "input": "2\n87 58", "output": "58" }, { "input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52", "output": "2028" }, { "input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96", "output": "5664" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "10000" }, { "input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98", "output": "700" }, { "input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42", "output": "819" }, { "input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70", "output": "4130" }, { "input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22", "output": "1914" }, { "input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63", "output": "945" }, { "input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91", "output": "273" }, { "input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36", "output": "324" }, { "input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71", "output": "3266" }, { "input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33", "output": "770" }, { "input": "10\n60 12 96 48 60 24 60 36 60 60", "output": "120" }, { "input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51", "output": "1020" }, { "input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58", "output": "2900" }, { "input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90", "output": "980" }, { "input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82", "output": "8200" }, { "input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70", "output": "100" }, { "input": "2\n100 1", "output": "2" }, { "input": "2\n18 30", "output": "12" }, { "input": "2\n3 5", "output": "2" }, { "input": "2\n1 10", "output": "2" }, { "input": "2\n8 5", "output": "2" }, { "input": "5\n2 3 5 8 18", "output": "5" }, { "input": "5\n2 4 1 6 8", "output": "5" }, { "input": "3\n12 10 5", "output": "3" }, { "input": "3\n6 10 15", "output": "3" } ]
1,566,723,380
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
0
n=int(input()) array=list(map(int,input().split())) array.sort(reverse=True) for i in range(n**n): if array[0]>array[1]: array[0]=array[0]-array[1] array.sort(reverse=True) print(sum(array))
Title: Fox and Number Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. Please help Ciel to find this minimal sum. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). Output Specification: Output a single integer — the required minimal sum. Demo Input: ['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n'] Demo Output: ['2\n', '6\n', '12\n', '15\n'] Note: In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
```python n=int(input()) array=list(map(int,input().split())) array.sort(reverse=True) for i in range(n**n): if array[0]>array[1]: array[0]=array[0]-array[1] array.sort(reverse=True) print(sum(array)) ```
0
825
C
Multi-judge Solving
PROGRAMMING
1,600
[ "greedy", "implementation" ]
null
null
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge). Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it). Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*. With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces. Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another. Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109). The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
[ "3 3\n2 1 9\n", "4 20\n10 3 6 3\n" ]
[ "1\n", "0\n" ]
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second example he can solve every problem right from the start.
0
[ { "input": "3 3\n2 1 9", "output": "1" }, { "input": "4 20\n10 3 6 3", "output": "0" }, { "input": "1 1000000000\n1", "output": "0" }, { "input": "1 1\n3", "output": "1" }, { "input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82", "output": "0" }, { "input": "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 488 416 659 988 998 93 662 92 749 889 78 214 786 735 625 921 372 713 617 975 119 402 411 878 138 548 905 802 762 940 336 529 373 745 835 805 880 816 94 166 114 475 699 974 462 61 337 555 805 968 815 392 746 591 558 740 380 668 29 881 151 387 986 174 923 541 520 998 947 535 651 103 584 664 854 180 852 726 93", "output": "1" }, { "input": "2 1\n1 1000000000", "output": "29" }, { "input": "29 2\n1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911", "output": "27" }, { "input": "1 1\n1000000000", "output": "29" }, { "input": "7 6\n4 20 16 14 3 17 4", "output": "1" }, { "input": "2 1\n3 6", "output": "1" }, { "input": "1 1\n20", "output": "4" }, { "input": "5 2\n86 81 53 25 18", "output": "4" }, { "input": "4 1\n88 55 14 39", "output": "4" }, { "input": "3 1\n2 3 6", "output": "0" }, { "input": "3 2\n4 9 18", "output": "1" }, { "input": "5 3\n6 6 6 13 27", "output": "2" }, { "input": "5 1\n23 8 83 26 18", "output": "4" }, { "input": "3 1\n4 5 6", "output": "1" }, { "input": "3 1\n1 3 6", "output": "1" }, { "input": "1 1\n2", "output": "0" }, { "input": "3 2\n4 5 6", "output": "0" }, { "input": "5 1\n100 200 400 1000 2000", "output": "7" }, { "input": "2 1\n1 4", "output": "1" }, { "input": "4 1\n2 4 8 32", "output": "1" }, { "input": "2 10\n21 42", "output": "1" }, { "input": "3 3\n1 7 13", "output": "1" }, { "input": "3 1\n1 4 6", "output": "1" }, { "input": "2 2\n2 8", "output": "1" }, { "input": "1 1\n4", "output": "1" }, { "input": "2 2\n8 16", "output": "1" }, { "input": "3 1\n4 8 16", "output": "1" }, { "input": "3 1\n3 6 9", "output": "1" }, { "input": "2 1\n4 8", "output": "1" }, { "input": "2 2\n7 14", "output": "1" }, { "input": "1 4\n9", "output": "1" }, { "input": "5 3\n1024 4096 16384 65536 536870913", "output": "24" }, { "input": "2 5\n10 11", "output": "0" }, { "input": "2 2\n3 6", "output": "0" }, { "input": "2 2\n8 11", "output": "1" }, { "input": "3 19905705\n263637263 417905394 108361057", "output": "3" }, { "input": "4 25\n100 11 1 13", "output": "1" }, { "input": "10 295206008\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696", "output": "0" }, { "input": "4 2\n45 44 35 38", "output": "4" }, { "input": "1 2\n9", "output": "2" }, { "input": "3 6\n13 26 52", "output": "1" }, { "input": "9 30111088\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021", "output": "2" }, { "input": "3 72014068\n430005292 807436976 828082746", "output": "2" }, { "input": "3 165219745\n737649884 652879952 506420386", "output": "1" }, { "input": "2 60669400\n95037700 337255240", "output": "1" }, { "input": "4 28\n34 1 86 90", "output": "1" }, { "input": "2 1\n5 10", "output": "2" }, { "input": "2 1\n4 1000000000", "output": "28" }, { "input": "2 1\n2 3", "output": "0" }, { "input": "2 1\n3 5", "output": "1" }, { "input": "3 3\n1 5 20", "output": "1" }, { "input": "9 1\n1 2 4 9 15 32 64 128 1024", "output": "4" } ]
1,500,225,111
2,147,483,647
Python 3
OK
TESTS
61
62
4,915,200
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) answer = 0 for elem in a: while 2 * k < elem: k *= 2 answer += 1 k = max(k, elem) print(answer)
Title: Multi-judge Solving Time Limit: None seconds Memory Limit: None megabytes Problem Description: Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge). Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it). Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*. With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces. Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another. Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces. Input Specification: The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109). The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. Demo Input: ['3 3\n2 1 9\n', '4 20\n10 3 6 3\n'] Demo Output: ['1\n', '0\n'] Note: In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second example he can solve every problem right from the start.
```python n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) answer = 0 for elem in a: while 2 * k < elem: k *= 2 answer += 1 k = max(k, elem) print(answer) ```
3
388
A
Fox and Box Accumulation
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output a single integer — the minimal possible number of piles.
[ "3\n0 0 10\n", "5\n0 1 2 3 4\n", "4\n0 0 0 0\n", "9\n0 1 0 2 0 1 1 2 10\n" ]
[ "2\n", "1\n", "4\n", "3\n" ]
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
500
[ { "input": "3\n0 0 10", "output": "2" }, { "input": "5\n0 1 2 3 4", "output": "1" }, { "input": "4\n0 0 0 0", "output": "4" }, { "input": "9\n0 1 0 2 0 1 1 2 10", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n100 99", "output": "1" }, { "input": "9\n0 1 1 0 2 0 3 45 4", "output": "3" }, { "input": "10\n1 1 1 1 2 2 2 2 2 2", "output": "4" }, { "input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "2" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "1" }, { "input": "11\n71 34 31 71 42 38 64 60 36 76 67", "output": "1" }, { "input": "39\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54", "output": "1" }, { "input": "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46", "output": "1" }, { "input": "87\n52 63 93 90 50 35 67 66 46 89 43 64 33 88 34 80 69 59 75 55 55 68 66 83 46 33 72 36 73 34 54 85 52 87 67 68 47 95 52 78 92 58 71 66 84 61 36 77 69 44 84 70 71 55 43 91 33 65 77 34 43 59 83 70 95 38 92 92 74 53 66 65 81 45 55 89 49 52 43 69 78 41 37 79 63 70 67", "output": "1" }, { "input": "15\n20 69 36 63 40 40 52 42 20 43 59 68 64 49 47", "output": "1" }, { "input": "39\n40 20 49 35 80 18 20 75 39 62 43 59 46 37 58 52 67 16 34 65 32 75 59 42 59 41 68 21 41 61 66 19 34 63 19 63 78 62 24", "output": "1" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "18" }, { "input": "46\n14 13 13 10 13 15 8 8 12 9 11 15 8 10 13 8 12 13 11 8 12 15 12 15 11 13 12 9 13 12 10 8 13 15 9 15 8 13 11 8 9 9 9 8 11 8", "output": "3" }, { "input": "70\n6 1 4 1 1 6 5 2 5 1 1 5 2 1 2 4 1 1 1 2 4 5 2 1 6 6 5 2 1 4 3 1 4 3 6 5 2 1 3 4 4 1 4 5 6 2 1 2 4 4 5 3 6 1 1 2 2 1 5 6 1 6 3 1 4 4 2 3 1 4", "output": "11" }, { "input": "94\n11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11", "output": "8" }, { "input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "46\n14 8 7 4 8 7 8 8 12 9 9 12 9 12 14 8 10 14 14 6 9 11 7 14 14 13 11 4 13 13 11 13 9 10 10 12 10 8 12 10 13 10 7 13 14 6", "output": "4" }, { "input": "74\n4 4 5 5 5 5 5 5 6 6 5 4 4 4 3 3 5 4 5 3 4 4 5 6 3 3 5 4 4 5 4 3 5 5 4 4 3 5 6 4 3 6 6 3 4 5 4 4 3 3 3 6 3 5 6 5 5 5 5 3 6 4 5 4 4 6 6 3 4 5 6 6 6 6", "output": "11" }, { "input": "100\n48 35 44 37 35 42 42 39 49 53 35 55 41 42 42 39 43 49 46 54 48 39 42 53 55 39 56 43 43 38 48 40 54 36 48 55 46 40 41 39 45 56 38 40 47 46 45 46 53 51 38 41 54 35 35 47 42 43 54 54 39 44 49 41 37 49 36 37 37 49 53 44 47 37 55 49 45 40 35 51 44 40 42 35 46 48 53 48 35 38 42 36 54 46 44 47 41 40 41 42", "output": "2" }, { "input": "100\n34 3 37 35 40 44 38 46 13 31 12 23 26 40 26 18 28 36 5 21 2 4 10 29 3 46 38 41 37 28 44 14 39 10 35 17 24 28 38 16 29 6 2 42 47 34 43 2 43 46 7 16 16 43 33 32 20 47 8 48 32 4 45 38 15 7 25 25 19 41 20 35 16 2 31 5 31 25 27 3 45 29 32 36 9 47 39 35 9 21 32 17 21 41 29 48 11 40 5 25", "output": "3" }, { "input": "100\n2 4 5 5 0 5 3 0 3 0 5 3 4 1 0 3 0 5 5 0 4 3 3 3 0 2 1 2 2 4 4 2 4 0 1 3 4 1 4 2 5 3 5 2 3 0 1 2 5 5 2 0 4 2 5 1 0 0 4 0 1 2 0 1 2 4 1 4 5 3 4 5 5 1 0 0 3 1 4 0 4 5 1 3 3 0 4 2 0 4 5 2 3 0 5 1 4 4 1 0", "output": "21" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "17" }, { "input": "100\n1 1 1 2 2 2 2 2 2 1 1 1 2 0 2 2 0 0 0 0 0 2 0 0 2 2 1 0 2 0 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 0 1 2 2 0 2 2 2 2 1 0 1 0 0 0 2 0 2 0 1 1 0 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 0 2 1 0 1 2 0 1 1 2 0 0 1 1 0 1 1", "output": "34" }, { "input": "100\n0 3 1 0 3 2 1 2 2 1 2 1 3 2 1 2 1 3 2 0 0 2 3 0 0 2 1 2 2 3 1 2 2 2 0 3 3 2 0 0 1 0 1 2 3 1 0 3 3 3 0 2 1 3 0 1 3 2 2 2 2 3 3 2 0 2 0 1 0 1 3 0 1 2 0 1 3 2 0 3 1 1 2 3 1 3 1 0 3 0 3 0 2 1 1 1 2 2 0 1", "output": "26" }, { "input": "100\n1 0 2 2 2 2 1 0 1 2 2 2 0 1 0 1 2 1 2 1 0 1 2 2 2 1 0 1 0 2 1 2 0 2 1 1 2 1 1 0 1 2 1 1 2 1 1 0 2 2 0 0 1 2 0 2 0 0 1 1 0 0 2 1 2 1 0 2 2 2 2 2 2 1 2 0 1 2 1 2 1 0 1 0 1 0 1 1 0 2 1 0 0 1 2 2 1 0 0 1", "output": "34" }, { "input": "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4 4 3 3 3 4 4 4 4 3", "output": "20" }, { "input": "100\n8 7 9 10 2 7 8 11 11 4 7 10 2 5 8 9 10 3 9 4 10 5 5 6 3 8 8 9 6 9 5 5 4 11 4 2 11 8 3 5 6 6 11 9 8 11 9 8 3 3 8 9 8 9 4 8 6 11 4 4 4 9 7 5 3 4 11 3 9 11 8 10 3 5 5 7 6 9 4 5 2 11 3 6 2 10 9 4 6 10 5 11 8 10 10 8 9 8 5 3", "output": "9" }, { "input": "5\n4 1 1 1 1", "output": "2" } ]
1,601,825,307
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
108
0
n=int(input()) a=list(map(int,input().split())) temp={} def makestrdict(s): for l in s: if temp.get(l): temp[l]+=1 else: temp[l]=1 return temp makestrdict(a) print(max(temp.values()))
Title: Fox and Box Accumulation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). Output Specification: Output a single integer — the minimal possible number of piles. Demo Input: ['3\n0 0 10\n', '5\n0 1 2 3 4\n', '4\n0 0 0 0\n', '9\n0 1 0 2 0 1 1 2 10\n'] Demo Output: ['2\n', '1\n', '4\n', '3\n'] Note: In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
```python n=int(input()) a=list(map(int,input().split())) temp={} def makestrdict(s): for l in s: if temp.get(l): temp[l]+=1 else: temp[l]=1 return temp makestrdict(a) print(max(temp.values())) ```
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,651,274,316
2,147,483,647
PyPy 3-64
OK
TESTS
40
77
0
s = input() pos = s.find('h') if pos != -1: pos = s.find('e',pos + 1) if pos != -1: pos = s.find('l',pos + 1) if pos != -1: pos = s.find('l',pos + 1) if pos != -1: pos = s.find('o',pos + 1) if pos != -1: print('YES') else : print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s = input() pos = s.find('h') if pos != -1: pos = s.find('e',pos + 1) if pos != -1: pos = s.find('l',pos + 1) if pos != -1: pos = s.find('l',pos + 1) if pos != -1: pos = s.find('o',pos + 1) if pos != -1: print('YES') else : print('NO') ```
3.9615
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,695,407,210
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
x=list(map(int,input().split())) counter=0 for i in range (3): if x[i]==x[i+1]: counter+=1 print (counter)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python x=list(map(int,input().split())) counter=0 for i in range (3): if x[i]==x[i+1]: counter+=1 print (counter) ```
0
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "input": "49152 0 0 0 0 81920", "output": "No" }, { "input": "1 -1 4 4 2 -3", "output": "No" }, { "input": "-2 -2 1 4 -2 0", "output": "No" }, { "input": "5 0 4 -2 0 1", "output": "No" }, { "input": "-4 -3 2 -1 -3 4", "output": "No" }, { "input": "-3 -3 5 2 3 -1", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 999999999", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 1000000000", "output": "No" }, { "input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564", "output": "No" }, { "input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734", "output": "No" }, { "input": "419578772 -125025887 169314071 89851312 961404059 21419450", "output": "No" }, { "input": "-607353321 -620687860 248029390 477864359 728255275 -264646027", "output": "No" }, { "input": "299948862 -648908808 338174789 841279400 -850322448 350263551", "output": "No" }, { "input": "48517753 416240699 7672672 272460100 -917845051 199790781", "output": "No" }, { "input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665", "output": "No" }, { "input": "-685673792 -488079395 909733355 385950193 -705890324 256550506", "output": "No" }, { "input": "-326038504 547872194 49630307 713863100 303770000 -556852524", "output": "No" }, { "input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303", "output": "No" }, { "input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000", "output": "Yes" }, { "input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000", "output": "Yes" }, { "input": "-999999999 -1000000000 0 0 1000000000 999999999", "output": "Yes" }, { "input": "-1000000000 -999999999 0 0 1000000000 999999999", "output": "No" }, { "input": "-1 -1000000000 0 1000000000 1 -1000000000", "output": "Yes" }, { "input": "0 1000000000 1 0 0 -1000000000", "output": "Yes" }, { "input": "0 1000000000 0 0 0 -1000000000", "output": "No" }, { "input": "0 1 1 2 2 3", "output": "No" }, { "input": "999999999 1000000000 0 0 -1000000000 -999999999", "output": "Yes" }, { "input": "0 0 1 1 2 0", "output": "Yes" }, { "input": "0 0 1 1 2 2", "output": "No" }, { "input": "1 1 2 2 3 3", "output": "No" }, { "input": "0 2 0 3 0 4", "output": "No" }, { "input": "1 1 1 2 1 3", "output": "No" }, { "input": "0 0 3 4 3 9", "output": "Yes" }, { "input": "589824 196608 262144 196608 0 0", "output": "Yes" }, { "input": "0 0 1000000000 1 1000000000 -999999999", "output": "No" }, { "input": "0 0 2 45 0 90", "output": "Yes" }, { "input": "0 0 0 2 0 1", "output": "No" }, { "input": "0 2 4 5 4 0", "output": "Yes" }, { "input": "0 0 2 0 4 0", "output": "No" }, { "input": "1 1 3 3 5 5", "output": "No" }, { "input": "1 1 2 2 3 1", "output": "Yes" } ]
1,572,118,800
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
0
import math ax, ay, bx, by, cx, cy = input().split(' ') ax = int(ax) ay = int(ay) bx = int(bx) by = int(by) cx = int(cx) cy = int(cy) dist_ab = math.sqrt( (ax - bx)**2 + (ay - by)**2 ) dist_bc = math.sqrt( (bx - cx)**2 + (by - cy)**2 ) if(dist_ab == dist_bc): print("Yes") else: print("No")
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. Input Specification: The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. Output Specification: Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
```python import math ax, ay, bx, by, cx, cy = input().split(' ') ax = int(ax) ay = int(ay) bx = int(bx) by = int(by) cx = int(cx) cy = int(cy) dist_ab = math.sqrt( (ax - bx)**2 + (ay - by)**2 ) dist_bc = math.sqrt( (bx - cx)**2 + (by - cy)**2 ) if(dist_ab == dist_bc): print("Yes") else: print("No") ```
0
137
A
Postcards and photos
PROGRAMMING
900
[ "implementation" ]
null
null
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?
The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo.
Print the only number — the minimum number of times Polycarpus has to visit the closet.
[ "CPCPCPC\n", "CCCCCCPPPPPP\n", "CCCCCCPPCPPPPPPPPPP\n", "CCCCCCCCCC\n" ]
[ "7\n", "4\n", "6\n", "2\n" ]
In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice. In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
500
[ { "input": "CPCPCPC", "output": "7" }, { "input": "CCCCCCPPPPPP", "output": "4" }, { "input": "CCCCCCPPCPPPPPPPPPP", "output": "6" }, { "input": "CCCCCCCCCC", "output": "2" }, { "input": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "output": "20" }, { "input": "CPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCP", "output": "100" }, { "input": "CCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPP", "output": "28" }, { "input": "P", "output": "1" }, { "input": "C", "output": "1" }, { "input": "PC", "output": "2" }, { "input": "PPPPP", "output": "1" }, { "input": "PPPP", "output": "1" }, { "input": "CCCCCCCCCC", "output": "2" }, { "input": "CP", "output": "2" }, { "input": "CPCCPCPPPC", "output": "7" }, { "input": "PPCPCCPCPPCCPPPPPPCP", "output": "12" }, { "input": "PCPCCPCPPCCPCPCCPPPPPCPCPCPCCC", "output": "20" }, { "input": "CCPPPPPCPCCPPPCCPPCPCCPCPPCPPCCCPPCPPPCC", "output": "21" }, { "input": "CPPCCCCCCPCCCCPCCPCPPPCPCCCCCCCPCCPPCCCPCCCCCPPCCC", "output": "23" }, { "input": "PPCCCCPPCCPPPCCCCPPPPPCPPPCPPPCCCPCCCPCPPPCPCCCPCCPPCCPPPPPC", "output": "26" }, { "input": "PPCPPCCCCCPCCCPCCPCCCCPPPCCCCPCPCCPCPCPCPPPPCCPPPPPPPCPCPPPCPCPCPCPPPC", "output": "39" }, { "input": "CCPCPPPPCPPPPCCCCPCCPCPCCPPCPCCCPPCCCCPCCCPCPCCPPPCPPPCPCPPPPPCPCCPCCPPCCCPCPPPC", "output": "43" }, { "input": "CCPPCPCPCPPCCCPCPPPCCCCCPCPPCCCPPCPCPPPPCPPCPPPPCCCPCCPCPPPCPCPPCCCPCCCCCCPCCCCPCCPPPPCCPP", "output": "47" }, { "input": "PPCPPPPCCCCPPPPCPPPPPPPPCPCPPCCPPPPPPPPCPPPPCCCCPPPPCPPCPCPPPCCPPCPPCCCPCPPCCCCCCPCPCPCPPCPCPCPPPCCC", "output": "49" }, { "input": "CCPCCCPPCPPCPCCCPCPPCPPCPPCCCCCCCPCPPCPCCPCCPCPCPCCCPCCCPPPCCPCCPPCCCCCPPPPCPCPPCPCPCCPCPPP", "output": "53" }, { "input": "PCPCPPPPCPCPPPCPPCCCPCPCPCPPCPPPPCCPPPCPPPCPPPPCCPPCCCPCCPCCCCPCCPCPPCPCCCPCPPCP", "output": "47" }, { "input": "PCCPPCCCPPCPPCC", "output": "8" }, { "input": "CCCPPPPPPCCCCPCCPCCCCCCPCCCPPPCPC", "output": "15" }, { "input": "CPPCCPPCCPPPCCCPPPPCPPPPPPPCCPCPCCPPPPCCCPPCCPCCPPCCCPCCPCPPPPCCPP", "output": "31" }, { "input": "CCCCCPPPCCPCPCCPPPPCPCCCPCPPCPCPPPPPCCPCPCPC", "output": "25" }, { "input": "PPPPPPPPPCPCP", "output": "6" }, { "input": "PPPCPCPCCCPPCPCCPPPPCCCPCCP", "output": "15" }, { "input": "PCPCCPCPPPPPPCPCCPCPCPCCPPPCPCPCPPCPPCCPCPCCCPCCCPPCPCPCCPCPPPPCCCCCCPPCCPCCCCCPCCCCPPPCPCCCCCPCPCP", "output": "59" }, { "input": "PCCPCPPCCCCCPCCCPCCCPPCCCCCPPPCCPPPPPPPPCPPPCCPPCPPCPCP", "output": "26" }, { "input": "CPCPCCPPPPCCPPCPPCPPCCCCCCPCCPPPCPPCPCCCCCCPCPCCCCCPCCCCCCPCCPPCCP", "output": "35" }, { "input": "PPCCCCCCPP", "output": "4" }, { "input": "CCCCCCCCCCCCPPCCCCPP", "output": "6" }, { "input": "PPPPPPPPPPPCCCCCCCCCCCCCCCCCCP", "output": "8" }, { "input": "PPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCPPPPCCCC", "output": "10" }, { "input": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCPPPC", "output": "12" }, { "input": "CCCCCCCCCPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCC", "output": "13" }, { "input": "CCCCCCCCCCCCCCCCCCCCCCCCCPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "output": "15" }, { "input": "CCCCCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCPPPPPPPCCPPP", "output": "18" }, { "input": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPP", "output": "19" }, { "input": "PPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCCCPPPPCCCCCPCC", "output": "23" } ]
1,611,302,578
2,147,483,647
Python 3
OK
TESTS
45
124
307,200
s=input() c=[] ans=0 for i in s: if len(c)==0: c.append(i) elif len(c)!=0 and i=="C" and c[-1]=="P": ans=ans+1 c=[] c.append(i) elif len(c)!=0 and i=="P" and c[-1]=="C": ans=ans+1 c=[] c.append(i) else: if len(c)==5: c=[] c.append(i) ans=ans+1 else: c.append(i) print(ans+1)
Title: Postcards and photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items? Input Specification: The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo. Output Specification: Print the only number — the minimum number of times Polycarpus has to visit the closet. Demo Input: ['CPCPCPC\n', 'CCCCCCPPPPPP\n', 'CCCCCCPPCPPPPPPPPPP\n', 'CCCCCCCCCC\n'] Demo Output: ['7\n', '4\n', '6\n', '2\n'] Note: In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice. In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
```python s=input() c=[] ans=0 for i in s: if len(c)==0: c.append(i) elif len(c)!=0 and i=="C" and c[-1]=="P": ans=ans+1 c=[] c.append(i) elif len(c)!=0 and i=="P" and c[-1]=="C": ans=ans+1 c=[] c.append(i) else: if len(c)==5: c=[] c.append(i) ans=ans+1 else: c.append(i) print(ans+1) ```
3
0
none
none
none
0
[ "none" ]
null
null
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*: - If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*. Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0. At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook. The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=&lt;<=*i*) — notes in the logbook.
In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.
[ "2\n0 0\n", "5\n0 1 0 1 3\n" ]
[ "2\n", "3\n" ]
In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2. In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.
0
[ { "input": "2\n0 0", "output": "2" }, { "input": "5\n0 1 0 1 3", "output": "3" }, { "input": "7\n0 1 0 0 0 0 0", "output": "6" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13", "output": "66" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12", "output": "71" }, { "input": "1\n0", "output": "1" }, { "input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6", "output": "8" }, { "input": "2\n0 1", "output": "1" } ]
1,510,504,422
1,722
Python 3
OK
TESTS
31
234
20,480,000
n = int(input()) t = list(map(int, input().split())) r = {0:1} # time visited : room num m = 1 for time in range(1, n+1): x = t[time-1] # number written down if x in r: r[time] = r.pop(x) else: m += 1 r[time] = m print(m)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*: - If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*. Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0. At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook. The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=&lt;<=*i*) — notes in the logbook. Output Specification: In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. Demo Input: ['2\n0 0\n', '5\n0 1 0 1 3\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2. In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.
```python n = int(input()) t = list(map(int, input().split())) r = {0:1} # time visited : room num m = 1 for time in range(1, n+1): x = t[time-1] # number written down if x in r: r[time] = r.pop(x) else: m += 1 r[time] = m print(m) ```
3
883
G
Orientation of Edges
PROGRAMMING
1,900
[ "dfs and similar", "graphs" ]
null
null
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximize number of vertices reachable from vertex *s*; 1. to orient each undirected edge in one of two possible directions to minimize number of vertices reachable from vertex *s*. In each of two plans each undirected edge must become directed. For an edge chosen directions can differ in two plans. Help Vasya find the plans.
The first line contains three integers *n*, *m* and *s* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*m*<=≤<=3·105, 1<=≤<=*s*<=≤<=*n*) — number of vertices and edges in the graph, and the vertex Vasya has picked. The following *m* lines contain information about the graph edges. Each line contains three integers *t**i*, *u**i* and *v**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — edge type and vertices connected by the edge. If *t**i*<==<=1 then the edge is directed and goes from the vertex *u**i* to the vertex *v**i*. If *t**i*<==<=2 then the edge is undirected and it connects the vertices *u**i* and *v**i*. It is guaranteed that there is at least one undirected edge in the graph.
The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices. A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan should consist of *f* symbols '+' and '-', where *f* is the number of undirected edges in the initial graph. Print '+' as the *j*-th symbol of the string if the *j*-th undirected edge (*u*,<=*v*) from the input should be oriented from *u* to *v*. Print '-' to signify the opposite direction (from *v* to *u*). Consider undirected edges to be numbered in the same order they are given in the input. If there are multiple solutions, print any of them.
[ "2 2 1\n1 1 2\n2 2 1\n", "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3\n" ]
[ "2\n-\n2\n+\n", "6\n++-\n2\n+-+\n" ]
none
0
[ { "input": "2 2 1\n1 1 2\n2 2 1", "output": "2\n-\n2\n+" }, { "input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3", "output": "6\n++-\n2\n+-+" }, { "input": "5 5 5\n2 5 3\n1 2 3\n1 4 5\n2 5 2\n1 2 1", "output": "4\n++\n1\n--" }, { "input": "13 18 9\n2 3 10\n1 12 10\n1 11 4\n2 2 8\n1 5 1\n1 7 12\n1 5 13\n1 9 7\n1 10 11\n2 3 12\n1 9 2\n1 3 9\n1 8 12\n2 11 3\n1 3 1\n1 8 4\n2 9 11\n1 12 13", "output": "11\n++-++\n8\n+-+-+" }, { "input": "5 10 2\n2 2 4\n1 1 2\n2 2 3\n1 3 1\n1 4 1\n1 5 1\n1 3 4\n2 5 4\n1 5 2\n2 5 3", "output": "5\n++--\n1\n--++" }, { "input": "5 5 1\n2 5 3\n2 2 5\n1 2 1\n2 4 2\n1 1 5", "output": "5\n+--\n2\n-++" }, { "input": "5 10 3\n2 5 1\n2 1 3\n2 3 5\n2 1 4\n2 5 4\n2 2 5\n2 3 2\n2 2 1\n2 4 3\n2 4 2", "output": "5\n--+---+---\n1\n++-+++-+++" }, { "input": "10 10 9\n2 1 6\n2 7 8\n1 4 1\n2 5 10\n1 5 2\n1 6 7\n1 5 1\n2 9 8\n2 5 3\n2 3 8", "output": "9\n+-++--\n1\n+++-++" }, { "input": "10 20 5\n2 3 8\n2 10 2\n1 8 2\n1 7 3\n1 1 8\n1 8 5\n1 2 7\n1 3 9\n1 6 1\n2 10 8\n1 4 5\n1 6 8\n2 3 4\n1 6 5\n1 2 4\n1 2 3\n1 5 9\n2 4 9\n1 4 7\n1 6 2", "output": "8\n+----\n2\n+++++" }, { "input": "10 10 6\n2 1 4\n1 7 8\n1 6 4\n1 7 2\n1 6 2\n1 1 3\n1 9 7\n1 3 10\n1 9 6\n1 9 1", "output": "6\n-\n3\n+" }, { "input": "10 20 10\n2 7 3\n1 7 9\n1 3 6\n2 8 3\n2 9 2\n1 5 3\n2 9 8\n2 9 1\n1 5 9\n1 10 2\n1 6 7\n2 3 2\n2 8 1\n1 6 1\n2 4 6\n2 10 9\n2 5 7\n2 10 1\n1 2 7\n2 3 4", "output": "10\n---+----+-++\n4\n-++--+++++-+" }, { "input": "14 19 14\n2 5 7\n1 4 1\n2 9 8\n1 7 3\n2 14 2\n2 2 8\n2 6 7\n2 14 7\n1 7 8\n2 10 8\n2 11 10\n1 11 7\n2 3 13\n1 5 4\n1 14 8\n2 3 1\n2 6 1\n2 6 10\n2 8 1", "output": "13\n--+--+--+---+\n2\n++-++-++++++-" }, { "input": "300000 1 5345\n2 5345 23423", "output": "2\n+\n1\n-" }, { "input": "2 5 1\n1 1 2\n1 1 2\n1 1 2\n2 1 2\n1 1 2", "output": "2\n+\n2\n+" }, { "input": "2 5 2\n1 1 2\n1 1 2\n1 1 2\n2 1 2\n1 1 2", "output": "2\n-\n1\n+" }, { "input": "2 5 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2", "output": "2\n-----\n1\n+++++" }, { "input": "2 5 2\n1 1 2\n1 1 2\n1 2 1\n2 1 2\n1 2 1", "output": "2\n-\n2\n+" }, { "input": "2 5 1\n1 1 2\n1 1 2\n1 2 1\n2 1 2\n1 2 1", "output": "2\n+\n2\n+" }, { "input": "2 2 1\n2 1 2\n2 2 1", "output": "2\n+-\n1\n-+" }, { "input": "2 5 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2", "output": "2\n+++++\n1\n-----" } ]
1,596,468,389
2,147,483,647
PyPy 3
OK
TESTS
141
2,963
69,222,400
def put(): return map(int, input().split()) def dfs(x,flag=1): s,vis,ans = [x],[0]*n,['+']*m vis[x]= 1 while s: i = s.pop() for j,k in graph[i]: if vis[j]==0: if k*flag<0: ans[abs(k)-1]='-' elif k*flag>0: ans[abs(k)-1]='+' if flag==1 or k==0: s.append(j) vis[j]=1 return ''.join(ans), sum(vis) n,m,s = put() graph = [[] for i in range(n)] k=1 for _ in range(m): z,x,y = put() x,y = x-1,y-1 if z==1: graph[x].append((y, 0)) else: graph[x].append((y, k)) graph[y].append((x,-k)) k+=1 m = k-1 x,y = dfs(s-1, 1) print(y) print(x) x,y = dfs(s-1,-1) print(y) print(x)
Title: Orientation of Edges Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximize number of vertices reachable from vertex *s*; 1. to orient each undirected edge in one of two possible directions to minimize number of vertices reachable from vertex *s*. In each of two plans each undirected edge must become directed. For an edge chosen directions can differ in two plans. Help Vasya find the plans. Input Specification: The first line contains three integers *n*, *m* and *s* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*m*<=≤<=3·105, 1<=≤<=*s*<=≤<=*n*) — number of vertices and edges in the graph, and the vertex Vasya has picked. The following *m* lines contain information about the graph edges. Each line contains three integers *t**i*, *u**i* and *v**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — edge type and vertices connected by the edge. If *t**i*<==<=1 then the edge is directed and goes from the vertex *u**i* to the vertex *v**i*. If *t**i*<==<=2 then the edge is undirected and it connects the vertices *u**i* and *v**i*. It is guaranteed that there is at least one undirected edge in the graph. Output Specification: The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices. A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan should consist of *f* symbols '+' and '-', where *f* is the number of undirected edges in the initial graph. Print '+' as the *j*-th symbol of the string if the *j*-th undirected edge (*u*,<=*v*) from the input should be oriented from *u* to *v*. Print '-' to signify the opposite direction (from *v* to *u*). Consider undirected edges to be numbered in the same order they are given in the input. If there are multiple solutions, print any of them. Demo Input: ['2 2 1\n1 1 2\n2 2 1\n', '6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3\n'] Demo Output: ['2\n-\n2\n+\n', '6\n++-\n2\n+-+\n'] Note: none
```python def put(): return map(int, input().split()) def dfs(x,flag=1): s,vis,ans = [x],[0]*n,['+']*m vis[x]= 1 while s: i = s.pop() for j,k in graph[i]: if vis[j]==0: if k*flag<0: ans[abs(k)-1]='-' elif k*flag>0: ans[abs(k)-1]='+' if flag==1 or k==0: s.append(j) vis[j]=1 return ''.join(ans), sum(vis) n,m,s = put() graph = [[] for i in range(n)] k=1 for _ in range(m): z,x,y = put() x,y = x-1,y-1 if z==1: graph[x].append((y, 0)) else: graph[x].append((y, k)) graph[y].append((x,-k)) k+=1 m = k-1 x,y = dfs(s-1, 1) print(y) print(x) x,y = dfs(s-1,-1) print(y) print(x) ```
3
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,480,578,491
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
0
print(((int(input())//2)-1)//2)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python print(((int(input())//2)-1)//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,663,553,241
2,147,483,647
Python 3
OK
TESTS
45
46
0
n, m = (int(i) for i in input().split()) s = set(range(1, m + 1)) for _ in range(n): x, *y = (int(i) for i in input().split()) for i in y: s.discard(i) res = "NO" if s else "YES" print(res)
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 n, m = (int(i) for i in input().split()) s = set(range(1, m + 1)) for _ in range(n): x, *y = (int(i) for i in input().split()) for i in y: s.discard(i) res = "NO" if s else "YES" print(res) ```
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
1,698,072,447
2,147,483,647
Python 3
OK
TESTS
36
46
0
n = int(input()) operation_input = [list(map(str, input().split())) for i in range(n)] x = 0 operation_plus = [['++X'], ['X++']] operation_minus = [['--X'], ['X--']] for i in operation_input: if i in operation_plus: x += 1 if i in operation_minus: x -= 1 print(x)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python n = int(input()) operation_input = [list(map(str, input().split())) for i in range(n)] x = 0 operation_plus = [['++X'], ['X++']] operation_minus = [['--X'], ['X--']] for i in operation_input: if i in operation_plus: x += 1 if i in operation_minus: x -= 1 print(x) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total.
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7", "output": "37 37" }, { "input": "40 10\n1 2 3 4 5 6 7 10 10 10", "output": "223 158" }, { "input": "1 1\n6", "output": "6 6" }, { "input": "1 2\n10 9", "output": "10 9" }, { "input": "2 1\n7", "output": "13 13" }, { "input": "2 2\n7 2", "output": "13 3" }, { "input": "3 2\n4 7", "output": "18 9" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "10 10\n3 1 2 2 1 1 2 1 2 3", "output": "20 13" }, { "input": "10 2\n7 3", "output": "34 34" }, { "input": "10 1\n19", "output": "145 145" }, { "input": "100 3\n29 36 35", "output": "1731 1731" }, { "input": "100 5\n3 38 36 35 2", "output": "2019 1941" }, { "input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62", "output": "50279 5479" }, { "input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4", "output": "1501 1501" }, { "input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2", "output": "12204 8871" } ]
1,598,853,243
2,147,483,647
Python 3
OK
TESTS
33
966
6,963,200
#!/usr/bin/env python3 if __name__ == "__main__": n, m = map(int, input().split()) ais = list(map(int, input().split())) ris = sorted(ais, reverse=True) ais.sort() maxx = 0 minn = 0 for _ in range(n): maxx += ris[0] ris[0] -= 1 i = 0 while i < m - 1 and ris[i] < ris[i + 1]: ris[i], ris[i+1] = ris[i+1], ris[i] i += 1 i = 0 while n > 0: minn += ais[i] ais[i] -= 1 n -= 1 if ais[i] <= 0: i += 1 print(maxx, minn)
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. Output Specification: Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. Demo Input: ['4 3\n2 1 1\n', '4 3\n2 2 2\n'] Demo Output: ['5 5\n', '7 6\n'] Note: In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
```python #!/usr/bin/env python3 if __name__ == "__main__": n, m = map(int, input().split()) ais = list(map(int, input().split())) ris = sorted(ais, reverse=True) ais.sort() maxx = 0 minn = 0 for _ in range(n): maxx += ris[0] ris[0] -= 1 i = 0 while i < m - 1 and ris[i] < ris[i + 1]: ris[i], ris[i+1] = ris[i+1], ris[i] i += 1 i = 0 while n > 0: minn += ais[i] ais[i] -= 1 n -= 1 if ais[i] <= 0: i += 1 print(maxx, minn) ```
3